composer require sauvank/php-console-table
#### 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 |
+------+--------------------------------+------------+
// Return trow error if index row not exist
$pt->showRow(2);
Output in console :
+------+--------------------------------+------------+
| Row | title | release |
|------|--------------------------------|------------|
| 2 | The lion king | 2019-07-17 |
+------+--------------------------------+------------+
Just get the answer user :
use ConsoleTable\Readline;
$txtToShow = "line to show :";
$userAnswer = new Readline($txtToShow);
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);
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);
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";
}
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";
}
- Custom color for header / row.
- Multiple display type.
- Option for center/left/right text table.