@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @access public |
| 81 | 81 | * @var string |
| 82 | 82 | */ |
| 83 | - public static $tableCellPadding = ' '; |
|
| 83 | + public static $tableCellPadding = ' '; |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * The horizontal separator sign. |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @access public |
| 97 | 97 | * @var string |
| 98 | 98 | */ |
| 99 | - public static $verticalSeparator = '|'; |
|
| 99 | + public static $verticalSeparator = '|'; |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * The vertical header separator sign. |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @access public |
| 105 | 105 | * @var string |
| 106 | 106 | */ |
| 107 | - public static $verticalHeaderSeparator = '+'; |
|
| 107 | + public static $verticalHeaderSeparator = '+'; |
|
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * The vertical separator sign. |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @access public |
| 113 | 113 | * @var string |
| 114 | 114 | */ |
| 115 | - public static $verticalInnerSeparator = '+'; |
|
| 115 | + public static $verticalInnerSeparator = '+'; |
|
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * Resets the default options |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | $columnsPads = !empty($args) ? $args[0] : []; |
| 149 | 149 | array_shift($args); |
| 150 | 150 | |
| 151 | - $str = self::$verticalSeparator ; |
|
| 152 | - $cellPaddingLenght = mb_strlen(self::$tableCellPadding) *2; |
|
| 153 | - foreach ($columnsPads as $key => $pad){ |
|
| 154 | - $str .= str_repeat(self::$horizontalSeparator , $pad + $cellPaddingLenght) .self::$verticalInnerSeparator; |
|
| 151 | + $str = self::$verticalSeparator; |
|
| 152 | + $cellPaddingLenght = mb_strlen(self::$tableCellPadding)*2; |
|
| 153 | + foreach ($columnsPads as $key => $pad) { |
|
| 154 | + $str .= str_repeat(self::$horizontalSeparator, $pad+$cellPaddingLenght).self::$verticalInnerSeparator; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - return self::getCliString(self::$verticalInnerSeparator === '' ? $str : substr($str, 0, mb_strlen($str) -1). self::$verticalSeparator, $args); |
|
| 157 | + return self::getCliString(self::$verticalInnerSeparator === '' ? $str : substr($str, 0, mb_strlen($str)-1).self::$verticalSeparator, $args); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | $columnsPads = !empty($args) ? $args[0] : []; |
| 175 | 175 | array_shift($args); |
| 176 | 176 | |
| 177 | - $str = self::$verticalHeaderSeparator ; |
|
| 178 | - $cellPaddingLenght = mb_strlen(self::$tableCellPadding) *2; |
|
| 179 | - foreach ($columnsPads as $key => $pad){ |
|
| 180 | - $str .= str_repeat(self::$horizontalSeparator , $pad + $cellPaddingLenght) .self::$verticalInnerSeparator ; |
|
| 177 | + $str = self::$verticalHeaderSeparator; |
|
| 178 | + $cellPaddingLenght = mb_strlen(self::$tableCellPadding)*2; |
|
| 179 | + foreach ($columnsPads as $key => $pad) { |
|
| 180 | + $str .= str_repeat(self::$horizontalSeparator, $pad+$cellPaddingLenght).self::$verticalInnerSeparator; |
|
| 181 | 181 | } |
| 182 | - return self::getCliString(self::$verticalInnerSeparator === '' ? $str : substr($str, 0, mb_strlen($str) -1). self::$verticalHeaderSeparator, $args); |
|
| 182 | + return self::getCliString(self::$verticalInnerSeparator === '' ? $str : substr($str, 0, mb_strlen($str)-1).self::$verticalHeaderSeparator, $args); |
|
| 183 | 183 | |
| 184 | 184 | } |
| 185 | 185 | |
@@ -203,12 +203,12 @@ discard block |
||
| 203 | 203 | $columnsPads = !empty($args) ? $args[0] : []; |
| 204 | 204 | array_shift($args); |
| 205 | 205 | |
| 206 | - $str = self::$verticalSeparator ; |
|
| 207 | - foreach ($columnsPads as $pad){ |
|
| 206 | + $str = self::$verticalSeparator; |
|
| 207 | + foreach ($columnsPads as $pad) { |
|
| 208 | 208 | $str .= self::$tableCellPadding. |
| 209 | 209 | str_pad(' ', $pad). |
| 210 | 210 | self::$tableCellPadding. |
| 211 | - self::$verticalSeparator ; |
|
| 211 | + self::$verticalSeparator; |
|
| 212 | 212 | } |
| 213 | 213 | return self::getCliString($str, $args); |
| 214 | 214 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | $str = self::$verticalSeparator; |
| 272 | 272 | |
| 273 | 273 | // add columns |
| 274 | - foreach ($columns as $column => $pad){ |
|
| 274 | + foreach ($columns as $column => $pad) { |
|
| 275 | 275 | $str .= self::$tableCellPadding. |
| 276 | 276 | self::pad($column, $pad). |
| 277 | 277 | self::$tableCellPadding. |
@@ -279,6 +279,6 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // format full row |
| 282 | - return self::getCliString($str, $args) ; |
|
| 282 | + return self::getCliString($str, $args); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | \ No newline at end of file |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public static function getColumns(): int |
| 52 | 52 | { |
| 53 | - if (!self::isWin() ){ |
|
| 53 | + if (!self::isWin()) { |
|
| 54 | 54 | return (int) shell_exec('tput cols'); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public static function getLines() |
| 69 | 69 | { |
| 70 | - if (!self::isWin() ){ |
|
| 70 | + if (!self::isWin()) { |
|
| 71 | 71 | return (int) shell_exec('tput lines'); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public static function newWindow() |
| 84 | 84 | { |
| 85 | - if (!self::isWin() ){ |
|
| 85 | + if (!self::isWin()) { |
|
| 86 | 86 | system('tput smcup'); |
| 87 | 87 | self::clear(); |
| 88 | 88 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public static function restoreWindow() |
| 100 | 100 | { |
| 101 | - if (!self::isWin() ){ |
|
| 101 | + if (!self::isWin()) { |
|
| 102 | 102 | system('tput rmcup'); |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public static function hideInput() |
| 115 | 115 | { |
| 116 | - if (!self::isWin() ){ |
|
| 116 | + if (!self::isWin()) { |
|
| 117 | 117 | system('stty -echo'); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public static function restoreInput() |
| 130 | 130 | { |
| 131 | - if (!self::isWin()){ |
|
| 131 | + if (!self::isWin()) { |
|
| 132 | 132 | system('stty echo'); |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | 'magenta' => '35', |
| 36 | 36 | 'cyan' => '36', |
| 37 | 37 | 'lightgray' => '37', |
| 38 | - 'default' => '39', // your default color |
|
| 38 | + 'default' => '39', // your default color |
|
| 39 | 39 | 'darkgray' => '90', |
| 40 | 40 | 'lightred' => '91', |
| 41 | 41 | 'lightgreen' => '92', |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | * @var array |
| 82 | 82 | */ |
| 83 | 83 | protected static $options = array( |
| 84 | - 'none' => '0', // reset all styles |
|
| 85 | - 'bold' => '1', // |
|
| 84 | + 'none' => '0', // reset all styles |
|
| 85 | + 'bold' => '1', // |
|
| 86 | 86 | 'dim' => '2', |
| 87 | 87 | 'underlined' => '4', |
| 88 | 88 | 'blink' => '5', |
| 89 | - 'reverse' => '7', // reverse foreground/background color |
|
| 89 | + 'reverse' => '7', // reverse foreground/background color |
|
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -125,39 +125,39 @@ discard block |
||
| 125 | 125 | array_shift($args); |
| 126 | 126 | |
| 127 | 127 | // |
| 128 | - switch($command){ |
|
| 128 | + switch ($command) { |
|
| 129 | 129 | |
| 130 | 130 | // **************************************** |
| 131 | 131 | // Get methods (return string) |
| 132 | 132 | // **************************************** |
| 133 | 133 | |
| 134 | 134 | case'text': |
| 135 | - return self::getCliString($str, $args); // get formatted text |
|
| 135 | + return self::getCliString($str, $args); // get formatted text |
|
| 136 | 136 | |
| 137 | 137 | // **************************************** |
| 138 | 138 | // Print methods (echo and return null) |
| 139 | 139 | // **************************************** |
| 140 | 140 | |
| 141 | 141 | case'print': |
| 142 | - echo (self::getCliString($str, $args)); // print text |
|
| 142 | + echo (self::getCliString($str, $args)); // print text |
|
| 143 | 143 | break; |
| 144 | 144 | |
| 145 | 145 | case'log': |
| 146 | - echo (self::getCliString($str, $args) . self::$EOF ); // print text + newline |
|
| 146 | + echo (self::getCliString($str, $args).self::$EOF); // print text + newline |
|
| 147 | 147 | break; |
| 148 | 148 | |
| 149 | 149 | case'relog': |
| 150 | 150 | // overwrite last line (cursor stays at the beginning) |
| 151 | - echo (self::getCliString($str ."\r", $args)); |
|
| 151 | + echo (self::getCliString($str."\r", $args)); |
|
| 152 | 152 | break; |
| 153 | 153 | |
| 154 | 154 | case'overwrite': |
| 155 | 155 | // Overwrite last x printed line (add trailing new lines) |
| 156 | 156 | // text could be one line string, or array of lines |
| 157 | 157 | $text = is_array($str) ? implode(PHP_EOL, $str) : $str; |
| 158 | - $overwriteIndex = is_array($str) ? count($str) : 1; |
|
| 158 | + $overwriteIndex = is_array($str) ? count($str) : 1; |
|
| 159 | 159 | // https://stackoverflow.com/questions/11283625/overwrite-last-line-on-terminal |
| 160 | - echo ("\033[". $overwriteIndex ."A\033[K".self::getCliString($text, $args).self::$EOF); |
|
| 160 | + echo ("\033[".$overwriteIndex."A\033[K".self::getCliString($text, $args).self::$EOF); |
|
| 161 | 161 | |
| 162 | 162 | break; |
| 163 | 163 | |
@@ -166,19 +166,19 @@ discard block |
||
| 166 | 166 | // ***************************************** |
| 167 | 167 | |
| 168 | 168 | case'ask': |
| 169 | - echo (self::getCliString($str, $args)); // print question |
|
| 170 | - return trim(fgets(STDIN)); // reads and return one line from STDIN |
|
| 169 | + echo (self::getCliString($str, $args)); // print question |
|
| 170 | + return trim(fgets(STDIN)); // reads and return one line from STDIN |
|
| 171 | 171 | |
| 172 | 172 | case'askPassword': |
| 173 | - self::hideInput(); // hide |
|
| 174 | - echo (self::getCliString($str, $args)); // print question |
|
| 175 | - $line= trim(fgets(STDIN)); // reads one line from STDIN |
|
| 176 | - self::restoreInput(); // restore |
|
| 177 | - return $line; // return line |
|
| 173 | + self::hideInput(); // hide |
|
| 174 | + echo (self::getCliString($str, $args)); // print question |
|
| 175 | + $line = trim(fgets(STDIN)); // reads one line from STDIN |
|
| 176 | + self::restoreInput(); // restore |
|
| 177 | + return $line; // return line |
|
| 178 | 178 | |
| 179 | 179 | case 'askInt': |
| 180 | - echo (self::getCliString($str, $args)); // print question |
|
| 181 | - fscanf(STDIN, "%d\n", $number); // reads number from STDIN |
|
| 180 | + echo (self::getCliString($str, $args)); // print question |
|
| 181 | + fscanf(STDIN, "%d\n", $number); // reads number from STDIN |
|
| 182 | 182 | return (is_int($number) ? $number : false); // return int value or false |
| 183 | 183 | } |
| 184 | 184 | |
@@ -196,16 +196,16 @@ discard block |
||
| 196 | 196 | $bgcolor, |
| 197 | 197 | $background = 'darkgray', |
| 198 | 198 | $progressLenght = 40, |
| 199 | - $pendingSign = ' ', |
|
| 200 | - $progressSign = ' ', |
|
| 199 | + $pendingSign = ' ', |
|
| 200 | + $progressSign = ' ', |
|
| 201 | 201 | $withPurcent = true |
| 202 | - ){ |
|
| 203 | - $perc = min(100,$percent); |
|
| 204 | - $start = round($progressLenght * $perc / 100); |
|
| 202 | + ) { |
|
| 203 | + $perc = min(100, $percent); |
|
| 204 | + $start = round($progressLenght*$perc/100); |
|
| 205 | 205 | |
| 206 | - return ($withPurcent ? Console::text(Console::pad($perc . '% ', 5, ' ', STR_PAD_LEFT), $color) : ''). |
|
| 207 | - Console::text(Console::pad('', $start, $progressSign), 'white', $bgcolor) . |
|
| 208 | - Console::text(Console::pad('', $progressLenght - $start, $pendingSign), 'black', $background) ; |
|
| 206 | + return ($withPurcent ? Console::text(Console::pad($perc.'% ', 5, ' ', STR_PAD_LEFT), $color) : ''). |
|
| 207 | + Console::text(Console::pad('', $start, $progressSign), 'white', $bgcolor). |
|
| 208 | + Console::text(Console::pad('', $progressLenght-$start, $pendingSign), 'black', $background); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | protected static function getCliString(string $str, array $arguments = []) |
| 222 | 222 | { |
| 223 | - if (empty($arguments)){ |
|
| 223 | + if (empty($arguments)) { |
|
| 224 | 224 | return $str; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -233,25 +233,25 @@ discard block |
||
| 233 | 233 | foreach ($arguments as $argument) { |
| 234 | 234 | |
| 235 | 235 | // it's a color? |
| 236 | - if(!$hasColor && isset(self::$foregroundColors[$argument])){ |
|
| 236 | + if (!$hasColor && isset(self::$foregroundColors[$argument])) { |
|
| 237 | 237 | $cliArgs[] = self::$foregroundColors[$argument]; |
| 238 | 238 | $hasColor = true; |
| 239 | 239 | |
| 240 | 240 | // it's a backcolor? |
| 241 | - } elseif ($hasColor && !$hasBackColor && isset(self::$backgroundColors[$argument])){ |
|
| 241 | + } elseif ($hasColor && !$hasBackColor && isset(self::$backgroundColors[$argument])) { |
|
| 242 | 242 | $cliArgs[] = self::$backgroundColors[$argument]; |
| 243 | 243 | $hasBackColor = true; |
| 244 | 244 | |
| 245 | 245 | // or it's an option? |
| 246 | - } elseif (isset(self::$options[$argument])){ |
|
| 246 | + } elseif (isset(self::$options[$argument])) { |
|
| 247 | 247 | $cliArgs[] = self::$options[$argument]; |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // Add string and end coloring |
| 252 | 252 | // todo \e[0m |
| 253 | - $coloredString .= "\033[" . implode(';',$cliArgs) .'m'; |
|
| 254 | - $coloredString .= $str . "\033[0m"; |
|
| 253 | + $coloredString .= "\033[".implode(';', $cliArgs).'m'; |
|
| 254 | + $coloredString .= $str."\033[0m"; |
|
| 255 | 255 | return $coloredString; |
| 256 | 256 | } |
| 257 | 257 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public static function askPassword() |
| 337 | 337 | { |
| 338 | - return self::cmd('askPassword',func_get_args()); |
|
| 338 | + return self::cmd('askPassword', func_get_args()); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | public static function log() |
| 354 | 354 | { |
| 355 | - self::cmd('log',func_get_args()); |
|
| 355 | + self::cmd('log', func_get_args()); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | */ |
| 370 | 370 | public static function relog() |
| 371 | 371 | { |
| 372 | - self::cmd('relog',func_get_args()); |
|
| 372 | + self::cmd('relog', func_get_args()); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | */ |
| 387 | 387 | public static function overwrite() |
| 388 | 388 | { |
| 389 | - self::cmd('overwrite',func_get_args()); |
|
| 389 | + self::cmd('overwrite', func_get_args()); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
@@ -403,20 +403,20 @@ discard block |
||
| 403 | 403 | */ |
| 404 | 404 | public static function pad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT) |
| 405 | 405 | { |
| 406 | - $diff = $padLength - mb_strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input)); |
|
| 406 | + $diff = $padLength-mb_strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input)); |
|
| 407 | 407 | |
| 408 | - if ($diff > 0){ |
|
| 409 | - switch ($padType){ |
|
| 408 | + if ($diff > 0) { |
|
| 409 | + switch ($padType) { |
|
| 410 | 410 | |
| 411 | 411 | case STR_PAD_RIGHT: |
| 412 | - return $input . str_repeat($padString, $diff); |
|
| 412 | + return $input.str_repeat($padString, $diff); |
|
| 413 | 413 | |
| 414 | 414 | case STR_PAD_LEFT: |
| 415 | - return str_repeat($padString, $diff ) . $input; |
|
| 415 | + return str_repeat($padString, $diff).$input; |
|
| 416 | 416 | |
| 417 | 417 | case STR_PAD_BOTH: |
| 418 | 418 | $padLeft = round(($diff)/2); |
| 419 | - return str_repeat($padString, $padLeft) . $input . str_repeat($padString, $diff - $padLeft); |
|
| 419 | + return str_repeat($padString, $padLeft).$input.str_repeat($padString, $diff-$padLeft); |
|
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | return $input; |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * @version 1.6.2 |
| 15 | 15 | * @copyright 2017-2024 Kr157uff |
| 16 | 16 | */ |
| 17 | -declare(ticks = 1); // Allow posix signal handling |
|
| 17 | +declare(ticks=1); // Allow posix signal handling |
|
| 18 | 18 | |
| 19 | 19 | namespace Kristuff\Mishell; |
| 20 | 20 | |
@@ -62,10 +62,9 @@ discard block |
||
| 62 | 62 | * @return string|null |
| 63 | 63 | * |
| 64 | 64 | */ |
| 65 | - public static function getArgumentValue(array $arguments, string $shortArg, string $longArg):? string |
|
| 65 | + public static function getArgumentValue(array $arguments, string $shortArg, string $longArg): ? string |
|
| 66 | 66 | { |
| 67 | - return array_key_exists($shortArg, $arguments) ? $arguments[$shortArg] : |
|
| 68 | - (array_key_exists($longArg, $arguments) ? $arguments[$longArg] : null); |
|
| 67 | + return array_key_exists($shortArg, $arguments) ? $arguments[$shortArg] : (array_key_exists($longArg, $arguments) ? $arguments[$longArg] : null); |
|
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | } |
| 72 | 71 | \ No newline at end of file |
@@ -1,24 +1,24 @@ 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(); |
| 6 | -Console::log(' '. Console::text('Overview:', 'underlined', 'bold')); |
|
| 7 | -Console::log(" - Use " . Console::text("Console::relog()", 'lightblue', 'underlined') . " to write temporary output to be overwritten later.", 'white'); |
|
| 6 | +Console::log(' '.Console::text('Overview:', 'underlined', 'bold')); |
|
| 7 | +Console::log(" - Use ".Console::text("Console::relog()", 'lightblue', 'underlined')." to write temporary output to be overwritten later.", 'white'); |
|
| 8 | 8 | Console::log(); |
| 9 | 9 | |
| 10 | -Console::log(' '. Console::text('Tips:', 'underlined', 'bold')); |
|
| 11 | -Console::log(" - you may need to use " . Console::text("php str_pad()", 'lightblue', 'underlined') . " method to be sure all previous text is overwritten."); |
|
| 10 | +Console::log(' '.Console::text('Tips:', 'underlined', 'bold')); |
|
| 11 | +Console::log(" - you may need to use ".Console::text("php str_pad()", 'lightblue', 'underlined')." method to be sure all previous text is overwritten."); |
|
| 12 | 12 | Console::log(" - You can customize colors (foreground and background) and some styles in same way than "); |
| 13 | -Console::log(' with ' . Console::text("Console::text()", 'lightblue', 'underlined') . |
|
| 14 | - ' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.'); |
|
| 13 | +Console::log(' with '.Console::text("Console::text()", 'lightblue', 'underlined'). |
|
| 14 | + ' and '.Console::text("Console::log()", 'lightblue', 'underlined').' methods.'); |
|
| 15 | 15 | Console::log(); |
| 16 | -Console::log(' '. Console::text('Sample code:', 'underlined', 'bold')); |
|
| 16 | +Console::log(' '.Console::text('Sample code:', 'underlined', 'bold')); |
|
| 17 | 17 | Console::log(); |
| 18 | -Console::log(' '.Console::text(str_pad('// fake progress loop ', 100),'green')); |
|
| 18 | +Console::log(' '.Console::text(str_pad('// fake progress loop ', 100), 'green')); |
|
| 19 | 19 | Console::log(' '.Console::text(str_pad('for ($i=0 ; $i<=10 ; $i++) {', 100), 'lightgray')); |
| 20 | -Console::log(' '.Console::text(str_pad(' // Overwrite progress message.', 100), 'green')); |
|
| 21 | -Console::log(' '.Console::text(str_pad(" Console::relog(' I am a progress text... ['.Console::text($\i, 'green') .']% completed');", 100),'lightgray')); |
|
| 20 | +Console::log(' '.Console::text(str_pad(' // Overwrite progress message.', 100), 'green')); |
|
| 21 | +Console::log(' '.Console::text(str_pad(" Console::relog(' I am a progress text... ['.Console::text($\i, 'green') .']% completed');", 100), 'lightgray')); |
|
| 22 | 22 | Console::log(' '.Console::text(str_pad(" // wait for a while, so we see the animation ", 100), 'green')); |
| 23 | 23 | Console::log(' '.Console::text(str_pad(' usleep(300000);', 100), 'lightgray')); |
| 24 | 24 | Console::log(' '.Console::text(str_pad('}', 100), 'lightgray')); |
@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | Console::log(' '.Console::text(str_pad("// note: you may need to use str_pad() method to be sure all previous text is overwritten", 100), 'green')); |
| 36 | 36 | Console::log(' '.Console::text(str_pad("Console::relog(Console::text('Done!', 'white', 'green', 'underlined'). str_pad(' ', 100);", 100), 'lightgray')); |
| 37 | 37 | Console::log(); |
| 38 | -Console::log(' ' .' '.Console::text('Sample result:', 'underlined', 'bold')); |
|
| 38 | +Console::log(' '.' '.Console::text('Sample result:', 'underlined', 'bold')); |
|
| 39 | 39 | // ----------------- |
| 40 | 40 | // sample start here |
| 41 | 41 | // ----------------- |
| 42 | 42 | |
| 43 | 43 | // fake progress message |
| 44 | -for ($i=0 ; $i<=100 ; $i++) { |
|
| 44 | +for ($i = 0; $i <= 100; $i++) { |
|
| 45 | 45 | |
| 46 | 46 | // Overwrite progress message. |
| 47 | - Console::relog(' I am a progress text... ['.Console::text($i, 'green') .']% completed'); |
|
| 47 | + Console::relog(' I am a progress text... ['.Console::text($i, 'green').']% completed'); |
|
| 48 | 48 | |
| 49 | 49 | // wait for a while, so we see the animation |
| 50 | 50 | usleep(100000); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // Overwrite progress message. |
| 62 | 62 | // note: you may need to use str_pad() method to be sure all previous text is overwritten. |
| 63 | -Console::relog(Console::text(' Done!', 'white', 'green', 'underlined'). str_pad(' ', 100)); |
|
| 63 | +Console::relog(Console::text(' Done!', 'white', 'green', 'underlined').str_pad(' ', 100)); |
|
| 64 | 64 | Console::log(''); |
| 65 | 65 | |
| 66 | 66 | ?> |
@@ -1,29 +1,29 @@ |
||
| 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 | -Console::log(' '. Console::text('Overview:', 'underlined', 'bold')); |
|
| 7 | -Console::log(' '. Console::text(" - Use ") . Console::text("string ", 'blue'). Console::text("Console::ask()", 'lightblue', 'underlined') . " to ask something to user in the console."); |
|
| 6 | +Console::log(' '.Console::text('Overview:', 'underlined', 'bold')); |
|
| 7 | +Console::log(' '.Console::text(" - Use ").Console::text("string ", 'blue').Console::text("Console::ask()", 'lightblue', 'underlined')." to ask something to user in the console."); |
|
| 8 | 8 | Console::log(); |
| 9 | -Console::log(' '. Console::text('Tips:', 'underlined', 'bold')); |
|
| 9 | +Console::log(' '.Console::text('Tips:', 'underlined', 'bold')); |
|
| 10 | 10 | Console::log(" - You can customize colors (foreground and background) and some styles in same way than "); |
| 11 | -Console::log(' with ' . Console::text("Console::text()", 'lightblue', 'underlined') . |
|
| 12 | - ' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.'); |
|
| 11 | +Console::log(' with '.Console::text("Console::text()", 'lightblue', 'underlined'). |
|
| 12 | + ' and '.Console::text("Console::log()", 'lightblue', 'underlined').' methods.'); |
|
| 13 | 13 | Console::log(); |
| 14 | -Console::log(' '. Console::text('Usage:', 'underlined', 'bold')); |
|
| 15 | -Console::log(' '. Console::text("\$value = Console::ask('Please enter something > ');", 'lightmagenta')); |
|
| 16 | -Console::log(' '. Console::text("// or", 'green')); |
|
| 17 | -Console::log(' '. Console::text("\$value = Console::ask('Please enter something > ', 'white', 'blue);", 'lightmagenta')); |
|
| 14 | +Console::log(' '.Console::text('Usage:', 'underlined', 'bold')); |
|
| 15 | +Console::log(' '.Console::text("\$value = Console::ask('Please enter something > ');", 'lightmagenta')); |
|
| 16 | +Console::log(' '.Console::text("// or", 'green')); |
|
| 17 | +Console::log(' '.Console::text("\$value = Console::ask('Please enter something > ', 'white', 'blue);", 'lightmagenta')); |
|
| 18 | 18 | Console::log(); |
| 19 | 19 | |
| 20 | 20 | // ----------------- |
| 21 | 21 | // sample start here |
| 22 | 22 | // ----------------- |
| 23 | 23 | $value = Console::ask('Please enter something > '); |
| 24 | -Console::log('=> the value you entered is [' . Console::text($value, 'lightyellow') . ']'); |
|
| 24 | +Console::log('=> the value you entered is ['.Console::text($value, 'lightyellow').']'); |
|
| 25 | 25 | |
| 26 | 26 | $value2 = Console::ask('Please enter something > ', 'magenta', 'underlined'); |
| 27 | -Console::log('=> the value you entered is [' . Console::text($value2, 'lightyellow') . ']'); |
|
| 27 | +Console::log('=> the value you entered is ['.Console::text($value2, 'lightyellow').']'); |
|
| 28 | 28 | |
| 29 | 29 | ?> |
@@ -1,5 +1,5 @@ |
||
| 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::restoreWindow(); |
@@ -1,32 +1,32 @@ |
||
| 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 | |
| 6 | -Console::log(' '. Console::text('Overview:', 'underlined', 'bold')); |
|
| 7 | -Console::log(' '. Console::text('- Using ','white').Console::text("Console::overwrite()", 'lightblue', 'underlined').Console::text('you can overwrite more than one row.', 'white')); |
|
| 8 | -Console::log(' '. Console::text('To overwrite the 2 last printed rows, you need to pass an array of 2 ','white').Console::text("string", 'lightblue', '').' '. Console::text('.', 'white')); |
|
| 6 | +Console::log(' '.Console::text('Overview:', 'underlined', 'bold')); |
|
| 7 | +Console::log(' '.Console::text('- Using ', 'white').Console::text("Console::overwrite()", 'lightblue', 'underlined').Console::text('you can overwrite more than one row.', 'white')); |
|
| 8 | +Console::log(' '.Console::text('To overwrite the 2 last printed rows, you need to pass an array of 2 ', 'white').Console::text("string", 'lightblue', '').' '.Console::text('.', 'white')); |
|
| 9 | 9 | Console::log(); |
| 10 | 10 | |
| 11 | -Console::log(' '. Console::text('Tips:', 'underlined', 'bold')); |
|
| 12 | -Console::log(" - " . Console::text('No need', 'underlined', 'bold') ." to use " . Console::text("php str_pad()", 'lightblue', 'underlined') . " method like with " .Console::text("Console::relog()", 'lightblue', 'underlined') ); |
|
| 11 | +Console::log(' '.Console::text('Tips:', 'underlined', 'bold')); |
|
| 12 | +Console::log(" - ".Console::text('No need', 'underlined', 'bold')." to use ".Console::text("php str_pad()", 'lightblue', 'underlined')." method like with ".Console::text("Console::relog()", 'lightblue', 'underlined')); |
|
| 13 | 13 | Console::log(" - You can customize colors (foreground and background) and some styles in same way than "); |
| 14 | -Console::log(' ' .Console::text("Console::text()", 'lightblue', 'underlined') . |
|
| 15 | - ' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.'); |
|
| 14 | +Console::log(' '.Console::text("Console::text()", 'lightblue', 'underlined'). |
|
| 15 | + ' and '.Console::text("Console::log()", 'lightblue', 'underlined').' methods.'); |
|
| 16 | 16 | Console::log(); |
| 17 | -Console::log(' '. Console::text('Basic usage:', 'underlined', 'bold')); |
|
| 17 | +Console::log(' '.Console::text('Basic usage:', 'underlined', 'bold')); |
|
| 18 | 18 | Console::log(); |
| 19 | 19 | Console::log(" Console::log('I am a real log line, with \\n, but I will be erased');"); |
| 20 | 20 | Console::log(" Console::log('I am another real log line, with \\n, but I will be erased');"); |
| 21 | 21 | Console::log(" Console::overwrite('I am new real line.');"); |
| 22 | 22 | Console::log(); |
| 23 | -Console::log(' ' .Console::text('Sample code:', 'underlined', 'bold')); |
|
| 23 | +Console::log(' '.Console::text('Sample code:', 'underlined', 'bold')); |
|
| 24 | 24 | Console::log(); |
| 25 | 25 | // ----------------- |
| 26 | 26 | // sample start here |
| 27 | 27 | // ----------------- |
| 28 | 28 | |
| 29 | -$msg1 = Console::text(' [*]', 'blue'). Console::text(' Tortoise vs Hare Race will starting. Place your bets! ...', 'white'); |
|
| 29 | +$msg1 = Console::text(' [*]', 'blue').Console::text(' Tortoise vs Hare Race will starting. Place your bets! ...', 'white'); |
|
| 30 | 30 | $msg2 = Console::text(' [*]', 'blue').Console::text(' |
@@ -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 | // headers |
@@ -10,12 +10,12 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | // loop into foregrounds |
| 12 | 12 | $i = 1; |
| 13 | -foreach (Console::getStyles()['foregrounds'] as $color => $colorValue ){ |
|
| 13 | +foreach (Console::getStyles()['foregrounds'] as $color => $colorValue) { |
|
| 14 | 14 | Console::log(' '.Console::tableRow([ |
| 15 | - ' ' . $i => 7, |
|
| 15 | + ' '.$i => 7, |
|
| 16 | 16 | $color => 15, |
| 17 | - "\\033[" . $colorValue .'m' => 15, |
|
| 18 | - Console::text(str_pad('I am a text color={' . $color .'}', 48), $color) => 50 |
|
| 17 | + "\\033[".$colorValue.'m' => 15, |
|
| 18 | + Console::text(str_pad('I am a text color={'.$color.'}', 48), $color) => 50 |
|
| 19 | 19 | ])); |
| 20 | 20 | $i++; |
| 21 | 21 | } |