Skip to content

Commit

Permalink
update readme to add docs of twoColumnDetail method
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtrovich committed Mar 26, 2024
1 parent 22cd2c4 commit 2fdabc1
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,36 +583,55 @@ $writer->table([
]);
```

#### Two columns detail (Display setting)

If you want to display certain configurations (from your .env file for example) a bit like Laravel does (via the php artisan `about` command) you can use the `twoColumnDetail` method.

```php
$writer->twoColumnDetail('Environment');
$writer->twoColumnDetail('PHP Version', PHP_VERSION);
$writer->twoColumnDetail('App Version', '1.0.0');
$writer->twoColumnDetail('Locale', 'en');
```

Gives something like:

```
+--------+------+------+
| A | B C | C D |
+--------+------+------+
| apple | ball | cat |
| applet | bee | cute |
+--------+------+------+
Environment ........................................
PHP Version .................................. 8.1.4
App Version .................................. 1.0.0
Locale .......................................... en
```

> Designing table look and feel
You can use the `sep` parameter to define the separator to use.

Just pass 2nd param `$styles`:
```php
$writer->twoColumnDetail('Environment', '', ['sep' => '-']);
$writer->twoColumnDetail('PHP Version', PHP_VERSION);
```

Gives something like:

```
Environment ----------------------------------------
PHP Version .................................. 8.1.4
```

In addition, the text color, the background color and the thickness of the two texts can be defined via the 3rd argument of this method.

```php
$writer->table([
['a' => 'apple', 'b-c' => 'ball', 'c_d' => 'cat'],
['a' => 'applet', 'b-c' => 'bee', 'c_d' => 'cute'],
], [
// for => styleName (anything that you would call in $writer instance)
'head' => 'boldGreen', // For the table heading
'odd' => 'bold', // For the odd rows (1st row is odd, then 3, 5 etc)
'even' => 'comment', // For the even rows (2nd row is even, then 4, 6 etc)
$writer->twoColumnDetail('Cache Enable', 'true', [
'first' => ['fg' => Ahc\Cli\Output\Color::CYAN], // style of the key
'second' => ['fg' => Ahc\Cli\Output\Color::GREEN], // style of the value
]);
$writer->twoColumnDetail('Debug Mode', 'false', [
'first' => ['fg' => Ahc\Cli\Output\Color::CYAN], // style of the key
'second' => ['fg' => Ahc\Cli\Output\Color::RED], // style of the value
]);

// 'head', 'odd', 'even' are all the styles for now
// In future we may support styling a column by its name!
```

For more details regarding the different color options, see [Custom style](#custom-style)

#### Reader

Read and pre process user input.
Expand Down

0 comments on commit 2fdabc1

Please sign in to comment.