@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -require_once __DIR__ .'/../vendor/autoload.php'; |
|
| 2 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 3 | 3 | use Kristuff\Mishell\Console; |
| 4 | 4 | |
| 5 | 5 | Console::clear(); |
@@ -18,15 +18,15 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | Console::log(); |
| 20 | 20 | Console::log(); |
| 21 | - Console::log(' '. Console::text(" _ ____ _ _ _ ", 'red')); |
|
| 22 | - Console::log(' '. Console::text(" _ __ ___ (_)/ ___|| |__ ___| | | ", 'red')); |
|
| 23 | - Console::log(' '. Console::text(" | '_ ` _ \| |\___ \| '_ \ / _ \ | | ", 'red')); |
|
| 24 | - Console::log(' '. Console::text(" | | | | | | | ___) | | | | __/ | | ", 'red')); |
|
| 25 | - Console::log(' '. Console::text(" |_| |_| |_|_||____/|_| |_|\___|_|_| ", 'red')); |
|
| 26 | - Console::log(' '. Console::text(" ", 'red')); |
|
| 27 | - Console::log(' '. Console::text(" Version 1.4 ", 'red')); |
|
| 28 | - Console::log(' '. Console::text(" © 2017-2020 Kristuff ", 'red')); |
|
| 29 | - Console::log(' '. Console::text(" ", 'red')); |
|
| 21 | + Console::log(' '.Console::text(" _ ____ _ _ _ ", 'red')); |
|
| 22 | + Console::log(' '.Console::text(" _ __ ___ (_)/ ___|| |__ ___| | | ", 'red')); |
|
| 23 | + Console::log(' '.Console::text(" | '_ ` _ \| |\___ \| '_ \ / _ \ | | ", 'red')); |
|
| 24 | + Console::log(' '.Console::text(" | | | | | | | ___) | | | | __/ | | ", 'red')); |
|
| 25 | + Console::log(' '.Console::text(" |_| |_| |_|_||____/|_| |_|\___|_|_| ", 'red')); |
|
| 26 | + Console::log(' '.Console::text(" ", 'red')); |
|
| 27 | + Console::log(' '.Console::text(" Version 1.4 ", 'red')); |
|
| 28 | + Console::log(' '.Console::text(" © 2017-2020 Kristuff ", 'red')); |
|
| 29 | + Console::log(' '.Console::text(" ", 'red')); |
|
| 30 | 30 | Console::log(); |
| 31 | 31 | Console::log(); |
| 32 | 32 | Console::log(); |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | $pad = ' '; |
| 35 | 35 | |
| 36 | 36 | // fake progress message |
| 37 | - for ($i=0 ; $i<=100 ; $i++) { |
|
| 37 | + for ($i = 0; $i <= 100; $i++) { |
|
| 38 | 38 | |
| 39 | 39 | // Overwrite progress message. |
| 40 | 40 | Console::relog($pad.Console::text('This is a fake progress message... [', 'white'). |
| 41 | - Console::text($i .'%', 'green'). |
|
| 41 | + Console::text($i.'%', 'green'). |
|
| 42 | 42 | Console::text('] completed', 'white')); |
| 43 | 43 | |
| 44 | 44 | // wait for a while, so we see the animation |
@@ -54,25 +54,25 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $index = []; |
| 56 | 56 | |
| 57 | - $index[1] = ['Styles', 'How to get available basic styles', 'demo.styles.php']; |
|
| 58 | - $index[2] = ['Colors', 'How to get available foreground colors', 'demo.colors.php']; |
|
| 59 | - $index[3] = ['Backgrounds', 'How to get available background colors', 'demo.bgcolors.php']; |
|
| 57 | + $index[1] = ['Styles', 'How to get available basic styles', 'demo.styles.php']; |
|
| 58 | + $index[2] = ['Colors', 'How to get available foreground colors', 'demo.colors.php']; |
|
| 59 | + $index[3] = ['Backgrounds', 'How to get available background colors', 'demo.bgcolors.php']; |
|
| 60 | 60 | // $index[4] = ['Text', 'Console::text() overview', 'demo.log.php']; |
| 61 | 61 | // $index[5] = ['Log', 'Console::log() overview', 'demo.log.php']; |
| 62 | 62 | // $index[6] = ['ReLog', 'Console::relog() overview', 'demo.relog.php']; |
| 63 | - $index[7] = ['Pad', 'Console::pad() overview', 'demo.pad.php']; |
|
| 64 | - $index[8] = ['Size', 'How to get the number of columns and lines in terminal', 'demo.size.php']; |
|
| 63 | + $index[7] = ['Pad', 'Console::pad() overview', 'demo.pad.php']; |
|
| 64 | + $index[8] = ['Size', 'How to get the number of columns and lines in terminal', 'demo.size.php']; |
|
| 65 | 65 | |
| 66 | - $index[11] = ['Ask', 'How to ask? (get user input)', 'demo.ask.php']; |
|
| 67 | - $index[12] = ['Ask Number', 'How to ask and expect a number?', 'demo.askint.php']; |
|
| 68 | - $index[13] = ['Ask Password', 'How to ask a password? (do not print user input)', 'demo.askpassword.php']; |
|
| 66 | + $index[11] = ['Ask', 'How to ask? (get user input)', 'demo.ask.php']; |
|
| 67 | + $index[12] = ['Ask Number', 'How to ask and expect a number?', 'demo.askint.php']; |
|
| 68 | + $index[13] = ['Ask Password', 'How to ask a password? (do not print user input)', 'demo.askpassword.php']; |
|
| 69 | 69 | |
| 70 | - $index[14] = ['Table', 'How to print a table?', 'demo.table.php']; |
|
| 71 | - $index[15] = ['Bell', 'How to run the bell?', 'demo.bell.php']; |
|
| 72 | - $index[16] = ['Progress', 'How to output progress message?', 'demo.progress.php']; |
|
| 73 | - $index[17] = ['New window', 'How to open new/restore window?', 'demo.window.php']; |
|
| 70 | + $index[14] = ['Table', 'How to print a table?', 'demo.table.php']; |
|
| 71 | + $index[15] = ['Bell', 'How to run the bell?', 'demo.bell.php']; |
|
| 72 | + $index[16] = ['Progress', 'How to output progress message?', 'demo.progress.php']; |
|
| 73 | + $index[17] = ['New window', 'How to open new/restore window?', 'demo.window.php']; |
|
| 74 | 74 | |
| 75 | - $index[20] = ['BlueScreen', 'Really nice full screen centered message sample', 'demo.bluescreen.php']; |
|
| 75 | + $index[20] = ['BlueScreen', 'Really nice full screen centered message sample', 'demo.bluescreen.php']; |
|
| 76 | 76 | |
| 77 | 77 | return $index; |
| 78 | 78 | } |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | Console::clear(); |
| 83 | 83 | Console::log(); |
| 84 | - Console::log(Console::text(' Kristuff/Mishell ', 'darkgray') . Console::text(' v1.2 ', 'white', 'green')); |
|
| 85 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
| 84 | + Console::log(Console::text(' Kristuff/Mishell ', 'darkgray').Console::text(' v1.2 ', 'white', 'green')); |
|
| 85 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
| 86 | 86 | Console::log( |
| 87 | - Console::text(' © 2017-2020 Kristuff (', 'darkgray') . |
|
| 88 | - Console::text('https://github.com/kristuff)', 'darkgray', 'underlined') . |
|
| 87 | + Console::text(' © 2017-2020 Kristuff (', 'darkgray'). |
|
| 88 | + Console::text('https://github.com/kristuff)', 'darkgray', 'underlined'). |
|
| 89 | 89 | Console::text(')', 'darkgray') |
| 90 | 90 | ); |
| 91 | 91 | Console::log(); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | function printSampleHeader($index, $title) |
| 97 | 97 | { |
| 98 | - Console::log(' ' . Console::text(' - '. $index .' - ' . $title . ' ', 'white', 'blue')); |
|
| 98 | + Console::log(' '.Console::text(' - '.$index.' - '.$title.' ', 'white', 'blue')); |
|
| 99 | 99 | Console::log(); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -115,11 +115,11 @@ discard block |
||
| 115 | 115 | Console::log(''.Console::tableRowSeparator($rowHeaders, 'darkgray')); |
| 116 | 116 | Console::log(); |
| 117 | 117 | |
| 118 | - foreach (getIndex() as $key => $value){ |
|
| 119 | - if (file_exists( __DIR__ . '/'. $value[2])) { |
|
| 118 | + foreach (getIndex() as $key => $value) { |
|
| 119 | + if (file_exists(__DIR__.'/'.$value[2])) { |
|
| 120 | 120 | Console::log(''. |
| 121 | 121 | Console::TableRowStart(). |
| 122 | - Console::TableRowCell(Console::text($key,'lightgray'), 6, Console::ALIGN_CENTER). //no align => default is left |
|
| 122 | + Console::TableRowCell(Console::text($key, 'lightgray'), 6, Console::ALIGN_CENTER).//no align => default is left |
|
| 123 | 123 | Console::TableRowCell(Console::text($value[0], 'lightgray'), 15). |
| 124 | 124 | Console::TableRowCell(Console::text($value[1], 'lightgray'), 55) |
| 125 | 125 | ); |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | Console::log(''); |
| 130 | 130 | Console::log(''.Console::tableRowSeparator($rowHeaders, 'darkgray')); |
| 131 | 131 | Console::log(''); |
| 132 | - Console::log(' '. Console::text('Tips:', 'underlined', 'bold')); |
|
| 133 | - Console::log(' '. Console::text(' - At any time you can stop this program using [') .Console::text('Ctrl+C', 'green') .Console::text(']')); |
|
| 132 | + Console::log(' '.Console::text('Tips:', 'underlined', 'bold')); |
|
| 133 | + Console::log(' '.Console::text(' - At any time you can stop this program using [').Console::text('Ctrl+C', 'green').Console::text(']')); |
|
| 134 | 134 | Console::log(''); |
| 135 | 135 | // reset table separators to defaults |
| 136 | 136 | Console::resetDefaults(); |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | function askIndex() |
| 140 | 140 | { |
| 141 | - $base = Console::text(' kristuff/mishell-demo' , 'yellow'); |
|
| 142 | - $base .= Console::text('~$ ' , 'gray'); |
|
| 143 | - $selectedIndex = Console::askInt($base . Console::text(' Enter desired index then press [Enter] to run sample > ', 'white')); |
|
| 141 | + $base = Console::text(' kristuff/mishell-demo', 'yellow'); |
|
| 142 | + $base .= Console::text('~$ ', 'gray'); |
|
| 143 | + $selectedIndex = Console::askInt($base.Console::text(' Enter desired index then press [Enter] to run sample > ', 'white')); |
|
| 144 | 144 | $index = getIndex(); |
| 145 | 145 | |
| 146 | - switch($selectedIndex){ |
|
| 146 | + switch ($selectedIndex) { |
|
| 147 | 147 | case 0: |
| 148 | 148 | Console::log(); |
| 149 | 149 | // Console::restoreWindow(); |
@@ -155,30 +155,30 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | $title = $index[$selectedIndex][0]; |
| 157 | 157 | $fileName = $index[$selectedIndex][2]; |
| 158 | - $filePath = __DIR__ . '/'. $fileName; |
|
| 158 | + $filePath = __DIR__.'/'.$fileName; |
|
| 159 | 159 | |
| 160 | 160 | Console::clear(); |
| 161 | 161 | printHeader(); |
| 162 | 162 | printSampleHeader($selectedIndex, $title); |
| 163 | 163 | |
| 164 | - Console::log($base . Console::text('Start running [', 'white') . |
|
| 165 | - Console::text( $title, 'lightcyan') . |
|
| 166 | - Console::text('] in file [', 'white') . |
|
| 167 | - Console::text( $fileName, 'lightcyan') . |
|
| 164 | + Console::log($base.Console::text('Start running [', 'white'). |
|
| 165 | + Console::text($title, 'lightcyan'). |
|
| 166 | + Console::text('] in file [', 'white'). |
|
| 167 | + Console::text($fileName, 'lightcyan'). |
|
| 168 | 168 | Console::text(']', 'white')); |
| 169 | 169 | |
| 170 | - if (file_exists($filePath)){ |
|
| 170 | + if (file_exists($filePath)) { |
|
| 171 | 171 | Console::log(); |
| 172 | 172 | include $filePath; |
| 173 | 173 | Console::log(); |
| 174 | - Console::log($base . Console::text('End running [', 'white') . |
|
| 175 | - Console::text( $title, 'lightcyan') . |
|
| 174 | + Console::log($base.Console::text('End running [', 'white'). |
|
| 175 | + Console::text($title, 'lightcyan'). |
|
| 176 | 176 | Console::text(']', 'white')); |
| 177 | 177 | |
| 178 | - $response = Console::ask($base . Console::text('Do you want to see the code that has been executed? (type y/Y to see the code) > ', 'white')); |
|
| 178 | + $response = Console::ask($base.Console::text('Do you want to see the code that has been executed? (type y/Y to see the code) > ', 'white')); |
|
| 179 | 179 | if (strtoupper($response) === 'Y') { |
| 180 | - Console::log($base . Console::text('The code in file [', 'white') . |
|
| 181 | - Console::text( $fileName, 'lightcyan') . |
|
| 180 | + Console::log($base.Console::text('The code in file [', 'white'). |
|
| 181 | + Console::text($fileName, 'lightcyan'). |
|
| 182 | 182 | Console::text('] is:', 'white')); |
| 183 | 183 | Console::log(); |
| 184 | 184 | |
@@ -186,29 +186,29 @@ discard block |
||
| 186 | 186 | $count = 1; |
| 187 | 187 | |
| 188 | 188 | Console::log(Console::pad(' ', 100, '-'), 'darkgray'); |
| 189 | - foreach($lines as $line){ |
|
| 189 | + foreach ($lines as $line) { |
|
| 190 | 190 | $codeLine = rtrim($line); |
| 191 | 191 | $isComment = substr(ltrim($codeLine), 0, 2) === '//'; |
| 192 | 192 | $isPhp = substr(ltrim($codeLine), 0, 5) === '<?php' || substr(ltrim($codeLine), 0, 2) === '?>'; |
| 193 | 193 | $color = $isPhp ? 'blue' : ($isComment ? 'green' : 'lightgray'); |
| 194 | - Console::log(' '. Console::text($codeLine, $color)); |
|
| 194 | + Console::log(' '.Console::text($codeLine, $color)); |
|
| 195 | 195 | $count++; |
| 196 | 196 | } |
| 197 | 197 | Console::log(Console::pad(' ', 100, '-'), 'darkgray'); |
| 198 | 198 | Console::log(); |
| 199 | 199 | } |
| 200 | 200 | } else { |
| 201 | - Console::log($base . Console::text('Error' , 'red')); |
|
| 202 | - Console::log($base . Console::text(' => File missing [' . $fileName . ']' , 'red')); |
|
| 201 | + Console::log($base.Console::text('Error', 'red')); |
|
| 202 | + Console::log($base.Console::text(' => File missing ['.$fileName.']', 'red')); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | } else { |
| 206 | - Console::log($base . Console::text('Error:', 'red')); |
|
| 207 | - Console::log($base . Console::text('=> the value you entered is not a valid index number.', 'red')); |
|
| 206 | + Console::log($base.Console::text('Error:', 'red')); |
|
| 207 | + Console::log($base.Console::text('=> the value you entered is not a valid index number.', 'red')); |
|
| 208 | 208 | askIndex(); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - Console::ask($base . Console::text('Press [Enter] to go back to index > ', 'white')); |
|
| 211 | + Console::ask($base.Console::text('Press [Enter] to go back to index > ', 'white')); |
|
| 212 | 212 | goIndex(); |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | \ No newline at end of file |
@@ -1,23 +1,23 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -require_once __DIR__ .'/../vendor/autoload.php'; |
|
| 2 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 3 | 3 | use Kristuff\Mishell\Console; |
| 4 | 4 | |
| 5 | 5 | console::resetDefaults(); |
| 6 | 6 | |
| 7 | -Console::log(' ' . Console::text('Basic sample', 'white', 'underlined')); |
|
| 7 | +Console::log(' '.Console::text('Basic sample', 'white', 'underlined')); |
|
| 8 | 8 | Console::log(); |
| 9 | 9 | |
| 10 | 10 | $rowHeaders = ['Index' => 10, 'Item' => 25, 'Description' => 50]; |
| 11 | 11 | $rows = [ |
| 12 | - ['foo', 'some text for foo'], |
|
| 13 | - ['bar', 'some text for bar'], |
|
| 14 | - ['foobar', 'some text for foobar'] |
|
| 12 | + ['foo', 'some text for foo'], |
|
| 13 | + ['bar', 'some text for bar'], |
|
| 14 | + ['foobar', 'some text for foobar'] |
|
| 15 | 15 | ]; |
| 16 | 16 | Console::log(Console::tableSeparator($rowHeaders)); |
| 17 | 17 | Console::log(Console::tableRow($rowHeaders)); |
| 18 | 18 | Console::log(Console::tableRowSeparator($rowHeaders)); |
| 19 | 19 | |
| 20 | -foreach ($rows as $key => $value){ |
|
| 20 | +foreach ($rows as $key => $value) { |
|
| 21 | 21 | Console::log(Console::tableRow([ |
| 22 | 22 | $key => 10, |
| 23 | 23 | $rows[$key][0] => 25, |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | // ------------------------------- |
| 35 | 35 | // ------ ADVANCED SAMPLE -------- |
| 36 | 36 | // ------------------------------- |
| 37 | -Console::log(' ' . Console::text('Advanced sample', 'white', 'underlined')); |
|
| 37 | +Console::log(' '.Console::text('Advanced sample', 'white', 'underlined')); |
|
| 38 | 38 | Console::log(); |
| 39 | 39 | |
| 40 | 40 | $rowHeaders = [ |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | ]; |
| 45 | 45 | $rows = [ |
| 46 | 46 | [ |
| 47 | - Console::text('foo', 'white'), |
|
| 47 | + Console::text('foo', 'white'), |
|
| 48 | 48 | Console::text('some centered text red for foo', 'red') |
| 49 | 49 | ], |
| 50 | 50 | [ |
| 51 | - Console::text('bar', 'white'), |
|
| 52 | - Console::text( 'some centered text green for bar', 'green') |
|
| 51 | + Console::text('bar', 'white'), |
|
| 52 | + Console::text('some centered text green for bar', 'green') |
|
| 53 | 53 | ], |
| 54 | 54 | [ |
| 55 | 55 | Console::text('foobar', 'white'), |
| 56 | - 'some text with unicode ✓ ' .Console::text('on BLUE here', 'white', 'blue') |
|
| 56 | + 'some text with unicode ✓ '.Console::text('on BLUE here', 'white', 'blue') |
|
| 57 | 57 | ] |
| 58 | 58 | ]; |
| 59 | 59 | |
@@ -66,24 +66,24 @@ discard block |
||
| 66 | 66 | Console::$tableCellPadding = ' '; // increase cell padding to 2 white chars (default is 1) |
| 67 | 67 | |
| 68 | 68 | // table start |
| 69 | -Console::log(Console::tableSeparator($rowHeaders)); // top line |----------------------- ... |
|
| 70 | -Console::log(Console::tableRow($rowHeaders)); // columns headers | foo | bar |--- ... |
|
| 69 | +Console::log(Console::tableSeparator($rowHeaders)); // top line |----------------------- ... |
|
| 70 | +Console::log(Console::tableRow($rowHeaders)); // columns headers | foo | bar |--- ... |
|
| 71 | 71 | Console::log(Console::tableRowSeparator($rowHeaders)); // saparator |---------|---------|--- ... |
| 72 | -Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 72 | +Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 73 | 73 | |
| 74 | 74 | // tables rows |
| 75 | -foreach ($rows as $key => $value){ |
|
| 75 | +foreach ($rows as $key => $value) { |
|
| 76 | 76 | |
| 77 | 77 | Console::log( |
| 78 | - Console::TableRowStart(). // start row with separator. Then, each cell will end with a separator |
|
| 79 | - Console::TableRowCell($key, 10). //no align => default is left |
|
| 80 | - Console::TableRowCell($rows[$key][0] , 25, Console::ALIGN_RIGHT). //set align right |
|
| 81 | - Console::TableRowCell($rows[$key][1] , 50, Console::ALIGN_CENTER) //set align center |
|
| 78 | + Console::TableRowStart().// start row with separator. Then, each cell will end with a separator |
|
| 79 | + Console::TableRowCell($key, 10).//no align => default is left |
|
| 80 | + Console::TableRowCell($rows[$key][0], 25, Console::ALIGN_RIGHT).//set align right |
|
| 81 | + Console::TableRowCell($rows[$key][1], 50, Console::ALIGN_CENTER) //set align center |
|
| 82 | 82 | ); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // table end |
| 86 | -Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 86 | +Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 87 | 87 | Console::log(Console::tableSeparator($rowHeaders)); // saparator |----------------------- ... |
| 88 | 88 | console::resetDefaults(); |
| 89 | 89 | |
@@ -91,38 +91,38 @@ discard block |
||
| 91 | 91 | // ------ ANOTHER STYLE --------- |
| 92 | 92 | // ------------------------------- |
| 93 | 93 | Console::log(); |
| 94 | -Console::log(' ' . Console::text('Another style sample', 'white', 'underlined')); |
|
| 94 | +Console::log(' '.Console::text('Another style sample', 'white', 'underlined')); |
|
| 95 | 95 | Console::log(); |
| 96 | 96 | |
| 97 | 97 | $rowHeaders = [ |
| 98 | - Console::text('Item', 'darkgray') => 10, |
|
| 99 | - Console::text('Status', 'darkgray') => 12, |
|
| 100 | - Console::text('Description', 'darkgray') => 25 |
|
| 98 | + Console::text('Item', 'darkgray') => 10, |
|
| 99 | + Console::text('Status', 'darkgray') => 12, |
|
| 100 | + Console::text('Description', 'darkgray') => 25 |
|
| 101 | 101 | ]; |
| 102 | 102 | $rows = [ |
| 103 | - [Console::text('foo', 'white'), Console::text(' ONLINE ', 'white', 'green') , Console::text('some text for foo', 'white')], |
|
| 104 | - [Console::text('bar', 'white'), Console::text(' ONLINE ', 'white', 'green') , Console::text('some text for bar', 'white')], |
|
| 105 | - [Console::text('foobar ', 'white'), Console::text(' OFFLINE ', 'white', 'red') , Console::text('some text for foobar', 'white')] |
|
| 103 | + [Console::text('foo', 'white'), Console::text(' ONLINE ', 'white', 'green'), Console::text('some text for foo', 'white')], |
|
| 104 | + [Console::text('bar', 'white'), Console::text(' ONLINE ', 'white', 'green'), Console::text('some text for bar', 'white')], |
|
| 105 | + [Console::text('foobar ', 'white'), Console::text(' OFFLINE ', 'white', 'red'), Console::text('some text for foobar', 'white')] |
|
| 106 | 106 | ]; |
| 107 | 107 | |
| 108 | -Console::$horizontalSeparator = '-'; // change the horizontal separator |
|
| 109 | -Console::$tableCellPadding = ''; // no padding |
|
| 110 | -Console::$verticalInnerSeparator = ' '; // blank separator |
|
| 111 | - Console::$verticalSeparator = ' '; // no top left/right separator except a margin.. |
|
| 108 | +Console::$horizontalSeparator = '-'; // change the horizontal separator |
|
| 109 | +Console::$tableCellPadding = ''; // no padding |
|
| 110 | +Console::$verticalInnerSeparator = ' '; // blank separator |
|
| 111 | + Console::$verticalSeparator = ' '; // no top left/right separator except a margin.. |
|
| 112 | 112 | // Console::$verticalHeaderSeparator = ''; // no top left/right separator (not needed) |
| 113 | 113 | |
| 114 | 114 | // table start |
| 115 | 115 | Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- --- |
| 116 | -Console::log(Console::tableRow($rowHeaders, 'drakgray')); // columns headers foo bar f... |
|
| 116 | +Console::log(Console::tableRow($rowHeaders, 'drakgray')); // columns headers foo bar f... |
|
| 117 | 117 | Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- --- |
| 118 | 118 | |
| 119 | 119 | // tables rows |
| 120 | -foreach ($rows as $row){ |
|
| 120 | +foreach ($rows as $row) { |
|
| 121 | 121 | Console::log( |
| 122 | - Console::TableRowStart(). // start row with separator. Then, each cell will end with a separator |
|
| 123 | - Console::TableRowCell($row[0] , 10). // keep align right left |
|
| 124 | - Console::TableRowCell($row[1] , 12, Console::ALIGN_CENTER). // align center |
|
| 125 | - Console::TableRowCell($row[2] , 25) // keep align right left |
|
| 122 | + Console::TableRowStart().// start row with separator. Then, each cell will end with a separator |
|
| 123 | + Console::TableRowCell($row[0], 10).// keep align right left |
|
| 124 | + Console::TableRowCell($row[1], 12, Console::ALIGN_CENTER).// align center |
|
| 125 | + Console::TableRowCell($row[2], 25) // keep align right left |
|
| 126 | 126 | ); |
| 127 | 127 | } |
| 128 | 128 | // table end |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | 'magenta' => '35', |
| 38 | 38 | 'cyan' => '36', |
| 39 | 39 | 'lightgray' => '37', |
| 40 | - 'default' => '39', // your default color |
|
| 40 | + 'default' => '39', // your default color |
|
| 41 | 41 | 'darkgray' => '90', |
| 42 | 42 | 'lightred' => '91', |
| 43 | 43 | 'lightgreen' => '92', |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * @var array |
| 84 | 84 | */ |
| 85 | 85 | protected static $options = array( |
| 86 | - 'none' => '0', // reset all styles |
|
| 87 | - 'bold' => '1', // |
|
| 86 | + 'none' => '0', // reset all styles |
|
| 87 | + 'bold' => '1', // |
|
| 88 | 88 | 'dim' => '2', |
| 89 | 89 | 'underlined' => '4', |
| 90 | 90 | 'blink' => '5', |
| 91 | - 'reverse' => '7', // reverse foreground/background color |
|
| 91 | + 'reverse' => '7', // reverse foreground/background color |
|
| 92 | 92 | |
| 93 | 93 | //formats=(["bold"]=1 ["bright"]=1 ["dim"]=2 ["underlined"]=4 ["blink"]=5 ["reverse"]=7 ["hidden"]=8) |
| 94 | 94 | //resets=(["all"]=0 ["bold"]=21 ["bright"]=21 ["dim"]=22 ["underlined"]=24 ["blink"]=25 ["reverse"]=27 ["hidden"]=28) |
@@ -130,27 +130,27 @@ discard block |
||
| 130 | 130 | array_shift($args); |
| 131 | 131 | |
| 132 | 132 | // |
| 133 | - switch($command){ |
|
| 133 | + switch ($command) { |
|
| 134 | 134 | |
| 135 | 135 | // **************************************** |
| 136 | 136 | // Get methods (return string) |
| 137 | 137 | // **************************************** |
| 138 | 138 | |
| 139 | 139 | case'text': |
| 140 | - return self::getCliString($str, $args); // get formated text |
|
| 140 | + return self::getCliString($str, $args); // get formated text |
|
| 141 | 141 | |
| 142 | 142 | // **************************************** |
| 143 | 143 | // Print methods (echo and return null) |
| 144 | 144 | // **************************************** |
| 145 | 145 | |
| 146 | 146 | case'print': |
| 147 | - echo (self::getCliString($str, $args)); // print text |
|
| 147 | + echo (self::getCliString($str, $args)); // print text |
|
| 148 | 148 | break; |
| 149 | 149 | case'log': |
| 150 | - echo (self::getCliString($str, $args) . self::$EOF ); // print text + newline |
|
| 150 | + echo (self::getCliString($str, $args).self::$EOF); // print text + newline |
|
| 151 | 151 | break; |
| 152 | 152 | case'relog': |
| 153 | - echo (self::getCliString($str ."\r", $args)); // overwrite current line |
|
| 153 | + echo (self::getCliString($str."\r", $args)); // overwrite current line |
|
| 154 | 154 | break; |
| 155 | 155 | |
| 156 | 156 | // ***************************************** |
@@ -158,19 +158,19 @@ discard block |
||
| 158 | 158 | // ***************************************** |
| 159 | 159 | |
| 160 | 160 | case'ask': |
| 161 | - echo (self::getCliString($str, $args)); // print question |
|
| 162 | - return trim(fgets(STDIN)); // reads and return one line from STDIN |
|
| 161 | + echo (self::getCliString($str, $args)); // print question |
|
| 162 | + return trim(fgets(STDIN)); // reads and return one line from STDIN |
|
| 163 | 163 | |
| 164 | 164 | case'askPassword': |
| 165 | - self::hideInput(); // hide |
|
| 166 | - echo (self::getCliString($str, $args)); // print question |
|
| 167 | - $line= trim(fgets(STDIN)); // reads one line from STDIN |
|
| 168 | - self::restoreInput(); // restore |
|
| 169 | - return $line; // return line |
|
| 165 | + self::hideInput(); // hide |
|
| 166 | + echo (self::getCliString($str, $args)); // print question |
|
| 167 | + $line = trim(fgets(STDIN)); // reads one line from STDIN |
|
| 168 | + self::restoreInput(); // restore |
|
| 169 | + return $line; // return line |
|
| 170 | 170 | |
| 171 | 171 | case 'askInt': |
| 172 | - echo (self::getCliString($str, $args)); // print question |
|
| 173 | - fscanf(STDIN, "%d\n", $number); // reads number from STDIN |
|
| 172 | + echo (self::getCliString($str, $args)); // print question |
|
| 173 | + fscanf(STDIN, "%d\n", $number); // reads number from STDIN |
|
| 174 | 174 | return (is_int($number) ? $number : false); // return int value or false |
| 175 | 175 | } |
| 176 | 176 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | protected static function getCliString(string $str, array $arguments = []) |
| 192 | 192 | { |
| 193 | - if (empty($arguments)){ |
|
| 193 | + if (empty($arguments)) { |
|
| 194 | 194 | return $str; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -203,25 +203,25 @@ discard block |
||
| 203 | 203 | foreach ($arguments as $argument) { |
| 204 | 204 | |
| 205 | 205 | // it's a color? |
| 206 | - if(!$hasColor && isset(self::$foregroundColors[$argument])){ |
|
| 206 | + if (!$hasColor && isset(self::$foregroundColors[$argument])) { |
|
| 207 | 207 | $cliArgs[] = self::$foregroundColors[$argument]; |
| 208 | 208 | $hasColor = true; |
| 209 | 209 | |
| 210 | 210 | // it's a backcolor? |
| 211 | - } elseif ($hasColor && !$hasBackColor && isset(self::$backgroundColors[$argument])){ |
|
| 211 | + } elseif ($hasColor && !$hasBackColor && isset(self::$backgroundColors[$argument])) { |
|
| 212 | 212 | $cliArgs[] = self::$backgroundColors[$argument]; |
| 213 | 213 | $hasBackColor = true; |
| 214 | 214 | |
| 215 | 215 | // or it's an option? |
| 216 | - } elseif (isset(self::$options[$argument])){ |
|
| 216 | + } elseif (isset(self::$options[$argument])) { |
|
| 217 | 217 | $cliArgs[] = self::$options[$argument]; |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | // Add string and end coloring |
| 222 | 222 | // todo \e[0m |
| 223 | - $coloredString .= "\033[" . implode(';',$cliArgs) .'m'; |
|
| 224 | - $coloredString .= $str . "\033[0m"; |
|
| 223 | + $coloredString .= "\033[".implode(';', $cliArgs).'m'; |
|
| 224 | + $coloredString .= $str."\033[0m"; |
|
| 225 | 225 | return $coloredString; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | */ |
| 306 | 306 | public static function askPassword() |
| 307 | 307 | { |
| 308 | - return self::cmd('askPassword',func_get_args()); |
|
| 308 | + return self::cmd('askPassword', func_get_args()); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | public static function log() |
| 324 | 324 | { |
| 325 | - self::cmd('log',func_get_args()); |
|
| 325 | + self::cmd('log', func_get_args()); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | public static function relog() |
| 341 | 341 | { |
| 342 | - self::cmd('relog',func_get_args()); |
|
| 342 | + self::cmd('relog', func_get_args()); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
@@ -356,20 +356,20 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | public static function pad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT) |
| 358 | 358 | { |
| 359 | - $diff = $padLength - mb_strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input)); |
|
| 359 | + $diff = $padLength-mb_strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input)); |
|
| 360 | 360 | |
| 361 | - if ($diff > 0){ |
|
| 362 | - switch ($padType){ |
|
| 361 | + if ($diff > 0) { |
|
| 362 | + switch ($padType) { |
|
| 363 | 363 | |
| 364 | 364 | case STR_PAD_RIGHT: |
| 365 | - return $input . str_repeat($padString, $diff); |
|
| 365 | + return $input.str_repeat($padString, $diff); |
|
| 366 | 366 | |
| 367 | 367 | case STR_PAD_LEFT: |
| 368 | - return str_repeat($padString, $diff ) . $input; |
|
| 368 | + return str_repeat($padString, $diff).$input; |
|
| 369 | 369 | |
| 370 | 370 | case STR_PAD_BOTH: |
| 371 | 371 | $padLeft = round(($diff)/2); |
| 372 | - return str_repeat($padString, $padLeft) . $input . str_repeat($padString, $diff - $padLeft); |
|
| 372 | + return str_repeat($padString, $padLeft).$input.str_repeat($padString, $diff-$padLeft); |
|
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | return $input; |