Skip to content

Commit 45ae4cd

Browse files
committed
Add Color::bg256 and Color::fg256
1 parent 5fc43fb commit 45ae4cd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ echo $color->ok('This is ok msg');
465465
```php
466466
Ahc\Cli\Output\Color::style('mystyle', [
467467
'bg' => Ahc\Cli\Output\Color::CYAN,
468-
'fg' => '38;5;57', // 256 colors can be used as well
468+
'fg' => hc\Cli\Output\Color::fg256(57), // 256 colors can be used as well
469469
'bold' => 1, // You can experiment with 0, 1, 2, 3 ... as well
470470
]);
471471

src/Output/Color.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ public function info(string $text, array $style = []): string
117117
return $this->line($text, static::$styles['info'] + $style);
118118
}
119119

120+
/**
121+
* Returns the color code for a 256 background color
122+
*/
123+
public function bg256(int $code)
124+
{
125+
return "48;5;{$code}";
126+
}
127+
128+
/**
129+
* Returns the color code for a 256 foreground color
130+
*/
131+
public function fg256(int $code)
132+
{
133+
return "38;5;{$code}";
134+
}
135+
120136
/**
121137
* Returns a formatted/colored line.
122138
*/

0 commit comments

Comments
 (0)