nafisc / ansi-util
An ANSI library for PHP
Installs: 1 691
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 0
Open Issues: 0
This package is auto-updated.
Last update: 2024-10-19 10:49:25 UTC
README
Allows you to create ANSI strings with ease in PHP.
Java Version: See here
Usage
Note: It is not guaranteed that all of these ANSI codes will work on all terminals. See here for a list of compatible terminals.
$stringBuilder = new \Ansi\StringBuilder; echo $stringBuilder ->raw('Hello, ') ->underline('John Doe') ->resetUnderline() ->raw('. ') ->raw('This is ') ->color16(\Ansi\Color16::FG_RED, 'red') ->raw('.') .PHP_EOL;
\Ansi\StringBuilder
Note: Each of these functions takes an optional
string
parameter which will be added immediately after the ANSI code is applied. They also all follow the Fluent Design Pattern. The string builder itself implements the__toString
magic method, and as such can be treated as a string.
Utility Methods
\Ansi\Color16
The Color16
class is a utility class for 16-bit color codes.
Note: Each of these constants needs to be prefixed with either
FG_
when using it as a foreground color orBG_
when using it as a background color.
RESET
BLACK
RED
GREEN
YELLOW
BLUE
MAGENTA
CYAN
LIGHT_GRAY
DARK_GRAY
LIGHT_RED
LIGHT_GREEN
LIGHT_YELLOW
LIGHT_BLUE
LIGHT_MAGENTA
LIGHT_CYAN
WHITE