Skip to content

Commit

Permalink
Merge branch 'main' into translations
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtrovich committed Dec 2, 2024
2 parents a0845f6 + cd0152f commit 3bd4243
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ Ahc\Cli\Output\Color::style('error', [
]);
```

#### Disable colors

```php
Ahc\Cli\Output\Color::$enabled = false;
```

Colors will be automatically disabled if the `NO_COLOR` environment variable is set to true.

### Cursor

Move cursor around, erase line up or down, clear screen.
Expand Down
6 changes: 6 additions & 0 deletions src/Output/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Color
const GRAY = 47;
const DARKGRAY = 100;

public static bool $enabled = true;

protected string $format = "\033[:mod:;:fg:;:bg:m:txt:\033[0m";

/** @var array Custom styles */
Expand Down Expand Up @@ -140,6 +142,10 @@ public static function fg256(int $code): string
*/
public function line(string $text, array $style = []): string
{
if (!self::$enabled || getenv('NO_COLOR')) {
return $text;
}

$style += ['bg' => null, 'fg' => static::WHITE, 'bold' => 0, 'mod' => null];

$format = $style['bg'] === null
Expand Down

0 comments on commit 3bd4243

Please sign in to comment.