data demonstration

Console Data Display - Provides an output display of formatting information.

The main functions are packaged under the namespace Swoft\Console\Advanced\Formatter , and the Swoft\Console\Helper\Show helper classes are provided to quickly use them.

Title text output

Use Show::title()/$output->title()

 public static function title(string $title, array $opts = []) 

Paragraph text output

Use Show::section()/$output->section()

 public static function section(string $title, string|array $body, array $opts = []) 

List data display output

 public static function aList(array $data, string $title, array $opts = []) 
  • $data array List data. It can be in the form of key-value, or it can be only value, or it can be mixed.
  • $title string The $title list. Optional
  • $opts array option setting ( same table, panel options )
    • leftChar border character on the left side. The default is two spaces, or other characters (eg: * . )
    • keyStyle Renders the color style of the key when it is in the form of key-value. Default info , set to empty is no color rendering
    • The color style of the titleStyle title. Default comment

The default option of aList can render help information for a command.

Use Show::aList()/$output->aList()

 $title = 'list title';
$data = [
     'name'  => 'value text', // key-value
     'name2' => 'value text 2',
     'more info please XXX', // only value
Show::aList($data, $title); 

Rendering effect:


Multi-list data display output

 public static function mList(array $data, array $opts = []) 

The default option of mList can render help information for a set of commands. The effect is the same as helpPanel() and is more customizable.

Use the Show::mList()/$output->mList() alias method Show::multiList()

 $data = [
  'list1 title' => [
     'name' => 'value text',
     'name2' => 'value text 2',
  'list2 title' => [
     'name' => 'value text',
     'name2' => 'value text 2',
  // ... ...


Rendering effect:


Panel display information output

 public static function panel(mixed $data, string $title = 'Information Panel', array $opts = []) 

Show information panel. For example, the command line application needs to display some version information, environment information, etc. when it starts running.

Use Show::panel()/$output->panel()

 $data = [
    'application version' => '1.2.0',
    'system version' => '5.2.3',
    'see help' => 'please use php bin/app -h',
    'a only value message',
Show::panel($data, 'panel show', ['borderChar' => '#']); 

Rendering effect:


Data table information output

 public static function table(array $data, $title = 'Data Table', array $opts = []) 

Use Show::table()/$output->table()

  • Directly render data pulled from the database (the field name is automatically extracted as the header)
 // like from database query's data.
$data = [
 [ col1 => value1, col2 => value2, col3 => value3, ... ], // first row
 [ col1 => value4, col2 => value5, col3 => value6, ... ], // second row
 ... ...

Show::table($data, 'a table'); 
  • When you construct your own data, it is a bit of a hassle to write the field name. You can manually configure the header field list by configuring $opts with options.
 // use custom head
$data = [
 [ value1, value2, value3, ... ], // first row
 [ value4, value5, value6, ... ], // second row
 // ... ...

$opts = [
  'showBorder' => true,
  'columns' => [col1, col2, col3, ...]
Show::table($data, 'a table', $opts); 

Preview rendering effect:


Rendering help information panel

 public static function helpPanel(array $config, $showAfterQuit = true) 

Use Show::helpPanel()/$output->helpPanel()

    "description" => 'a help panel description text. (help panel show)',
    "usage" => 'a usage text',
    "arguments" => [
        'arg1' => 'arg1 description',
        'arg2' => 'arg2 description',
    "options" => [
        '--opt1' => 'a long option',
        '-s' => 'a short option',
        '-d' => 'Run the server on daemon.(default: <comment>false</comment>)',
        '-h, --help' => 'Display this help message'
], false); 

Preview rendering effect:

alt text