Cli
in package
CLI prompt helpers.
This relies heavily on VT100 escapes.
Uses the 'readline' extension when available.
http://www.climagic.org/mirrors/VT100_Escape_Codes.html
Table of Contents
Constants
- BG_BLACK : mixed = "\x1b[40m"
- BG_BLUE : mixed = "\x1b[44m"
- BG_CYAN : mixed = "\x1b[46m"
- BG_GREEN : mixed = "\x1b[42m"
- BG_GREY : mixed = "\x1b[48;5;248m"
- BG_PURPLE : mixed = "\x1b[45m"
- BG_RED : mixed = "\x1b[41m"
- BG_WHITE : mixed = "\x1b[47m"
- BG_YELLOW : mixed = "\x1b[43m"
- BOLD : mixed = "\x1b[1m"
- FG_BLACK : mixed = "\x1b[30m"
- FG_BLUE : mixed = "\x1b[34m"
- FG_CYAN : mixed = "\x1b[36m"
- FG_GREEN : mixed = "\x1b[32m"
- FG_GREY : mixed = "\x1b[38;5;248m"
- FG_PURPLE : mixed = "\x1b[35m"
- FG_RED : mixed = "\x1b[31m"
- FG_WHITE : mixed = "\x1b[37m"
- FG_YELLOW : mixed = "\x1b[33m"
- ITALIC : mixed = "\x1b[3m"
- KEY_DOWN : mixed = "\x1b[B"
- KEY_LEFT : mixed = "\x1b[D"
- KEY_RIGHT : mixed = "\x1b[C"
- KEY_UP : mixed = "\x1b[A"
- NEGATIVE : mixed = "\x1b[7m"
- RE_ANSI_ANY : mixed = '/\033\[[\d;]*m/'
- RE_ANSI_ID : mixed = '/^\033\[([\d;]*)m$/'
- RESET : mixed = "\x1b[0m"
- STRIKE : mixed = "\x1b[9m"
- UNDERLINE : mixed = "\x1b[4m"
Properties
- $colors : bool|null
Methods
- clear() : void
- Clear the screen.
- clearLine() : void
- Clear the current line.
- color() : string
- Colourise text using ANSI control codes.
- error() : void
- Write text to the standard error stream.
- hasColors() : bool
- Does the given stream have colors? (default STDOUT)
- hasReadline() : bool
- The readline extension is loaded.
- hasTTY() : bool
- Is the host terminal a TTY.
- input() : string
- Get regular input.
- invisible() : string
- Get input, but no echo.
- isAnsi() : bool
- Is this text an ANSI control code?
- isInteractive() : bool
- Is the standard input interactive?
- joinAnsi() : string
- Join text and ANSI control codes.
- masked() : string
- Get input, but the echo is masked.
- options() : string
- Get an option from a list.
- puts() : void
- Write text to the standard output stream.
- question() : bool
- Ask a yes/no question. Accept nothing else.
- setColors() : void
- Set the colors mode.
- stderr() : void
- stdout() : void
- stripAnsi() : string
- Strip ANSI control codes from a string.
- write() : void
- Write text to a stream.
- registerExits() : void
Constants
BG_BLACK
public
mixed
BG_BLACK
= "\x1b[40m"
BG_BLUE
public
mixed
BG_BLUE
= "\x1b[44m"
BG_CYAN
public
mixed
BG_CYAN
= "\x1b[46m"
BG_GREEN
public
mixed
BG_GREEN
= "\x1b[42m"
BG_GREY
public
mixed
BG_GREY
= "\x1b[48;5;248m"
BG_PURPLE
public
mixed
BG_PURPLE
= "\x1b[45m"
BG_RED
public
mixed
BG_RED
= "\x1b[41m"
BG_WHITE
public
mixed
BG_WHITE
= "\x1b[47m"
BG_YELLOW
public
mixed
BG_YELLOW
= "\x1b[43m"
BOLD
public
mixed
BOLD
= "\x1b[1m"
FG_BLACK
public
mixed
FG_BLACK
= "\x1b[30m"
FG_BLUE
public
mixed
FG_BLUE
= "\x1b[34m"
FG_CYAN
public
mixed
FG_CYAN
= "\x1b[36m"
FG_GREEN
public
mixed
FG_GREEN
= "\x1b[32m"
FG_GREY
public
mixed
FG_GREY
= "\x1b[38;5;248m"
FG_PURPLE
public
mixed
FG_PURPLE
= "\x1b[35m"
FG_RED
public
mixed
FG_RED
= "\x1b[31m"
FG_WHITE
public
mixed
FG_WHITE
= "\x1b[37m"
FG_YELLOW
public
mixed
FG_YELLOW
= "\x1b[33m"
ITALIC
public
mixed
ITALIC
= "\x1b[3m"
KEY_DOWN
public
mixed
KEY_DOWN
= "\x1b[B"
KEY_LEFT
public
mixed
KEY_LEFT
= "\x1b[D"
KEY_RIGHT
public
mixed
KEY_RIGHT
= "\x1b[C"
KEY_UP
public
mixed
KEY_UP
= "\x1b[A"
NEGATIVE
public
mixed
NEGATIVE
= "\x1b[7m"
RE_ANSI_ANY
public
mixed
RE_ANSI_ANY
= '/\033\[[\d;]*m/'
RE_ANSI_ID
public
mixed
RE_ANSI_ID
= '/^\033\[([\d;]*)m$/'
RESET
public
mixed
RESET
= "\x1b[0m"
STRIKE
public
mixed
STRIKE
= "\x1b[9m"
UNDERLINE
public
mixed
UNDERLINE
= "\x1b[4m"
Properties
$colors
protected
static bool|null
$colors
= null
Methods
clear()
Clear the screen.
public
static clear() : void
clearLine()
Clear the current line.
public
static clearLine() : void
color()
Colourise text using ANSI control codes.
public
static color(string $text, string ...$colors) : string
This wraps joinAnsi() but ensures the text ends with a RESET.
Parameters
- $text : string
- $colors : string
Tags
Return values
stringerror()
Write text to the standard error stream.
public
static error(mixed ...$args) : void
This supports ANSI control codes.
Parameters
- $args : mixed
hasColors()
Does the given stream have colors? (default STDOUT)
public
static hasColors([resource $stream = STDOUT ]) : bool
Parameters
- $stream : resource = STDOUT
Return values
boolhasReadline()
The readline extension is loaded.
public
static hasReadline() : bool
Return values
boolhasTTY()
Is the host terminal a TTY.
public
static hasTTY() : bool
use isInteractive() or hasColors() instead
This is required for interactive input.
Return values
boolinput()
Get regular input.
public
static input([string|null $prompt = null ]) : string
Parameters
- $prompt : string|null = null
Return values
stringinvisible()
Get input, but no echo.
public
static invisible([string|null $prompt = null ]) : string
Parameters
- $prompt : string|null = null
Return values
stringisAnsi()
Is this text an ANSI control code?
public
static isAnsi(string $text) : bool
Parameters
- $text : string
Return values
boolisInteractive()
Is the standard input interactive?
public
static isInteractive() : bool
Return values
booljoinAnsi()
Join text and ANSI control codes.
public
static joinAnsi(string $separator, array<string|int, string> $items) : string
Unlike implode() this will not add a separator between ANSI control codes.
Parameters
- $separator : string
- $items : array<string|int, string>
Return values
stringmasked()
Get input, but the echo is masked.
public
static masked([string|null $prompt = null ]) : string
Parameters
- $prompt : string|null = null
Return values
stringoptions()
Get an option from a list.
public
static options(string $prompt, array<string|int, string> $options) : string
Use the up/down keys to choose an option.
Parameters
- $prompt : string
- $options : array<string|int, string>
Return values
stringputs()
Write text to the standard output stream.
public
static puts(mixed ...$args) : void
This supports ANSI control codes.
Parameters
- $args : mixed
question()
Ask a yes/no question. Accept nothing else.
public
static question(string $prompt) : bool
Parameters
- $prompt : string
Return values
boolsetColors()
Set the colors mode.
public
static setColors([bool|string $enable = true ]) : void
- 'auto' will use colors if the terminal supports it (default).
- 'true' will use colors, regardless if the terminal supports it.
- 'false' will not use colors.
Parameters
- $enable : bool|string = true
stderr()
public
static stderr(mixed $text) : void
Parameters
- $text : mixed
stdout()
public
static stdout(mixed $text) : void
Parameters
- $text : mixed
stripAnsi()
Strip ANSI control codes from a string.
public
static stripAnsi(string $text) : string
Parameters
- $text : string
Return values
stringwrite()
Write text to a stream.
public
static write(resource $stream, mixed ...$args) : void
This supports ANSI control codes.
Parameters
- $stream : resource
- $args : mixed
registerExits()
protected
static registerExits() : void