定制 sauvank/php-console-table 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sauvank/php-console-table

Composer 安装命令:

composer require sauvank/php-console-table

包简介

Display a table in the console from parameters.

README 文档

README

Display a table in the console from parameters.

Install :

composer require sauvank/php-console-table

Doc :

#### Show Table from parameters :

<?php

use ConsoleTable\Table;

$columns = [
    'column title', // By default, the size of the column is equal to the big string in title column or row.

     [ // If you want define custom size for this column 
         'name' => 'release',
         'size' => 10
     ]
 ];
 
 $lines = [
    [
        "Fight club",
        "1999-11-10"
    ],  
    [
        "The lion king",
        "2019-07-17"
    ],
];

 // Optional
 $conf = [
     'margin' => 1, // int , Default : 1, set space character beetween limit column. 
     'showNumberRow' => true, // Bool, default : true,  show the row number in table.
     'defaultSizeCol' => 30, // int, default : 30, for size column if key size not set in $column array key.
 ];

 $pt = new Table($columns, $lines, $conf);
 $pt->show(); // Show all row of table

Output in console :


+------+--------------------------------+------------+
| Row  | column title                   | release    |
-------|--------------------------------|------------|
| 1    | Fight club                     | 1999-11-10 |
-------|--------------------------------|------------|
| 2    | The lion king                  | 2019-07-17 |
+------+--------------------------------+------------+

Show specific row ;

  // Return trow error if index row not exist
  $pt->showRow(2);

Output in console :


+------+--------------------------------+------------+
| Row  | title                          | release    |
|------|--------------------------------|------------|
| 2    | The lion king                  | 2019-07-17 |
+------+--------------------------------+------------+

Use readline

Basic usage :

Just get the answer user :

use ConsoleTable\Readline;

$txtToShow = "line to show :";

$userAnswer = new Readline($txtToShow);

readline with option :

If the user enters a value other than that included in the "option" array, the question is asked again

use ConsoleTable\Readline;

$txtToShow = "line to show :";
$option = ["y", "n"];

$userAnswer = new Readline($txtToShow, $option);

Option by default :

If the user enters an empty value, the option by default is taken

use ConsoleTable\Readline;

$txtToShow = "line to show :";
$option = ["y", "n"]; // list of optino valid
$defaultValue = 0; // key index of the $option array.

$userAnswer = new Readline($txtToShow, $option, $defaultValue);

Confirm the last choice :

Add a prompt for confim choice.

use ConsoleTable\Readline;

$readline= new Readline("line to show", ['1', '2']);
$confirm = $readline->confirm(); // return true or false

if($confirm){
    echo "You have confirmed your choice " . $readline->getAnswer();
}else{
    echo "You have not confirm your choice.\n";
}

Only get confirm option without readline txt :

use ConsoleTable\Readline;

$readline= new Readline(null);
$confirm = $readline->confirm(); // return true or false

if($confirm){
    echo "You have confirmed your choice " . $readline->getAnswer();
}else{
    echo "You have not confirm your choice.\n";
}

Todo

  • Custom color for header / row.
  • Multiple display type.
  • Option for center/left/right text table.

统计信息

  • 总下载量: 49
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2020-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固