@@ -354,7 +354,7 @@ public static function helpPanel($usage, $commands = [], $options = [], $example
354
354
* @param string $title
355
355
* @return void
356
356
*/
357
- public static function panel ($ data , $ title ='Info panel ' , $ char = '* ' )
357
+ public static function panel ($ data , $ title ='Information Panel ' , $ char = '* ' )
358
358
{
359
359
$ data = is_array ($ data ) ? array_filter ($ data ) : [trim ($ data )];
360
360
$ title = trim ($ title );
@@ -363,8 +363,6 @@ public static function panel($data, $title='Info panel', $char = '*')
363
363
$ labelMaxWidth = 0 ; // if label exists, label max width
364
364
$ valueMaxWidth = 0 ; // value max width
365
365
366
- self ::write ("\n " . sprintf (self ::STAR_LINE ,"<bold> $ title</bold> " ), false );
367
-
368
366
foreach ($ data as $ label => $ value ) {
369
367
// label exists
370
368
if ( !is_numeric ($ label ) ) {
@@ -377,11 +375,18 @@ public static function panel($data, $title='Info panel', $char = '*')
377
375
$ temp = '' ;
378
376
379
377
foreach ($ value as $ key => $ val ) {
380
- $ val = (string )$ val ;
381
- $ temp .= (!is_numeric ($ key ) ? "$ key: " : '' ) . "<info> $ value</info>, " ;
378
+ if (is_bool ($ val )) {
379
+ $ val = $ val ? 'True ' : 'False ' ;
380
+ } else {
381
+ $ val = (string )$ val ;
382
+ }
383
+
384
+ $ temp .= (!is_numeric ($ key ) ? "$ key: " : '' ) . "<info> $ val</info>, " ;
382
385
}
383
386
384
387
$ value = rtrim ($ temp , ' , ' );
388
+ } else if (is_bool ($ value )) {
389
+ $ value = $ value ? 'True ' : 'False ' ;
385
390
}
386
391
387
392
// get value width
@@ -390,6 +395,7 @@ public static function panel($data, $title='Info panel', $char = '*')
390
395
$ width = mb_strlen (strip_tags ($ value ), 'UTF-8 ' ); // must clear style tag
391
396
$ valueMaxWidth = $ width > $ valueMaxWidth ? $ width : $ valueMaxWidth ;
392
397
} else {
398
+ de ((string )$ value );
393
399
throw new \Exception ('Panel data value only allow [array|string|number] ' );
394
400
}
395
401
@@ -402,12 +408,13 @@ public static function panel($data, $title='Info panel', $char = '*')
402
408
if ($ title ) {
403
409
$ title = ucwords ($ title );
404
410
$ titleLength = mb_strlen ($ title , 'UTF-8 ' );
411
+ $ panelWidth = $ panelWidth > $ titleLength ? $ panelWidth : $ titleLength ;
405
412
$ indentSpace = str_pad (' ' , ceil ($ panelWidth /2 ) - ceil ($ titleLength /2 ) + 2 *2 , ' ' );
406
413
self ::write (" {$ indentSpace }<bold> {$ title }</bold> " );
407
414
}
408
415
409
416
// output panel top border
410
- $ border = str_pad ($ char , $ panelWidth + (2 *3 ), $ char );
417
+ $ border = str_pad ($ char , $ panelWidth + (3 *3 ), $ char );
411
418
self ::write (' ' . $ border );
412
419
413
420
// output panel body
0 commit comments