|
|
@@ -73,7 +73,7 @@ class DedeCli |
|
|
|
$optionsFound = false; |
|
|
|
} |
|
|
|
} |
|
|
|
public static function getOption(string $name) |
|
|
|
public static function getOption($name) |
|
|
|
{ |
|
|
|
if (! array_key_exists($name, static::$options)) { |
|
|
|
return null; |
|
|
@@ -87,7 +87,7 @@ class DedeCli |
|
|
|
{ |
|
|
|
return static::$options; |
|
|
|
} |
|
|
|
public static function getOptionString(): string |
|
|
|
public static function getOptionString() |
|
|
|
{ |
|
|
|
if (! count(static::$options)) { |
|
|
|
return ''; |
|
|
@@ -102,7 +102,7 @@ class DedeCli |
|
|
|
} |
|
|
|
return $out; |
|
|
|
} |
|
|
|
public static function newLine(int $num = 1) |
|
|
|
public static function newLine($num = 1) |
|
|
|
{ |
|
|
|
for ($i = 0; $i < $num; $i++) { |
|
|
|
static::write(''); |
|
|
@@ -112,7 +112,7 @@ class DedeCli |
|
|
|
{ |
|
|
|
return 'win' === strtolower(substr(php_uname("s"), 0, 3)); |
|
|
|
} |
|
|
|
public static function color(string $text, string $foreground, string $background = null, string $format = null) |
|
|
|
public static function color($text, $foreground, $background = null, $format = null) |
|
|
|
{ |
|
|
|
if (static::isWindows() && ! isset($_SERVER['ANSICON'])) { |
|
|
|
return $text; |
|
|
@@ -133,21 +133,21 @@ class DedeCli |
|
|
|
$string .= $text."\033[0m"; |
|
|
|
return $string; |
|
|
|
} |
|
|
|
public static function getWidth(int $default = 80): int |
|
|
|
public static function getWidth($default = 80) |
|
|
|
{ |
|
|
|
if (static::isWindows()) { |
|
|
|
return $default; |
|
|
|
} |
|
|
|
return (int)shell_exec('tput cols'); |
|
|
|
} |
|
|
|
public static function getHeight(int $default = 32): int |
|
|
|
public static function getHeight($default = 32) |
|
|
|
{ |
|
|
|
if (static::isWindows()) { |
|
|
|
return $default; |
|
|
|
} |
|
|
|
return (int)shell_exec('tput lines'); |
|
|
|
} |
|
|
|
public static function showProgress($thisStep = 1, int $totalSteps = 10, int $pos = 0,int $total = 0) |
|
|
|
public static function showProgress($thisStep = 1, $totalSteps = 10, $pos = 0, $total = 0) |
|
|
|
{ |
|
|
|
static $inProgress = false; |
|
|
|
if ($inProgress !== false && $inProgress <= $thisStep) { |
|
|
@@ -169,7 +169,7 @@ class DedeCli |
|
|
|
fwrite(STDOUT, "\007"); |
|
|
|
} |
|
|
|
} |
|
|
|
public static function wrap(string $string = null, int $max = 0, int $pad_left = 0): string |
|
|
|
public static function wrap($string = null, $max = 0, $pad_left = 0) |
|
|
|
{ |
|
|
|
if (empty($string)) { |
|
|
|
return ''; |
|
|
@@ -203,7 +203,7 @@ class DedeCli |
|
|
|
? static::newLine(40) |
|
|
|
: fwrite(STDOUT, chr(27)."[H".chr(27)."[2J"); |
|
|
|
} |
|
|
|
public static function input(string $prefix = null): string |
|
|
|
public static function input($prefix = null) |
|
|
|
{ |
|
|
|
if (static::$readline_support) { |
|
|
|
return readline($prefix); |
|
|
@@ -222,7 +222,7 @@ class DedeCli |
|
|
|
* |
|
|
|
* @return string the user input |
|
|
|
*/ |
|
|
|
public static function prompt(): string |
|
|
|
public static function prompt() |
|
|
|
{ |
|
|
|
$args = func_get_args(); |
|
|
|
$options = []; |
|
|
@@ -278,7 +278,7 @@ class DedeCli |
|
|
|
} |
|
|
|
return empty($input) ? '' : $input; |
|
|
|
} |
|
|
|
public static function wait(int $seconds, bool $countdown = false) |
|
|
|
public static function wait($seconds, $countdown = false) |
|
|
|
{ |
|
|
|
if ($countdown === true) { |
|
|
|
$time = $seconds; |
|
|
@@ -298,14 +298,14 @@ class DedeCli |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public static function error(string $text, string $foreground = 'light_red', string $background = null) |
|
|
|
public static function error($text, $foreground = 'light_red', $background = null) |
|
|
|
{ |
|
|
|
if ($foreground || $background) { |
|
|
|
$text = static::color($text, $foreground, $background); |
|
|
|
} |
|
|
|
fwrite(STDERR, $text.PHP_EOL); |
|
|
|
} |
|
|
|
public static function write(string $text = '', string $foreground = null, string $background = null) |
|
|
|
public static function write($text = '', $foreground = null, $background = null) |
|
|
|
{ |
|
|
|
if ($foreground || $background) { |
|
|
|
$text = static::color($text, $foreground, $background); |
|
|
|