2017 © Pedro Peláez
 

library ansi-styles

ANSI escape codes for styling strings in the terminal

image

cdoco/ansi-styles

ANSI escape codes for styling strings in the terminal

  • Wednesday, November 15, 2017
  • by cdoco
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ansi-styles

ANSI escape codes for styling strings in the terminal, (*1)

, (*2)

Install

$ composer require cdoco/ansi-styles

Usage

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., (*3)

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., (*4)

  • $style->modifier
  • $style->color
  • $style->bgColor
Example
echo $style->color->green->open;

256 / 16 million (TrueColor) support

To use these, call the associated conversion function with the intended output, for example:, (*5)

$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, (*6)

The Versions

15/11 2017

dev-master

9999999-dev

ANSI escape codes for styling strings in the terminal

  Sources   Download

The Development Requires

by ZiHang Gao

log logging console command-line terminal ansi cli colors text shell string formatting escape color rgb colour styles xterm tty 256

15/11 2017

1.0.0

1.0.0.0

ANSI escape codes for styling strings in the terminal

  Sources   Download

The Development Requires

by ZiHang Gao

log logging console command-line terminal ansi cli colors text shell string formatting escape color rgb colour styles xterm tty 256