14
14
use Toolkit \Cli \Color \Prompt ;
15
15
use Toolkit \Cli \Traits \ReadMessageTrait ;
16
16
use Toolkit \Cli \Traits \WriteMessageTrait ;
17
+ use function count ;
17
18
use function date ;
18
19
use function defined ;
19
20
use function function_exists ;
39
40
*
40
41
* @method static alert(string|array|mixed $message, string $style = 'info')
41
42
* @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.
42
48
*/
43
49
class Cli
44
50
{
@@ -54,13 +60,16 @@ public static function __callStatic(string $method, array $args)
54
60
Alert::global ()->withStyle ($ args [1 ] ?? '' )->println ($ args [0 ]);
55
61
return ;
56
62
}
63
+
57
64
if ($ method === 'prompt ' ) {
58
65
Prompt::global ()->withStyle ($ args [1 ] ?? '' )->println ($ args [0 ]);
59
66
return ;
60
67
}
61
68
62
69
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 ;
64
73
}
65
74
66
75
throw new RuntimeException ('call unknown method: ' . $ method );
@@ -179,7 +188,7 @@ public static function isSupportColor(): bool
179
188
return true ;
180
189
}
181
190
182
- // speical terminal
191
+ // special terminal
183
192
$ termProgram = getenv ('TERM_PROGRAM ' );
184
193
if ('Hyper ' === $ termProgram || 'Terminus ' === $ termProgram ) {
185
194
return true ;
@@ -199,11 +208,6 @@ public static function isSupportColor(): bool
199
208
|| 'xterm ' === getenv ('TERM ' );
200
209
}
201
210
202
- // PHP 7 >= 7.2.0
203
- if (function_exists ('stream_isatty ' )) {
204
- return \stream_isatty ($ stream );
205
- }
206
-
207
211
return self ::isInteractive ($ stream );
208
212
}
209
213
@@ -230,12 +234,17 @@ public static function isAnsiSupport(): bool
230
234
/**
231
235
* Returns if the file descriptor is an interactive terminal or not.
232
236
*
233
- * @param int| resource|mixed $fileDescriptor
237
+ * @param resource|mixed $fileDescriptor
234
238
*
235
239
* @return boolean
236
240
*/
237
241
public static function isInteractive ($ fileDescriptor ): bool
238
242
{
243
+ // PHP 7 >= 7.2.0
244
+ if (function_exists ('stream_isatty ' )) {
245
+ return \stream_isatty ($ fileDescriptor );
246
+ }
247
+
239
248
return function_exists ('posix_isatty ' ) && @posix_isatty ($ fileDescriptor );
240
249
}
241
250
0 commit comments