class Ansi

internal  
 

ANSI escape sequences for terminal colors, cursor control, and text formatting.

Constants

private Colors

Methods

static string
color(string $color)

Returns ANSI escape sequence for given color.

static string
colorize(string $text, string $color)

Wraps text with ANSI color sequence and color reset.

static string
boldOn()

Returns ANSI sequence to turn on bold text.

static string
boldOff()

Returns ANSI sequence to turn off bold text.

static string
showCursor()

Returns ANSI sequence to show the cursor.

static string
hideCursor()

Returns ANSI sequence to hide the cursor.

static string
cursorMove(int $x = 0, int $y = 0)

Returns ANSI sequence to move the cursor by the given number of columns (x) and rows (y).

static string
clearLine()

Returns ANSI sequence to clear from cursor to end of line.

static string
stripAnsi(string $text)

Removes all ANSI escape sequences from string (colors, cursor control, etc.).

static string
reset()

Returns ANSI sequence to reset all attributes.

static int
textWidth(string $text)

Returns display width of string (number of terminal columns).

static string
pad(string $text, int $width, string $char = ' ', int $type = STR_PAD_RIGHT)

Pads text to specified display width.

static string
truncate(string $text, int $maxWidth, string $ellipsis = '…')

Truncates text to max display width, adding ellipsis if needed.

Details

at line 30
static string color(string $color)

Returns ANSI escape sequence for given color.

Color format: 'foreground' or 'foreground/background' (e.g. 'red', 'white/blue').

Parameters

string $color

Return Value

string

at line 43
static string colorize(string $text, string $color)

Wraps text with ANSI color sequence and color reset.

Color format: 'foreground' or 'foreground/background' (e.g. 'red', 'white/blue').

Parameters

string $text
string $color

Return Value

string

at line 52
static string boldOn()

Returns ANSI sequence to turn on bold text.

Return Value

string

at line 61
static string boldOff()

Returns ANSI sequence to turn off bold text.

Return Value

string

at line 70
static string showCursor()

Returns ANSI sequence to show the cursor.

Return Value

string

at line 79
static string hideCursor()

Returns ANSI sequence to hide the cursor.

Return Value

string

at line 88
static string cursorMove(int $x = 0, int $y = 0)

Returns ANSI sequence to move the cursor by the given number of columns (x) and rows (y).

Parameters

int $x
int $y

Return Value

string

at line 105
static string clearLine()

Returns ANSI sequence to clear from cursor to end of line.

Return Value

string

at line 114
static string stripAnsi(string $text)

Removes all ANSI escape sequences from string (colors, cursor control, etc.).

Parameters

string $text

Return Value

string

at line 123
static string reset()

Returns ANSI sequence to reset all attributes.

Return Value

string

at line 132
static int textWidth(string $text)

Returns display width of string (number of terminal columns).

Parameters

string $text

Return Value

int

at line 144
static string pad(string $text, int $width, string $char = ' ', int $type = STR_PAD_RIGHT)

Pads text to specified display width.

Parameters

string $text
int $width
string $char
int $type

Return Value

string

at line 167
static string truncate(string $text, int $maxWidth, string $ellipsis = '…')

Truncates text to max display width, adding ellipsis if needed.

Parameters

string $text
int $maxWidth
string $ellipsis

Return Value

string