Skip to content

Commit 05c2ab8

Browse files
committed
udpate some cli common methods
1 parent 88937a0 commit 05c2ab8

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Diff for: src/Cli.php

+17-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Toolkit\Cli\Color\Prompt;
1515
use Toolkit\Cli\Traits\ReadMessageTrait;
1616
use Toolkit\Cli\Traits\WriteMessageTrait;
17+
use function count;
1718
use function date;
1819
use function defined;
1920
use function function_exists;
@@ -39,6 +40,11 @@
3940
*
4041
* @method static alert(string|array|mixed $message, string $style = 'info')
4142
* @method static prompt(string|array|mixed $message, string $style = 'info')
43+
*
44+
* @method static error(string ...$message) Print error style message line.
45+
* @method static warn(string ...$message) Print warn style message line.
46+
* @method static info(string ...$message) Print info style message line.
47+
* @method static success(string ...$message) Print success style message line.
4248
*/
4349
class Cli
4450
{
@@ -54,13 +60,16 @@ public static function __callStatic(string $method, array $args)
5460
Alert::global()->withStyle($args[1] ?? '')->println($args[0]);
5561
return;
5662
}
63+
5764
if ($method === 'prompt') {
5865
Prompt::global()->withStyle($args[1] ?? '')->println($args[0]);
5966
return;
6067
}
6168

6269
if (isset(Color::STYLES[$method])) {
63-
echo Color::render($args[0], $method), "\n";
70+
$msg = count($args) > 1 ? implode(' ', $args) : (string)$args[0];
71+
echo Color::render($msg, $method), "\n";
72+
return;
6473
}
6574

6675
throw new RuntimeException('call unknown method: ' . $method);
@@ -179,7 +188,7 @@ public static function isSupportColor(): bool
179188
return true;
180189
}
181190

182-
// speical terminal
191+
// special terminal
183192
$termProgram = getenv('TERM_PROGRAM');
184193
if ('Hyper' === $termProgram || 'Terminus' === $termProgram) {
185194
return true;
@@ -199,11 +208,6 @@ public static function isSupportColor(): bool
199208
|| 'xterm' === getenv('TERM');
200209
}
201210

202-
// PHP 7 >= 7.2.0
203-
if (function_exists('stream_isatty')) {
204-
return \stream_isatty($stream);
205-
}
206-
207211
return self::isInteractive($stream);
208212
}
209213

@@ -230,12 +234,17 @@ public static function isAnsiSupport(): bool
230234
/**
231235
* Returns if the file descriptor is an interactive terminal or not.
232236
*
233-
* @param int|resource|mixed $fileDescriptor
237+
* @param resource|mixed $fileDescriptor
234238
*
235239
* @return boolean
236240
*/
237241
public static function isInteractive($fileDescriptor): bool
238242
{
243+
// PHP 7 >= 7.2.0
244+
if (function_exists('stream_isatty')) {
245+
return \stream_isatty($fileDescriptor);
246+
}
247+
239248
return function_exists('posix_isatty') && @posix_isatty($fileDescriptor);
240249
}
241250

0 commit comments

Comments
 (0)