Skip to content

Commit

Permalink
refactor: change twoColumnsDetail to justify
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtrovich authored and adhocore committed Mar 28, 2024
1 parent eed7622 commit 595a5b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,15 +613,15 @@ $writer->table([
// In future we may support styling a column by its name!
```

#### Two columns detail (Display setting)
#### Justify content (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.
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 `justify` method.

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

Gives something like:
Expand All @@ -636,8 +636,8 @@ Locale .......................................... en
You can use the `sep` parameter to define the separator to use.

```php
$writer->twoColumnDetail('Environment', '', ['sep' => '-']);
$writer->twoColumnDetail('PHP Version', PHP_VERSION);
$writer->justify('Environment', '', ['sep' => '-']);
$writer->justify('PHP Version', PHP_VERSION);
```

Gives something like:
Expand All @@ -650,11 +650,11 @@ 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->twoColumnDetail('Cache Enable', 'true', [
$writer->justify('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', [
$writer->justify('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
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Output/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function table(array $rows, array $styles = []): self
*
* @return self
*/
public function twoColumnDetail(string $first, ?string $second = null, array $options = []): self
public function justify(string $first, ?string $second = null, array $options = []): self
{
$options = [
'first' => ($options['first'] ?? []) + ['bg' => null, 'fg' => Color::WHITE, 'bold' => 0],
Expand Down
4 changes: 2 additions & 2 deletions tests/Output/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ public function test_terminal()
$this->assertInstanceOf(Terminal::class, (new Writer)->terminal());
}

public function test_two_column_detail()
public function test_justify()
{
$w = new Writer(static::$ou);

$w->twoColumnDetail('PHP Version', PHP_VERSION, [
$w->justify('PHP Version', PHP_VERSION, [
'sep' => '-'
]);

Expand Down

0 comments on commit 595a5b7

Please sign in to comment.