Ansi
class Ansi
| internal |
ANSI escape sequences for terminal colors, cursor control, and text formatting.
Constants
| private Colors |
|
Methods
Returns ANSI escape sequence for given color.
Wraps text with ANSI color sequence and color reset.
Returns ANSI sequence to turn on bold text.
Returns ANSI sequence to turn off bold text.
Returns ANSI sequence to show the cursor.
Returns ANSI sequence to hide the cursor.
Returns ANSI sequence to move the cursor by the given number of columns (x) and rows (y).
Returns ANSI sequence to clear from cursor to end of line.
Removes all ANSI escape sequences from string (colors, cursor control, etc.).
Returns ANSI sequence to reset all attributes.
Returns display width of string (number of terminal columns).
Pads text to specified display width.
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').
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').
at line 52
static string
boldOn()
Returns ANSI sequence to turn on bold text.
at line 61
static string
boldOff()
Returns ANSI sequence to turn off bold text.
at line 70
static string
showCursor()
Returns ANSI sequence to show the cursor.
at line 79
static string
hideCursor()
Returns ANSI sequence to hide the cursor.
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).
at line 105
static string
clearLine()
Returns ANSI sequence to clear from cursor to end of line.
at line 114
static string
stripAnsi(string $text)
Removes all ANSI escape sequences from string (colors, cursor control, etc.).
at line 123
static string
reset()
Returns ANSI sequence to reset all attributes.
at line 132
static int
textWidth(string $text)
Returns display width of string (number of terminal columns).
at line 144
static string
pad(string $text, int $width, string $char = ' ', int $type = STR_PAD_RIGHT)
Pads text to specified display width.
at line 167
static string
truncate(string $text, int $maxWidth, string $ellipsis = '…')
Truncates text to max display width, adding ellipsis if needed.