https://github.com/cdoco/ansi-styles
ANSI escape codes for styling strings in the terminal
https://github.com/cdoco/ansi-styles
ansi-colors ansi-styles console-color
Last synced: about 2 months ago
JSON representation
ANSI escape codes for styling strings in the terminal
- Host: GitHub
- URL: https://github.com/cdoco/ansi-styles
- Owner: cdoco
- License: mit
- Created: 2017-11-15T02:55:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-15T03:54:27.000Z (over 7 years ago)
- Last Synced: 2025-03-02T05:41:37.261Z (3 months ago)
- Topics: ansi-colors, ansi-styles, console-color
- Language: PHP
- Size: 54.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ansi-styles
> [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal

## Install
```
$ composer require cdoco/ansi-styles
```## Usage
```php
require_once 'vendor/autoload.php';$style = new \Cdoco\AnsiStyles();
echo $style->blue->open . 'Hello Word!' . PHP_EOL . $style->blue->close;
echo $style->color->rgb(100, 200, 15) . "Hello Word!" . PHP_EOL . $style->color->close;
echo $style->color->hsl(120, 100, 60) . "Hello Word!" . PHP_EOL . $style->color->close;
echo $style->color->hex('#C0FFEE') . "Hello Word!" . PHP_EOL . $style->color->close;echo $style->bgColor->rgb(100, 200, 15) . "Hello Word!" . PHP_EOL . $style->bgColor->close;
```## API
Each style has an `open` and `close` property.
## Styles
### Modifiers
- `reset`
- `bold`
- `dim`
- `italic` *(Not widely supported)*
- `underline`
- `inverse`
- `hidden`
- `strikethrough` *(Not widely supported)*### Colors
- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `gray` ("bright black")
- `redBright`
- `greenBright`
- `yellowBright`
- `blueBright`
- `magentaBright`
- `cyanBright`
- `whiteBright`### Background colors
- `bgBlack`
- `bgRed`
- `bgGreen`
- `bgYellow`
- `bgBlue`
- `bgMagenta`
- `bgCyan`
- `bgWhite`
- `bgBlackBright`
- `bgRedBright`
- `bgGreenBright`
- `bgYellowBright`
- `bgBlueBright`
- `bgMagentaBright`
- `bgCyanBright`
- `bgWhiteBright`## Advanced usage
By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
- `$style->modifier`
- `$style->color`
- `$style->bgColor`###### Example
```php
echo $style->color->green->open;
```## [256 / 16 million (TrueColor) support](https://gist.github.com/XVilka/8346728)
To use these, call the associated conversion function with the intended output, for example:
```php
$style->color->rgb(100, 200, 15); // RGB to 16 color ansi foreground code
$style->bgColor->rgb(100, 200, 15); // RGB to 16 color ansi background code$style->color->hsl(120, 100, 60); // HSL to 256 color ansi foreground code
$style->bgColor->hsl(120, 100, 60); // HSL to 256 color ansi foreground code$style->color->hex('#C0FFEE'); // Hex (RGB) to 16 million color foreground code
$style->bgColor->hex('#C0FFEE'); // Hex (RGB) to 16 million color background code
```## License
MIT