2121use Toolkit \Cli \Cli ;
2222use Toolkit \Cli \ColorTag ;
2323use Toolkit \Cli \Style ;
24+ use Toolkit \Stdlib \Helper \JsonHelper ;
2425use Toolkit \Stdlib \Math ;
2526use Toolkit \Stdlib \Str ;
2627use Toolkit \Sys \Sys ;
3031use function implode ;
3132use function is_array ;
3233use function is_string ;
33- use function json_encode ;
3434use function microtime ;
3535use function sprintf ;
3636use function strlen ;
3737use function strpos ;
3838use function strtoupper ;
3939use function substr ;
4040use function ucwords ;
41- use const JSON_PRETTY_PRINT ;
42- use const JSON_UNESCAPED_SLASHES ;
43- use const JSON_UNESCAPED_UNICODE ;
4441use const PHP_EOL ;
4542
4643/**
@@ -208,17 +205,15 @@ public static function __callStatic(string $method, array $args = [])
208205 * Print JSON
209206 *
210207 * @param mixed $data
211- * @param int $flags
212- *
213- * @return int
208+ * @param string $title
214209 */
215- public static function prettyJSON (
216- $ data ,
217- int $ flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
218- ): int {
219- $ string = ( string ) json_encode ( $ data , $ flags );
210+ public static function prettyJSON ($ data , string $ title = ' JSON: ' ): void
211+ {
212+ if ( $ title ) {
213+ Console:: colored ( $ title , ' ylw0 ' );
214+ }
220215
221- return Console::write ($ string );
216+ Console::write (JsonHelper:: prettyJSON ( $ data ) );
222217 }
223218
224219 /**
@@ -424,7 +419,7 @@ public static function table(array $data, string $title = 'Data Table', array $o
424419 * @param string $msg
425420 * @param bool $ended
426421 */
427- public static function spinner (string $ msg = '' , $ ended = false ): void
422+ public static function spinner (string $ msg = '' , bool $ ended = false ): void
428423 {
429424 static $ chars = '-\|/ ' ;
430425 static $ counter = 0 ;
@@ -457,7 +452,7 @@ public static function spinner(string $msg = '', $ended = false): void
457452 * @param string $msg
458453 * @param bool $ended
459454 */
460- public static function loading (string $ msg = 'Loading ' , $ ended = false ): void
455+ public static function loading (string $ msg = 'Loading ' , bool $ ended = false ): void
461456 {
462457 self ::pending ($ msg , $ ended );
463458 }
@@ -476,7 +471,7 @@ public static function loading(string $msg = 'Loading ', $ended = false): void
476471 * @param string $msg
477472 * @param bool $ended
478473 */
479- public static function pending (string $ msg = 'Pending ' , $ ended = false ): void
474+ public static function pending (string $ msg = 'Pending ' , bool $ ended = false ): void
480475 {
481476 static $ counter = 0 ;
482477 static $ lastTime = null ;
@@ -516,9 +511,9 @@ public static function pending(string $msg = 'Pending ', $ended = false): void
516511 * @param string $msg
517512 * @param bool $ended
518513 *
519- * @return int|mixed
514+ * @return int
520515 */
521- public static function pointing (string $ msg = 'handling ' , $ ended = false )
516+ public static function pointing (string $ msg = 'handling ' , bool $ ended = false ): int
522517 {
523518 static $ counter = 0 ;
524519
@@ -532,40 +527,41 @@ public static function pointing(string $msg = 'handling ', $ended = false)
532527
533528 $ counter ++;
534529
535- return print '. ' ;
530+ print '. ' ;
531+ return 0 ;
536532 }
537533
538534 /**
539535 * 与文本进度条相比,没有 total
540536 *
541537 * @param string $msg
542- * @param string|null $doneMsg
538+ * @param string $doneMsg
543539 *
544540 * @return Generator
545541 */
546- public static function counterTxt (string $ msg , $ doneMsg = '' ): Generator
542+ public static function counterTxt (string $ msg , string $ doneMsg = '' ): Generator
547543 {
548544 return CounterText::gen ($ msg , $ doneMsg );
549545 }
550546
551547 /**
552548 * @param string $doneMsg
553- * @param string|null $fixMsg
549+ * @param string $fixMsg
554550 *
555551 * @return Generator
556552 */
557- public static function dynamicTxt (string $ doneMsg , string $ fixMsg = null ): Generator
553+ public static function dynamicTxt (string $ doneMsg , string $ fixMsg = '' ): Generator
558554 {
559555 return self ::dynamicText ($ doneMsg , $ fixMsg );
560556 }
561557
562558 /**
563559 * @param string $doneMsg
564- * @param string|null $fixedMsg
560+ * @param string $fixedMsg
565561 *
566562 * @return Generator
567563 */
568- public static function dynamicText (string $ doneMsg , string $ fixedMsg = null ): Generator
564+ public static function dynamicText (string $ doneMsg , string $ fixedMsg = '' ): Generator
569565 {
570566 return DynamicText::gen ($ doneMsg , $ fixedMsg );
571567 }
@@ -685,14 +681,14 @@ public static function clearBuffer(): void
685681 *
686682 * @param bool $flush Whether flush buffer to output stream
687683 * @param bool $nl Default is False, because the last write() have been added "\n"
688- * @param bool $quit
684+ * @param bool|int $quit
689685 * @param array $opts
690686 *
691687 * @return null|string If flush = False, will return all buffer text.
692688 * @see Show::write()
693689 * @deprecated Please use \Inhere\Console\Console method instead it.
694690 */
695- public static function stopBuffer ($ flush = true , $ nl = false , $ quit = false , array $ opts = []): ?string
691+ public static function stopBuffer (bool $ flush = true , bool $ nl = false , $ quit = false , array $ opts = []): ?string
696692 {
697693 self ::$ buffering = false ;
698694
@@ -720,7 +716,7 @@ public static function stopBuffer($flush = true, $nl = false, $quit = false, arr
720716 * @see Show::write()
721717 * @deprecated Please use \Inhere\Console\Console method instead it.
722718 */
723- public static function flushBuffer ($ nl = false , $ quit = false , array $ opts = []): void
719+ public static function flushBuffer (bool $ nl = false , $ quit = false , array $ opts = []): void
724720 {
725721 self ::stopBuffer (true , $ nl , $ quit , $ opts );
726722 }
@@ -747,7 +743,7 @@ public static function writef(string $format, ...$args): int
747743 *
748744 * @param string|array $messages Output message
749745 * @param boolean $nl True 会添加换行符, False 原样输出,不添加换行符
750- * @param int|boolean $quit If is int, setting it is exit code. 'True' translate as code 0 and exit, 'False' will not exit.
746+ * @param int|bool $quit If is int, setting it is exit code. 'True' translate as code 0 and exit, 'False' will not exit.
751747 * @param array $opts Some options for write
752748 * refer:
753749 * [
@@ -758,7 +754,7 @@ public static function writef(string $format, ...$args): int
758754 *
759755 * @return int
760756 */
761- public static function write ($ messages , $ nl = true , $ quit = false , array $ opts = []): int
757+ public static function write ($ messages , bool $ nl = true , $ quit = false , array $ opts = []): int
762758 {
763759 return Console::write ($ messages , $ nl , $ quit , $ opts );
764760 }
@@ -801,7 +797,7 @@ public static function writeln($message, $quit = false, array $opts = []): int
801797 *
802798 * @return int
803799 */
804- public static function colored ($ message , string $ style = 'info ' , $ nl = true , array $ opts = []): int
800+ public static function colored ($ message , string $ style = 'info ' , bool $ nl = true , array $ opts = []): int
805801 {
806802 $ quit = isset ($ opts ['quit ' ]) ? (bool )$ opts ['quit ' ] : false ;
807803
@@ -817,7 +813,7 @@ public static function colored($message, string $style = 'info', $nl = true, arr
817813 *
818814 * @return array
819815 */
820- public static function getBlockMethods ($ onlyKey = true ): array
816+ public static function getBlockMethods (bool $ onlyKey = true ): array
821817 {
822818 return $ onlyKey ? array_keys (self ::$ blockMethods ) : self ::$ blockMethods ;
823819 }
0 commit comments