@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | 31 | protected static $foregroundColors = array( |
| 32 | - 'normal' => '39', // your default color |
|
| 32 | + 'normal' => '39', // your default color |
|
| 33 | 33 | 'black' => '30', |
| 34 | 34 | 'grey' => '1;30', |
| 35 | 35 | 'lightgrey' => '37', |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | * @var array |
| 75 | 75 | */ |
| 76 | 76 | protected static $options = array( |
| 77 | - 'none' => '0', // reset all styles |
|
| 78 | - 'bold' => '1', // |
|
| 77 | + 'none' => '0', // reset all styles |
|
| 78 | + 'bold' => '1', // |
|
| 79 | 79 | 'underline' => '4', |
| 80 | 80 | 'blink' => '5', |
| 81 | - 'reverse' => '7', // reverse foreground/background color |
|
| 81 | + 'reverse' => '7', // reverse foreground/background color |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -117,27 +117,27 @@ discard block |
||
| 117 | 117 | array_shift($args); |
| 118 | 118 | |
| 119 | 119 | // |
| 120 | - switch($command){ |
|
| 120 | + switch ($command) { |
|
| 121 | 121 | |
| 122 | 122 | // **************************************** |
| 123 | 123 | // Get methods (return string) |
| 124 | 124 | // **************************************** |
| 125 | 125 | |
| 126 | 126 | case'text': |
| 127 | - return self::getCliString($str, $args); // get formated text |
|
| 127 | + return self::getCliString($str, $args); // get formated text |
|
| 128 | 128 | |
| 129 | 129 | // **************************************** |
| 130 | 130 | // Print methods (echo and return null) |
| 131 | 131 | // **************************************** |
| 132 | 132 | |
| 133 | 133 | case'print': |
| 134 | - echo (self::getCliString($str, $args)); // print text |
|
| 134 | + echo (self::getCliString($str, $args)); // print text |
|
| 135 | 135 | break; |
| 136 | 136 | case'log': |
| 137 | - echo (self::getCliString($str, $args) . self::$EOF ); // print text + newline |
|
| 137 | + echo (self::getCliString($str, $args).self::$EOF); // print text + newline |
|
| 138 | 138 | break; |
| 139 | 139 | case'relog': |
| 140 | - echo (self::getCliString($str ."\r", $args)); // overwrite current line |
|
| 140 | + echo (self::getCliString($str."\r", $args)); // overwrite current line |
|
| 141 | 141 | break; |
| 142 | 142 | |
| 143 | 143 | // ***************************************** |
@@ -145,19 +145,19 @@ discard block |
||
| 145 | 145 | // ***************************************** |
| 146 | 146 | |
| 147 | 147 | case'ask': |
| 148 | - echo (self::getCliString($str, $args)); // print question |
|
| 149 | - return trim(fgets(STDIN)); // reads and return one line from STDIN |
|
| 148 | + echo (self::getCliString($str, $args)); // print question |
|
| 149 | + return trim(fgets(STDIN)); // reads and return one line from STDIN |
|
| 150 | 150 | |
| 151 | 151 | case'askPassword': |
| 152 | - self::hideInput(); // hide |
|
| 153 | - echo (self::getCliString($str, $args)); // print question |
|
| 154 | - $line= trim(fgets(STDIN)); // reads one line from STDIN |
|
| 155 | - self::restoreInput(); // restore |
|
| 156 | - return $line; // return line |
|
| 152 | + self::hideInput(); // hide |
|
| 153 | + echo (self::getCliString($str, $args)); // print question |
|
| 154 | + $line = trim(fgets(STDIN)); // reads one line from STDIN |
|
| 155 | + self::restoreInput(); // restore |
|
| 156 | + return $line; // return line |
|
| 157 | 157 | |
| 158 | 158 | case 'askInt': |
| 159 | - echo (self::getCliString($str, $args)); // print question |
|
| 160 | - fscanf(STDIN, "%d\n", $number); // reads number from STDIN |
|
| 159 | + echo (self::getCliString($str, $args)); // print question |
|
| 160 | + fscanf(STDIN, "%d\n", $number); // reads number from STDIN |
|
| 161 | 161 | return (is_int($number) ? $number : false); // return int value or false |
| 162 | 162 | } |
| 163 | 163 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | protected static function getCliString($str, array $arguments = []) |
| 179 | 179 | { |
| 180 | - if (empty($arguments)){ |
|
| 180 | + if (empty($arguments)) { |
|
| 181 | 181 | return $str; |
| 182 | 182 | } |
| 183 | 183 | |
@@ -190,24 +190,24 @@ discard block |
||
| 190 | 190 | foreach ($arguments as $argument) { |
| 191 | 191 | |
| 192 | 192 | // it's a color? |
| 193 | - if(!$hasColor && isset(self::$foregroundColors[$argument])){ |
|
| 193 | + if (!$hasColor && isset(self::$foregroundColors[$argument])) { |
|
| 194 | 194 | $cliArgs[] = self::$foregroundColors[$argument]; |
| 195 | 195 | $hasColor = true; |
| 196 | 196 | |
| 197 | 197 | // it's a backcolor? |
| 198 | - } elseif ($hasColor && !$hasBackColor && isset(self::$backgroundColors[$argument])){ |
|
| 198 | + } elseif ($hasColor && !$hasBackColor && isset(self::$backgroundColors[$argument])) { |
|
| 199 | 199 | $cliArgs[] = self::$backgroundColors[$argument]; |
| 200 | 200 | $hasBackColor = true; |
| 201 | 201 | |
| 202 | 202 | // or it's an option? |
| 203 | - } elseif (isset(self::$options[$argument])){ |
|
| 203 | + } elseif (isset(self::$options[$argument])) { |
|
| 204 | 204 | $cliArgs[] = self::$options[$argument]; |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // Add string and end coloring |
| 209 | - $coloredString .= "\033[" . implode(';',$cliArgs) .'m'; |
|
| 210 | - $coloredString .= $str . "\033[0m"; |
|
| 209 | + $coloredString .= "\033[".implode(';', $cliArgs).'m'; |
|
| 210 | + $coloredString .= $str."\033[0m"; |
|
| 211 | 211 | return $coloredString; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | public static function askPassword() |
| 293 | 293 | { |
| 294 | - return self::cmd('askPassword',func_get_args()); |
|
| 294 | + return self::cmd('askPassword', func_get_args()); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | public static function log() |
| 310 | 310 | { |
| 311 | - self::cmd('log',func_get_args()); |
|
| 311 | + self::cmd('log', func_get_args()); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | public static function relog() |
| 327 | 327 | { |
| 328 | - self::cmd('relog',func_get_args()); |
|
| 328 | + self::cmd('relog', func_get_args()); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -342,20 +342,20 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | public function pad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT) |
| 344 | 344 | { |
| 345 | - $diff = $padLength - strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input)); |
|
| 345 | + $diff = $padLength-strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input)); |
|
| 346 | 346 | |
| 347 | - if ($diff > 0){ |
|
| 348 | - switch ($padType){ |
|
| 347 | + if ($diff > 0) { |
|
| 348 | + switch ($padType) { |
|
| 349 | 349 | |
| 350 | 350 | case STR_PAD_RIGHT: |
| 351 | - return $input . str_repeat($padString, $diff); |
|
| 351 | + return $input.str_repeat($padString, $diff); |
|
| 352 | 352 | |
| 353 | 353 | case STR_PAD_LEFT: |
| 354 | - return str_repeat($padString, $diff ) . $input; |
|
| 354 | + return str_repeat($padString, $diff).$input; |
|
| 355 | 355 | |
| 356 | 356 | case STR_PAD_BOTH: |
| 357 | 357 | $padLeft = round(($diff)/2); |
| 358 | - return str_repeat($padString, $padLeft) . $input . str_repeat($padString, $diff - $padLeft); |
|
| 358 | + return str_repeat($padString, $padLeft).$input.str_repeat($padString, $diff-$padLeft); |
|
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | return $input; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ .'/../vendor/autoload.php'; |
|
| 3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 4 | 4 | use Kristuff\Mishell\Console; |
| 5 | 5 | |
| 6 | 6 | Console::log('Basic sample', 'white', 'magenta'); |
@@ -8,15 +8,15 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | $rowHeaders = ['Index' => 10, 'Item' => 25, 'Description' => 50]; |
| 10 | 10 | $rows = [ |
| 11 | - ['foo', 'some text for foo'], |
|
| 12 | - ['bar', 'some text for bar'], |
|
| 13 | - ['foobar', 'some text for foobar'] |
|
| 11 | + ['foo', 'some text for foo'], |
|
| 12 | + ['bar', 'some text for bar'], |
|
| 13 | + ['foobar', 'some text for foobar'] |
|
| 14 | 14 | ]; |
| 15 | 15 | Console::log(Console::tableSeparator($rowHeaders)); |
| 16 | 16 | Console::log(Console::tableRow($rowHeaders)); |
| 17 | 17 | Console::log(Console::tableRowSeparator($rowHeaders)); |
| 18 | 18 | |
| 19 | -foreach ($rows as $key => $value){ |
|
| 19 | +foreach ($rows as $key => $value) { |
|
| 20 | 20 | Console::log(Console::tableRow([ |
| 21 | 21 | $key => 10, |
| 22 | 22 | $rows[$key][0] => 25, |
@@ -43,16 +43,16 @@ discard block |
||
| 43 | 43 | ]; |
| 44 | 44 | $rows = [ |
| 45 | 45 | [ |
| 46 | - Console::text('foo (on right)', 'white'), |
|
| 46 | + Console::text('foo (on right)', 'white'), |
|
| 47 | 47 | Console::text('some centered text red for foo', 'red') |
| 48 | 48 | ], |
| 49 | 49 | [ |
| 50 | - Console::text('bar (on right)', 'white'), |
|
| 51 | - Console::text( 'some centered text grey for bar', 'grey') |
|
| 50 | + Console::text('bar (on right)', 'white'), |
|
| 51 | + Console::text('some centered text grey for bar', 'grey') |
|
| 52 | 52 | ], |
| 53 | 53 | [ |
| 54 | 54 | Console::text('foobar (on right)', 'white'), |
| 55 | - 'some centered text ' .Console::text('on BLUE here', 'white', 'blue'). ' for foobar' |
|
| 55 | + 'some centered text '.Console::text('on BLUE here', 'white', 'blue').' for foobar' |
|
| 56 | 56 | ] |
| 57 | 57 | ]; |
| 58 | 58 | |
@@ -65,23 +65,23 @@ discard block |
||
| 65 | 65 | Console::$tableCellPadding = ' '; // increase cell padding to 2 white chars (default is 1) |
| 66 | 66 | |
| 67 | 67 | // table start |
| 68 | -Console::log(Console::tableSeparator($rowHeaders)); // top line |----------------------- ... |
|
| 69 | -Console::log(Console::tableRow($rowHeaders)); // columns headers | foo | bar |--- ... |
|
| 68 | +Console::log(Console::tableSeparator($rowHeaders)); // top line |----------------------- ... |
|
| 69 | +Console::log(Console::tableRow($rowHeaders)); // columns headers | foo | bar |--- ... |
|
| 70 | 70 | Console::log(Console::tableRowSeparator($rowHeaders)); // saparator |---------|---------|--- ... |
| 71 | -Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 71 | +Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 72 | 72 | |
| 73 | 73 | // tables rows |
| 74 | -foreach ($rows as $key => $value){ |
|
| 74 | +foreach ($rows as $key => $value) { |
|
| 75 | 75 | |
| 76 | 76 | Console::log( |
| 77 | - Console::TableRowStart(). // start row with separator. Then, each cell will end with a separator |
|
| 78 | - Console::TableRowCell($key, 10). //no align => default is left |
|
| 79 | - Console::TableRowCell($rows[$key][0] , 25, Console::ALIGN_RIGHT). //set align right |
|
| 80 | - Console::TableRowCell($rows[$key][1] , 50, Console::ALIGN_CENTER) //set align center |
|
| 77 | + Console::TableRowStart().// start row with separator. Then, each cell will end with a separator |
|
| 78 | + Console::TableRowCell($key, 10).//no align => default is left |
|
| 79 | + Console::TableRowCell($rows[$key][0], 25, Console::ALIGN_RIGHT).//set align right |
|
| 80 | + Console::TableRowCell($rows[$key][1], 50, Console::ALIGN_CENTER) //set align center |
|
| 81 | 81 | ); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // table end |
| 85 | -Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 85 | +Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
|
| 86 | 86 | Console::log(Console::tableSeparator($rowHeaders)); // saparator |----------------------- ... |
| 87 | 87 | |
@@ -1,10 +1,10 @@ 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::log('Overview:', 'underline', 'bold'); |
| 6 | -Console::log(" - Use " . Console::text("int Console::getLines()", 'blue', 'white') . " get the number of lines in terminal."); |
|
| 7 | -Console::log(" - Use " . Console::text("int Console::getColumns()", 'blue', 'white') . " get the number of columns in terminal."); |
|
| 6 | +Console::log(" - Use ".Console::text("int Console::getLines()", 'blue', 'white')." get the number of lines in terminal."); |
|
| 7 | +Console::log(" - Use ".Console::text("int Console::getColumns()", 'blue', 'white')." get the number of columns in terminal."); |
|
| 8 | 8 | Console::log(''); |
| 9 | 9 | Console::log(''); |
| 10 | 10 | Console::log('Sample:', 'underline', 'bold'); |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | $cols = Console::getColumns(); |
| 16 | 16 | |
| 17 | 17 | // print value |
| 18 | -Console::log('The number of lines is currently: ' .Console::text($lines, 'green')); |
|
| 19 | -Console::log('The number of columns is currently: ' .Console::text($cols, 'green')); |
|
| 18 | +Console::log('The number of lines is currently: '.Console::text($lines, 'green')); |
|
| 19 | +Console::log('The number of columns is currently: '.Console::text($cols, 'green')); |
|
| 20 | 20 | Console::log(''); |
| 21 | 21 | |
| 22 | 22 | // build a 'full' row |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $i = 0; |
| 128 | 128 | foreach (getIndex() as $key => $value){ |
| 129 | 129 | |
| 130 | - if (file_exists( __DIR__ . '/'. $value[2])) { |
|
| 130 | + if (file_exists( __DIR__ . '/'. $value[2])) { |
|
| 131 | 131 | Console::log(' '. |
| 132 | 132 | Console::tableRow([ |
| 133 | 133 | $key => 10, |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | ], |
| 137 | 137 | 'white', 'black' |
| 138 | 138 | |
| 139 | - // ($i % 2 == 1) ? 'white' : 'white', |
|
| 140 | - // ($i % 2 == 1) ? 'cyan' : 'lightgrey', |
|
| 141 | - // ($i % 2 == 1) ? '' : 'bold' |
|
| 139 | + // ($i % 2 == 1) ? 'white' : 'white', |
|
| 140 | + // ($i % 2 == 1) ? 'cyan' : 'lightgrey', |
|
| 141 | + // ($i % 2 == 1) ? '' : 'bold' |
|
| 142 | 142 | ) |
| 143 | 143 | ); |
| 144 | 144 | $i++; |
@@ -183,23 +183,23 @@ discard block |
||
| 183 | 183 | printSampleHeader($selectedIndex, $title); |
| 184 | 184 | |
| 185 | 185 | Console::log($base . Console::text('Start running [', 'white') . |
| 186 | - Console::text( $title, 'lightcyan') . |
|
| 187 | - Console::text('] in file [', 'white') . |
|
| 188 | - Console::text( $fileName, 'lightcyan') . |
|
| 189 | - Console::text(']', 'white')); |
|
| 186 | + Console::text( $title, 'lightcyan') . |
|
| 187 | + Console::text('] in file [', 'white') . |
|
| 188 | + Console::text( $fileName, 'lightcyan') . |
|
| 189 | + Console::text(']', 'white')); |
|
| 190 | 190 | |
| 191 | 191 | if (file_exists($filePath)){ |
| 192 | 192 | Console::log(); |
| 193 | 193 | include $filePath; |
| 194 | 194 | Console::log(); |
| 195 | 195 | Console::log($base . Console::text('End running [', 'white') . |
| 196 | - Console::text( $title, 'lightcyan') . |
|
| 197 | - Console::text(']', 'white')); |
|
| 196 | + Console::text( $title, 'lightcyan') . |
|
| 197 | + Console::text(']', 'white')); |
|
| 198 | 198 | $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')); |
| 199 | - if (strtoupper($response) === 'Y') { |
|
| 199 | + if (strtoupper($response) === 'Y') { |
|
| 200 | 200 | Console::log($base . Console::text('The code in file [', 'white') . |
| 201 | - Console::text( $fileName, 'lightcyan') . |
|
| 202 | - Console::text('] is:', 'white')); |
|
| 201 | + Console::text( $fileName, 'lightcyan') . |
|
| 202 | + Console::text('] is:', 'white')); |
|
| 203 | 203 | Console::log(); |
| 204 | 204 | |
| 205 | 205 | $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | Console::log(); |
| 217 | 217 | } |
| 218 | - } else { |
|
| 218 | + } else { |
|
| 219 | 219 | Console::log($base . Console::text('Error' , 'red')); |
| 220 | 220 | Console::log($base . Console::text(' => File missing [' . $fileName . ']' , 'red')); |
| 221 | - } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | 223 | } else { |
| 224 | 224 | Console::log($base . Console::text('Error:', 'red')); |
@@ -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,26 +18,26 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | Console::log(); |
| 20 | 20 | Console::log(); |
| 21 | - Console::log(' '. Console::text(" _ ", 'black', 'white') . Console::text(" ____ _ _ _ ", 'magenta', 'white')); |
|
| 22 | - Console::log(' '. Console::text(" _ __ ___ (_) ", 'black', 'white') . Console::text(" / ___|| |__ ___| | | ", 'magenta', 'white')); |
|
| 23 | - Console::log(' '. Console::text(" | '_ ` _ \| | ", 'black', 'white') . Console::text(" \___ \| '_ \ / _ \ | | ", 'magenta', 'white')); |
|
| 24 | - Console::log(' '. Console::text(" | | | | | | | ", 'black', 'white') . Console::text(" ___) | | | | __/ | | ", 'magenta', 'white')); |
|
| 25 | - Console::log(' '. Console::text(" |_| |_| |_|_| ", 'black', 'white') . Console::text(" |____/|_| |_|\___|_|_| ", 'magenta', 'white')); |
|
| 26 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" ", 'magenta', 'white')); |
|
| 27 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" Version 1.0 ", 'black', 'white')); |
|
| 28 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" © 2020 Kristuff ", 'black', 'white')); |
|
| 29 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" ", 'magenta', 'white')); |
|
| 21 | + Console::log(' '.Console::text(" _ ", 'black', 'white').Console::text(" ____ _ _ _ ", 'magenta', 'white')); |
|
| 22 | + Console::log(' '.Console::text(" _ __ ___ (_) ", 'black', 'white').Console::text(" / ___|| |__ ___| | | ", 'magenta', 'white')); |
|
| 23 | + Console::log(' '.Console::text(" | '_ ` _ \| | ", 'black', 'white').Console::text(" \___ \| '_ \ / _ \ | | ", 'magenta', 'white')); |
|
| 24 | + Console::log(' '.Console::text(" | | | | | | | ", 'black', 'white').Console::text(" ___) | | | | __/ | | ", 'magenta', 'white')); |
|
| 25 | + Console::log(' '.Console::text(" |_| |_| |_|_| ", 'black', 'white').Console::text(" |____/|_| |_|\___|_|_| ", 'magenta', 'white')); |
|
| 26 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" ", 'magenta', 'white')); |
|
| 27 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" Version 1.0 ", 'black', 'white')); |
|
| 28 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" © 2020 Kristuff ", 'black', 'white')); |
|
| 29 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" ", 'magenta', 'white')); |
|
| 30 | 30 | Console::log(); |
| 31 | 31 | Console::log(); |
| 32 | 32 | |
| 33 | 33 | $pad = ' '; |
| 34 | 34 | |
| 35 | 35 | // fake progress message |
| 36 | - for ($i=0 ; $i<=100 ; $i++) { |
|
| 36 | + for ($i = 0; $i <= 100; $i++) { |
|
| 37 | 37 | |
| 38 | 38 | // Overwrite progress message. |
| 39 | 39 | Console::relog($pad.Console::text('Loading... [', 'white'). |
| 40 | - Console::text($i .'%', 'green'). |
|
| 40 | + Console::text($i.'%', 'green'). |
|
| 41 | 41 | Console::text('] completed', 'white')); |
| 42 | 42 | |
| 43 | 43 | // wait for a while, so we see the animation |
@@ -55,25 +55,25 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | |
| 58 | - $index[1] = ['Styles', 'How to get available basic styles', 'demo.styles.php']; |
|
| 59 | - $index[2] = ['Colors', 'How to get available foreground colors', 'demo.colors.php']; |
|
| 60 | - $index[3] = ['Backgrounds', 'How to get available background colors', 'demo.bgcolors.php']; |
|
| 58 | + $index[1] = ['Styles', 'How to get available basic styles', 'demo.styles.php']; |
|
| 59 | + $index[2] = ['Colors', 'How to get available foreground colors', 'demo.colors.php']; |
|
| 60 | + $index[3] = ['Backgrounds', 'How to get available background colors', 'demo.bgcolors.php']; |
|
| 61 | 61 | |
| 62 | - $index[11] = ['Ask', 'How to ask? (get user input)', 'demo.ask.php']; |
|
| 63 | - $index[12] = ['Ask Number', 'How to ask and expect a number?', 'demo.askint.php']; |
|
| 64 | - $index[13] = ['Ask Password', 'How to ask a password? (do not print user input)', 'demo.askpassword.php']; |
|
| 62 | + $index[11] = ['Ask', 'How to ask? (get user input)', 'demo.ask.php']; |
|
| 63 | + $index[12] = ['Ask Number', 'How to ask and expect a number?', 'demo.askint.php']; |
|
| 64 | + $index[13] = ['Ask Password', 'How to ask a password? (do not print user input)', 'demo.askpassword.php']; |
|
| 65 | 65 | |
| 66 | - $index[14] = ['Table', 'How to print a table?', 'demo.table.php']; |
|
| 67 | - $index[15] = ['Bell', 'How to run the bell?', 'demo.bell.php']; |
|
| 68 | - $index[16] = ['Progress', 'How to output progress message?', 'demo.progress.php']; |
|
| 69 | - $index[17] = ['New window', 'How to open new/restore window?', 'demo.window.php']; |
|
| 66 | + $index[14] = ['Table', 'How to print a table?', 'demo.table.php']; |
|
| 67 | + $index[15] = ['Bell', 'How to run the bell?', 'demo.bell.php']; |
|
| 68 | + $index[16] = ['Progress', 'How to output progress message?', 'demo.progress.php']; |
|
| 69 | + $index[17] = ['New window', 'How to open new/restore window?', 'demo.window.php']; |
|
| 70 | 70 | |
| 71 | 71 | // $index[4] = ['Text', 'Console::text() overview', 'demo.log.php']; |
| 72 | 72 | // $index[5] = ['Log', 'Console::log() overview', 'demo.log.php']; |
| 73 | 73 | // $index[6] = ['ReLog', 'Console::relog() overview', 'demo.relog.php']; |
| 74 | - $index[7] = ['Pad', 'Console::pad() overview', 'demo.pad.php']; |
|
| 75 | - $index[8] = ['Size', 'How to get the number of columns and lines in terminal', 'demo.size.php']; |
|
| 76 | - $index[9] = ['BlueScreen', 'Really nice full screen centered message sample', 'demo.bluescreen.php']; |
|
| 74 | + $index[7] = ['Pad', 'Console::pad() overview', 'demo.pad.php']; |
|
| 75 | + $index[8] = ['Size', 'How to get the number of columns and lines in terminal', 'demo.size.php']; |
|
| 76 | + $index[9] = ['BlueScreen', 'Really nice full screen centered message sample', 'demo.bluescreen.php']; |
|
| 77 | 77 | |
| 78 | 78 | return $index; |
| 79 | 79 | } |
@@ -91,16 +91,16 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | function printSampleHeader($index, $title) |
| 93 | 93 | { |
| 94 | - Console::log(' ' . Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'bold', 'underline')); |
|
| 95 | - Console::log(' ' . Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
| 96 | - Console::log(' ' . Console::text(Console::pad($index .' - ' . $title, 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
| 97 | - Console::log(' ' . Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold', 'underline')); |
|
| 94 | + Console::log(' '.Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'bold', 'underline')); |
|
| 95 | + Console::log(' '.Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
| 96 | + Console::log(' '.Console::text(Console::pad($index.' - '.$title, 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
| 97 | + Console::log(' '.Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold', 'underline')); |
|
| 98 | 98 | Console::log(); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | function printIndex() |
| 102 | 102 | { |
| 103 | - Console::log(' '. Console::text('Index:', 'underline', 'bold')); |
|
| 103 | + Console::log(' '.Console::text('Index:', 'underline', 'bold')); |
|
| 104 | 104 | $rowHeaders = ['Index' => 10, 'Item' => 25, 'Description' => 70]; |
| 105 | 105 | |
| 106 | 106 | // customize table separator |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | Console::log(' '.Console::tableRowEmpty($rowHeaders, 'white', 'black')); |
| 126 | 126 | |
| 127 | 127 | $i = 0; |
| 128 | - foreach (getIndex() as $key => $value){ |
|
| 128 | + foreach (getIndex() as $key => $value) { |
|
| 129 | 129 | |
| 130 | - if (file_exists( __DIR__ . '/'. $value[2])) { |
|
| 130 | + if (file_exists(__DIR__.'/'.$value[2])) { |
|
| 131 | 131 | Console::log(' '. |
| 132 | 132 | Console::tableRow([ |
| 133 | 133 | $key => 10, |
@@ -153,19 +153,19 @@ discard block |
||
| 153 | 153 | // -------------------- |
| 154 | 154 | |
| 155 | 155 | Console::log(''); |
| 156 | - Console::log(' ' .Console::text('Tips:', 'underline', 'bold')); |
|
| 157 | - Console::log(' '. Console::text('- At any time you can stop this program using [', 'green') .Console::text('Ctrl+C', 'black','white') .Console::text(']', 'green')); |
|
| 156 | + Console::log(' '.Console::text('Tips:', 'underline', 'bold')); |
|
| 157 | + Console::log(' '.Console::text('- At any time you can stop this program using [', 'green').Console::text('Ctrl+C', 'black', 'white').Console::text(']', 'green')); |
|
| 158 | 158 | Console::log(''); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | function askIndex() |
| 162 | 162 | { |
| 163 | - $base = Console::text('~miShell^^' , 'yellow'); |
|
| 164 | - $base .= Console::text(' $ ' , 'grey'); |
|
| 165 | - $selectedIndex = Console::askInt($base . Console::text('Enter desired index then press [Enter] to run sample > ', 'white')); |
|
| 163 | + $base = Console::text('~miShell^^', 'yellow'); |
|
| 164 | + $base .= Console::text(' $ ', 'grey'); |
|
| 165 | + $selectedIndex = Console::askInt($base.Console::text('Enter desired index then press [Enter] to run sample > ', 'white')); |
|
| 166 | 166 | $index = getIndex(); |
| 167 | 167 | |
| 168 | - switch($selectedIndex){ |
|
| 168 | + switch ($selectedIndex) { |
|
| 169 | 169 | case 0: |
| 170 | 170 | Console::log(); |
| 171 | 171 | exit(); |
@@ -176,39 +176,39 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $title = $index[$selectedIndex][0]; |
| 178 | 178 | $fileName = $index[$selectedIndex][2]; |
| 179 | - $filePath = __DIR__ . '/'. $fileName; |
|
| 179 | + $filePath = __DIR__.'/'.$fileName; |
|
| 180 | 180 | |
| 181 | 181 | Console::clear(); |
| 182 | 182 | printHeader(); |
| 183 | 183 | printSampleHeader($selectedIndex, $title); |
| 184 | 184 | |
| 185 | - Console::log($base . Console::text('Start running [', 'white') . |
|
| 186 | - Console::text( $title, 'lightcyan') . |
|
| 187 | - Console::text('] in file [', 'white') . |
|
| 188 | - Console::text( $fileName, 'lightcyan') . |
|
| 185 | + Console::log($base.Console::text('Start running [', 'white'). |
|
| 186 | + Console::text($title, 'lightcyan'). |
|
| 187 | + Console::text('] in file [', 'white'). |
|
| 188 | + Console::text($fileName, 'lightcyan'). |
|
| 189 | 189 | Console::text(']', 'white')); |
| 190 | 190 | |
| 191 | - if (file_exists($filePath)){ |
|
| 191 | + if (file_exists($filePath)) { |
|
| 192 | 192 | Console::log(); |
| 193 | 193 | include $filePath; |
| 194 | 194 | Console::log(); |
| 195 | - Console::log($base . Console::text('End running [', 'white') . |
|
| 196 | - Console::text( $title, 'lightcyan') . |
|
| 195 | + Console::log($base.Console::text('End running [', 'white'). |
|
| 196 | + Console::text($title, 'lightcyan'). |
|
| 197 | 197 | Console::text(']', 'white')); |
| 198 | - $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')); |
|
| 198 | + $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')); |
|
| 199 | 199 | if (strtoupper($response) === 'Y') { |
| 200 | - Console::log($base . Console::text('The code in file [', 'white') . |
|
| 201 | - Console::text( $fileName, 'lightcyan') . |
|
| 200 | + Console::log($base.Console::text('The code in file [', 'white'). |
|
| 201 | + Console::text($fileName, 'lightcyan'). |
|
| 202 | 202 | Console::text('] is:', 'white')); |
| 203 | 203 | Console::log(); |
| 204 | 204 | |
| 205 | 205 | $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
| 206 | 206 | $count = 1; |
| 207 | - foreach($lines as $line){ |
|
| 207 | + foreach ($lines as $line) { |
|
| 208 | 208 | $codeLine = rtrim($line); |
| 209 | 209 | $isComment = substr(ltrim($codeLine), 0, 2) === '//'; |
| 210 | 210 | Console::log( |
| 211 | - Console::pad($count . ' ', 3, ' ', STR_PAD_LEFT) . |
|
| 211 | + Console::pad($count.' ', 3, ' ', STR_PAD_LEFT). |
|
| 212 | 212 | Console::text(Console::pad($codeLine, 150), $isComment ? 'magenta' : 'black', 'white') |
| 213 | 213 | ); |
| 214 | 214 | $count++; |
@@ -216,17 +216,17 @@ discard block |
||
| 216 | 216 | Console::log(); |
| 217 | 217 | } |
| 218 | 218 | } else { |
| 219 | - Console::log($base . Console::text('Error' , 'red')); |
|
| 220 | - Console::log($base . Console::text(' => File missing [' . $fileName . ']' , 'red')); |
|
| 219 | + Console::log($base.Console::text('Error', 'red')); |
|
| 220 | + Console::log($base.Console::text(' => File missing ['.$fileName.']', 'red')); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | } else { |
| 224 | - Console::log($base . Console::text('Error:', 'red')); |
|
| 225 | - Console::log($base . Console::text('=> the value you entered is not a valid index number.', 'red')); |
|
| 224 | + Console::log($base.Console::text('Error:', 'red')); |
|
| 225 | + Console::log($base.Console::text('=> the value you entered is not a valid index number.', 'red')); |
|
| 226 | 226 | askIndex(); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - Console::ask($base . Console::text('Press [Enter] to go back to index > ', 'white')); |
|
| 229 | + Console::ask($base.Console::text('Press [Enter] to go back to index > ', 'white')); |
|
| 230 | 230 | goIndex(); |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | \ No newline at end of file |