Skip to content

Commit 3bd4243

Browse files
committed
Merge branch 'main' into translations
2 parents a0845f6 + cd0152f commit 3bd4243

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ Ahc\Cli\Output\Color::style('error', [
508508
]);
509509
```
510510

511+
#### Disable colors
512+
513+
```php
514+
Ahc\Cli\Output\Color::$enabled = false;
515+
```
516+
517+
Colors will be automatically disabled if the `NO_COLOR` environment variable is set to true.
518+
511519
### Cursor
512520

513521
Move cursor around, erase line up or down, clear screen.

src/Output/Color.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class Color
5252
const GRAY = 47;
5353
const DARKGRAY = 100;
5454

55+
public static bool $enabled = true;
56+
5557
protected string $format = "\033[:mod:;:fg:;:bg:m:txt:\033[0m";
5658

5759
/** @var array Custom styles */
@@ -140,6 +142,10 @@ public static function fg256(int $code): string
140142
*/
141143
public function line(string $text, array $style = []): string
142144
{
145+
if (!self::$enabled || getenv('NO_COLOR')) {
146+
return $text;
147+
}
148+
143149
$style += ['bg' => null, 'fg' => static::WHITE, 'bold' => 0, 'mod' => null];
144150

145151
$format = $style['bg'] === null

0 commit comments

Comments
 (0)