BaseConsole
in package
BaseConsole provides concrete implementation for [[Console]].
Do not use BaseConsole. Use [[Console]] instead.
Tags
Table of Contents
Constants
- BG_BLACK = 40
- BG_BLUE = 44
- BG_CYAN = 46
- BG_GREEN = 42
- BG_GREY = 47
- BG_PURPLE = 45
- BG_RED = 41
- BG_YELLOW = 43
- BLINK = 5
- BOLD = 1
- CONCEALED = 8
- CROSSED_OUT = 9
- ENCIRCLED = 52
- FG_BLACK = 30
- FG_BLUE = 34
- FG_CYAN = 36
- FG_GREEN = 32
- FG_GREY = 37
- FG_PURPLE = 35
- FG_RED = 31
- FG_YELLOW = 33
- FRAMED = 51
- ITALIC = 3
- NEGATIVE = 7
- NORMAL = 0
- OVERLINED = 53
- RESET = 0
- UNDERLINE = 4
Properties
- $_progressEta : mixed
- $_progressEtaLastDone : mixed
- $_progressEtaLastUpdate : mixed
- $_progressPrefix : mixed
- $_progressStart : mixed
- $_progressWidth : mixed
Methods
- ansiColorizedSubstr() : string
- Returns the portion with ANSI color codes of string specified by the start and length parameters.
- ansiFormat() : string
- Will return a string formatted with the given ANSI style.
- ansiFormatCode() : string
- Returns the ANSI format code.
- ansiStrlen() : int
- Returns the length of the string without ANSI color codes.
- ansiStrwidth() : int
- Returns the width of the string without ANSI color codes.
- ansiToHtml() : string
- Converts an ANSI formatted string to HTML.
- beginAnsiFormat() : mixed
- Echoes an ANSI format code that affects the formatting of any text that is printed afterwards.
- clearLine() : mixed
- Clears the line, the cursor is currently on by sending ANSI control code EL with argument 2 to the terminal.
- clearLineAfterCursor() : mixed
- Clears text from cursor position to the end of the line by sending ANSI control code EL with argument 0 to the terminal.
- clearLineBeforeCursor() : mixed
- Clears text from cursor position to the beginning of the line by sending ANSI control code EL with argument 1 to the terminal.
- clearScreen() : mixed
- Clears entire screen content by sending ANSI control code ED with argument 2 to the terminal.
- clearScreenAfterCursor() : mixed
- Clears text from cursor to the end of the screen by sending ANSI control code ED with argument 0 to the terminal.
- clearScreenBeforeCursor() : mixed
- Clears text from cursor to the beginning of the screen by sending ANSI control code ED with argument 1 to the terminal.
- confirm() : bool
- Asks user to confirm by typing y or n.
- endAnsiFormat() : mixed
- Resets any ANSI format set by previous method [[beginAnsiFormat()]] Any output after this will have default text format.
- endProgress() : mixed
- Ends a progress bar that has been started by [[startProgress()]].
- error() : int|bool
- Prints text to STDERR appended with a carriage return (PHP_EOL).
- errorSummary() : string
- Generates a summary of the validation errors.
- escape() : string
- Escapes % so they don't get interpreted as color codes when the string is parsed by [[renderColoredString]].
- getScreenSize() : array<string|int, mixed>|bool
- Returns terminal screen size.
- hideCursor() : mixed
- Hides the cursor by sending ANSI DECTCEM code ?25l to the terminal.
- input() : string
- Asks the user for input. Ends when the user types a carriage return (PHP_EOL). Optionally, It also provides a prompt.
- isRunningOnWindows() : bool
- Returns true if the console is running on windows.
- markdownToAnsi() : string
- Converts Markdown to be better readable in console environments by applying some ANSI format.
- moveCursorBackward() : mixed
- Moves the terminal cursor backward by sending ANSI control code CUB to the terminal.
- moveCursorDown() : mixed
- Moves the terminal cursor down by sending ANSI control code CUD to the terminal.
- moveCursorForward() : mixed
- Moves the terminal cursor forward by sending ANSI control code CUF to the terminal.
- moveCursorNextLine() : mixed
- Moves the terminal cursor to the beginning of the next line by sending ANSI control code CNL to the terminal.
- moveCursorPrevLine() : mixed
- Moves the terminal cursor to the beginning of the previous line by sending ANSI control code CPL to the terminal.
- moveCursorTo() : mixed
- Moves the cursor to an absolute position given as column and row by sending ANSI control code CUP or CHA to the terminal.
- moveCursorUp() : mixed
- Moves the terminal cursor up by sending ANSI control code CUU to the terminal.
- output() : int|bool
- Prints text to STDOUT appended with a carriage return (PHP_EOL).
- prompt() : string
- Prompts the user for input and validates it.
- renderColoredString() : string
- Converts a string to ansi formatted by replacing patterns like %y (for yellow) with ansi control codes.
- restoreCursorPosition() : mixed
- Restores the cursor position saved with [[saveCursorPosition()]] by sending ANSI control code RCP to the terminal.
- saveCursorPosition() : mixed
- Saves the current cursor position by sending ANSI control code SCP to the terminal.
- scrollDown() : mixed
- Scrolls whole page down by sending ANSI control code SD to the terminal.
- scrollUp() : mixed
- Scrolls whole page up by sending ANSI control code SU to the terminal.
- select() : string
- Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations.
- showCursor() : mixed
- Will show a cursor again when it has been hidden by [[hideCursor()]] by sending ANSI DECTCEM code ?25h to the terminal.
- startProgress() : mixed
- Starts display of a progress bar on screen.
- stderr() : int|bool
- Prints a string to STDERR.
- stdin() : string
- Gets input from STDIN and returns a string right-trimmed for EOLs.
- stdout() : int|bool
- Prints a string to STDOUT.
- streamSupportsAnsiColors() : bool
- Returns true if the stream supports colorization. ANSI colors are disabled if not supported by the stream.
- stripAnsiFormat() : string
- Strips ANSI control codes from a string.
- updateProgress() : mixed
- Updates a progress bar that has been started by [[startProgress()]].
- wrapText() : string
- Word wrap text with indentation to fit the screen size.
- xtermBgColor() : string
- Returns the ansi format code for xterm background color.
- xtermFgColor() : string
- Returns the ansi format code for xterm foreground color.
- ansiCodesPattern() : mixed
- collectErrors() : array<string|int, mixed>
- Return array of the validation errors
- getProgressbarWidth() : int
- Return width of the progressbar
- setETA() : mixed
- Calculate $_progressEta, $_progressEtaLastUpdate and $_progressEtaLastDone
Constants
BG_BLACK
public
mixed
BG_BLACK
= 40
BG_BLUE
public
mixed
BG_BLUE
= 44
BG_CYAN
public
mixed
BG_CYAN
= 46
BG_GREEN
public
mixed
BG_GREEN
= 42
BG_GREY
public
mixed
BG_GREY
= 47
BG_PURPLE
public
mixed
BG_PURPLE
= 45
BG_RED
public
mixed
BG_RED
= 41
BG_YELLOW
public
mixed
BG_YELLOW
= 43
BLINK
public
mixed
BLINK
= 5
BOLD
public
mixed
BOLD
= 1
CONCEALED
public
mixed
CONCEALED
= 8
CROSSED_OUT
public
mixed
CROSSED_OUT
= 9
ENCIRCLED
public
mixed
ENCIRCLED
= 52
FG_BLACK
public
mixed
FG_BLACK
= 30
FG_BLUE
public
mixed
FG_BLUE
= 34
FG_CYAN
public
mixed
FG_CYAN
= 36
FG_GREEN
public
mixed
FG_GREEN
= 32
FG_GREY
public
mixed
FG_GREY
= 37
FG_PURPLE
public
mixed
FG_PURPLE
= 35
FG_RED
public
mixed
FG_RED
= 31
FG_YELLOW
public
mixed
FG_YELLOW
= 33
FRAMED
public
mixed
FRAMED
= 51
ITALIC
public
mixed
ITALIC
= 3
NEGATIVE
public
mixed
NEGATIVE
= 7
NORMAL
public
mixed
NORMAL
= 0
OVERLINED
public
mixed
OVERLINED
= 53
RESET
public
mixed
RESET
= 0
UNDERLINE
public
mixed
UNDERLINE
= 4
Properties
$_progressEta
private
static mixed
$_progressEta
$_progressEtaLastDone
private
static mixed
$_progressEtaLastDone
= 0
$_progressEtaLastUpdate
private
static mixed
$_progressEtaLastUpdate
$_progressPrefix
private
static mixed
$_progressPrefix
$_progressStart
private
static mixed
$_progressStart
$_progressWidth
private
static mixed
$_progressWidth
Methods
ansiColorizedSubstr()
Returns the portion with ANSI color codes of string specified by the start and length parameters.
public
static ansiColorizedSubstr(string $string, int $start, int $length) : string
If string has color codes, then will be return "TEXT_COLOR + TEXT_STRING + DEFAULT_COLOR", else will be simple "TEXT_STRING".
Parameters
- $string : string
- $start : int
- $length : int
Return values
stringansiFormat()
Will return a string formatted with the given ANSI style.
public
static ansiFormat(string $string[, array<string|int, mixed> $format = [] ]) : string
Parameters
- $string : string
-
the string to be formatted
- $format : array<string|int, mixed> = []
-
An array containing formatting values. You can pass any of the
FG_*
,BG_*
andTEXT_*
constants and also [[xtermFgColor]] and [[xtermBgColor]] to specify a format.
Return values
stringansiFormatCode()
Returns the ANSI format code.
public
static ansiFormatCode(array<string|int, mixed> $format) : string
Parameters
- $format : array<string|int, mixed>
-
An array containing formatting values. You can pass any of the
FG_*
,BG_*
andTEXT_*
constants and also [[xtermFgColor]] and [[xtermBgColor]] to specify a format.
Return values
string —The ANSI format code according to the given formatting constants.
ansiStrlen()
Returns the length of the string without ANSI color codes.
public
static ansiStrlen(string $string) : int
Parameters
- $string : string
-
the string to measure
Return values
int —the length of the string not counting ANSI format characters
ansiStrwidth()
Returns the width of the string without ANSI color codes.
public
static ansiStrwidth(string $string) : int
Parameters
- $string : string
-
the string to measure
Tags
Return values
int —the width of the string not counting ANSI format characters
ansiToHtml()
Converts an ANSI formatted string to HTML.
public
static ansiToHtml(string $string[, array<string|int, mixed> $styleMap = [] ]) : string
Note: xTerm 256 bit colors are currently not supported.
Parameters
- $string : string
-
the string to convert.
- $styleMap : array<string|int, mixed> = []
-
an optional mapping of ANSI control codes such as FG_COLOR or [[BOLD]] to a set of css style definitions. The CSS style definitions are represented as an array where the array keys correspond to the css style attribute names and the values are the css values. values may be arrays that will be merged and imploded with
' '
when rendered.
Return values
string —HTML representation of the ANSI formatted string
beginAnsiFormat()
Echoes an ANSI format code that affects the formatting of any text that is printed afterwards.
public
static beginAnsiFormat(array<string|int, mixed> $format) : mixed
Parameters
- $format : array<string|int, mixed>
-
An array containing formatting values. You can pass any of the
FG_*
,BG_*
andTEXT_*
constants and also [[xtermFgColor]] and [[xtermBgColor]] to specify a format.
Tags
clearLine()
Clears the line, the cursor is currently on by sending ANSI control code EL with argument 2 to the terminal.
public
static clearLine() : mixed
Cursor position will not be changed.
clearLineAfterCursor()
Clears text from cursor position to the end of the line by sending ANSI control code EL with argument 0 to the terminal.
public
static clearLineAfterCursor() : mixed
Cursor position will not be changed.
clearLineBeforeCursor()
Clears text from cursor position to the beginning of the line by sending ANSI control code EL with argument 1 to the terminal.
public
static clearLineBeforeCursor() : mixed
Cursor position will not be changed.
clearScreen()
Clears entire screen content by sending ANSI control code ED with argument 2 to the terminal.
public
static clearScreen() : mixed
Cursor position will not be changed. Note: ANSI.SYS implementation used in windows will reset cursor position to upper left corner of the screen.
clearScreenAfterCursor()
Clears text from cursor to the end of the screen by sending ANSI control code ED with argument 0 to the terminal.
public
static clearScreenAfterCursor() : mixed
Cursor position will not be changed.
clearScreenBeforeCursor()
Clears text from cursor to the beginning of the screen by sending ANSI control code ED with argument 1 to the terminal.
public
static clearScreenBeforeCursor() : mixed
Cursor position will not be changed.
confirm()
Asks user to confirm by typing y or n.
public
static confirm(string $message[, bool $default = false ]) : bool
A typical usage looks like the following:
if (Console::confirm("Are you sure?")) {
echo "user typed yes\n";
} else {
echo "user typed no\n";
}
Parameters
- $message : string
-
to print out before waiting for user input
- $default : bool = false
-
this value is returned if no selection is made.
Return values
bool —whether user confirmed
endAnsiFormat()
Resets any ANSI format set by previous method [[beginAnsiFormat()]] Any output after this will have default text format.
public
static endAnsiFormat() : mixed
This is equal to calling.
echo Console::ansiFormatCode([Console::RESET])
endProgress()
Ends a progress bar that has been started by [[startProgress()]].
public
static endProgress([string|bool $remove = false ][, bool $keepPrefix = true ]) : mixed
Parameters
- $remove : string|bool = false
-
This can be
false
to leave the progress bar on screen and just print a newline. If set totrue
, the line of the progress bar will be cleared. This may also be a string to be displayed instead of the progress bar. - $keepPrefix : bool = true
-
whether to keep the prefix that has been specified for the progressbar when progressbar gets removed. Defaults to true.
Tags
error()
Prints text to STDERR appended with a carriage return (PHP_EOL).
public
static error([string|null $string = null ]) : int|bool
Parameters
- $string : string|null = null
-
the text to print
Return values
int|bool —number of bytes printed or false on error.
errorSummary()
Generates a summary of the validation errors.
public
static errorSummary(Model|array<string|int, Model> $models[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $models : Model|array<string|int, Model>
-
the model(s) whose validation errors are to be displayed.
- $options : array<string|int, mixed> = []
-
the tag options in terms of name-value pairs. The following options are specially handled:
- showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise
only the first error message for each attribute will be shown. Defaults to
false
.
- showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise
only the first error message for each attribute will be shown. Defaults to
Tags
Return values
string —the generated error summary
escape()
Escapes % so they don't get interpreted as color codes when the string is parsed by [[renderColoredString]].
public
static escape(string $string) : string
Parameters
- $string : string
-
String to escape
Return values
stringgetScreenSize()
Returns terminal screen size.
public
static getScreenSize([bool $refresh = false ]) : array<string|int, mixed>|bool
Usage:
list($width, $height) = ConsoleHelper::getScreenSize();
Parameters
- $refresh : bool = false
-
whether to force checking and not re-use cached size value. This is useful to detect changing window size while the application is running but may not get up to date values on every terminal.
Return values
array<string|int, mixed>|bool —An array of ($width, $height) or false when it was not able to determine size.
hideCursor()
Hides the cursor by sending ANSI DECTCEM code ?25l to the terminal.
public
static hideCursor() : mixed
Use [[showCursor()]] to bring it back. Do not forget to show cursor when your application exits. Cursor might stay hidden in terminal after exit.
input()
Asks the user for input. Ends when the user types a carriage return (PHP_EOL). Optionally, It also provides a prompt.
public
static input([string|null $prompt = null ]) : string
Parameters
- $prompt : string|null = null
-
the prompt to display before waiting for input (optional)
Return values
string —the user's input
isRunningOnWindows()
Returns true if the console is running on windows.
public
static isRunningOnWindows() : bool
Return values
boolmarkdownToAnsi()
Converts Markdown to be better readable in console environments by applying some ANSI format.
public
static markdownToAnsi(string $markdown) : string
Parameters
- $markdown : string
-
the markdown string.
Return values
string —the parsed result as ANSI formatted string.
moveCursorBackward()
Moves the terminal cursor backward by sending ANSI control code CUB to the terminal.
public
static moveCursorBackward([int $steps = 1 ]) : mixed
If the cursor is already at the edge of the screen, this has no effect.
Parameters
- $steps : int = 1
-
number of steps the cursor should be moved backward
moveCursorDown()
Moves the terminal cursor down by sending ANSI control code CUD to the terminal.
public
static moveCursorDown([int $rows = 1 ]) : mixed
If the cursor is already at the edge of the screen, this has no effect.
Parameters
- $rows : int = 1
-
number of rows the cursor should be moved down
moveCursorForward()
Moves the terminal cursor forward by sending ANSI control code CUF to the terminal.
public
static moveCursorForward([int $steps = 1 ]) : mixed
If the cursor is already at the edge of the screen, this has no effect.
Parameters
- $steps : int = 1
-
number of steps the cursor should be moved forward
moveCursorNextLine()
Moves the terminal cursor to the beginning of the next line by sending ANSI control code CNL to the terminal.
public
static moveCursorNextLine([int $lines = 1 ]) : mixed
Parameters
- $lines : int = 1
-
number of lines the cursor should be moved down
moveCursorPrevLine()
Moves the terminal cursor to the beginning of the previous line by sending ANSI control code CPL to the terminal.
public
static moveCursorPrevLine([int $lines = 1 ]) : mixed
Parameters
- $lines : int = 1
-
number of lines the cursor should be moved up
moveCursorTo()
Moves the cursor to an absolute position given as column and row by sending ANSI control code CUP or CHA to the terminal.
public
static moveCursorTo(int $column[, int|null $row = null ]) : mixed
Parameters
- $column : int
-
1-based column number, 1 is the left edge of the screen.
- $row : int|null = null
-
1-based row number, 1 is the top edge of the screen. if not set, will move cursor only in current line.
moveCursorUp()
Moves the terminal cursor up by sending ANSI control code CUU to the terminal.
public
static moveCursorUp([int $rows = 1 ]) : mixed
If the cursor is already at the edge of the screen, this has no effect.
Parameters
- $rows : int = 1
-
number of rows the cursor should be moved up
output()
Prints text to STDOUT appended with a carriage return (PHP_EOL).
public
static output([string|null $string = null ]) : int|bool
Parameters
- $string : string|null = null
-
the text to print
Return values
int|bool —number of bytes printed or false on error.
prompt()
Prompts the user for input and validates it.
public
static prompt(string $text[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $text : string
-
prompt string
- $options : array<string|int, mixed> = []
-
the options to validate the input:
-
required
: whether it is required or not -
default
: default value if no input is inserted by the user -
pattern
: regular expression pattern to validate user input -
validator
: a callable function to validate input. The function must accept two parameters: -
input
: the user input to validate -
error
: the error value passed by reference if validation failed.
-
Return values
string —the user input
renderColoredString()
Converts a string to ansi formatted by replacing patterns like %y (for yellow) with ansi control codes.
public
static renderColoredString(string $string[, bool $colored = true ]) : string
Uses almost the same syntax as https://github.com/pear/Console_Color2/blob/master/Console/Color2.php The conversion table is: ('bold' meaning 'light' on some terminals). It's almost the same conversion table irssi uses.
text text background ------------------------------------------------ %k %K %0 black dark grey black %r %R %1 red bold red red %g %G %2 green bold green green %y %Y %3 yellow bold yellow yellow %b %B %4 blue bold blue blue %m %M %5 magenta bold magenta magenta %p %P magenta (think: purple) %c %C %6 cyan bold cyan cyan %w %W %7 white bold white white %F Blinking, Flashing %U Underline %8 Reverse %_,%9 Bold %n Resets the color %% A single %
First param is the string to convert, second is an optional flag if colors should be used. It defaults to true, if set to false, the color codes will just be removed (And %% will be transformed into %)
Parameters
- $string : string
-
String to convert
- $colored : bool = true
-
Should the string be colored?
Return values
stringrestoreCursorPosition()
Restores the cursor position saved with [[saveCursorPosition()]] by sending ANSI control code RCP to the terminal.
public
static restoreCursorPosition() : mixed
saveCursorPosition()
Saves the current cursor position by sending ANSI control code SCP to the terminal.
public
static saveCursorPosition() : mixed
Position can then be restored with [[restoreCursorPosition()]].
scrollDown()
Scrolls whole page down by sending ANSI control code SD to the terminal.
public
static scrollDown([int $lines = 1 ]) : mixed
New lines are added at the top. This is not supported by ANSI.SYS used in windows.
Parameters
- $lines : int = 1
-
number of lines to scroll down
scrollUp()
Scrolls whole page up by sending ANSI control code SU to the terminal.
public
static scrollUp([int $lines = 1 ]) : mixed
New lines are added at the bottom. This is not supported by ANSI.SYS used in windows.
Parameters
- $lines : int = 1
-
number of lines to scroll up
select()
Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations.
public
static select(string $prompt[, array<string|int, mixed> $options = [] ][, string|null $default = null ]) : string
Parameters
- $prompt : string
-
the prompt message
- $options : array<string|int, mixed> = []
-
Key-value array of options to choose from. Key is what is inputed and used, value is what's displayed to end user by help command.
- $default : string|null = null
-
value to use when the user doesn't provide an option. If the default is
null
, the user is required to select an option.
Tags
Return values
string —An option character the user chose
showCursor()
Will show a cursor again when it has been hidden by [[hideCursor()]] by sending ANSI DECTCEM code ?25h to the terminal.
public
static showCursor() : mixed
startProgress()
Starts display of a progress bar on screen.
public
static startProgress(int $done, int $total[, string $prefix = '' ][, int|float|bool|null $width = null ]) : mixed
This bar will be updated by [[updateProgress()]] and may be ended by [[endProgress()]].
The following example shows a simple usage of a progress bar:
Console::startProgress(0, 1000);
for ($n = 1; $n <= 1000; $n++) {
usleep(1000);
Console::updateProgress($n, 1000);
}
Console::endProgress();
Git clone like progress (showing only status information):
Console::startProgress(0, 1000, 'Counting objects: ', false);
for ($n = 1; $n <= 1000; $n++) {
usleep(1000);
Console::updateProgress($n, 1000);
}
Console::endProgress("done." . PHP_EOL);
Parameters
- $done : int
-
the number of items that are completed.
- $total : int
-
the total value of items that are to be done.
- $prefix : string = ''
-
an optional string to display before the progress bar. Default to empty string which results in no prefix to be displayed.
- $width : int|float|bool|null = null
-
optional width of the progressbar. This can be an integer representing the number of characters to display for the progress bar or a float between 0 and 1 representing the percentage of screen with the progress bar may take. It can also be set to false to disable the bar and only show progress information like percent, number of items and ETA. If not set, the bar will be as wide as the screen. Screen size will be detected using [[getScreenSize()]].
Tags
stderr()
Prints a string to STDERR.
public
static stderr(string $string) : int|bool
Parameters
- $string : string
-
the string to print
Return values
int|bool —Number of bytes printed or false on error
stdin()
Gets input from STDIN and returns a string right-trimmed for EOLs.
public
static stdin([bool $raw = false ]) : string
Parameters
- $raw : bool = false
-
If set to true, returns the raw string without trimming
Return values
string —the string read from stdin
stdout()
Prints a string to STDOUT.
public
static stdout(string $string) : int|bool
Parameters
- $string : string
-
the string to print
Return values
int|bool —Number of bytes printed or false on error
streamSupportsAnsiColors()
Returns true if the stream supports colorization. ANSI colors are disabled if not supported by the stream.
public
static streamSupportsAnsiColors(mixed $stream) : bool
- windows without ansicon
- not tty consoles
Parameters
- $stream : mixed
Return values
bool —true if the stream supports ANSI colors, otherwise false.
stripAnsiFormat()
Strips ANSI control codes from a string.
public
static stripAnsiFormat(string $string) : string
Parameters
- $string : string
-
String to strip
Return values
stringupdateProgress()
Updates a progress bar that has been started by [[startProgress()]].
public
static updateProgress(int $done, int $total[, string|null $prefix = null ]) : mixed
Parameters
- $done : int
-
the number of items that are completed.
- $total : int
-
the total value of items that are to be done.
- $prefix : string|null = null
-
an optional string to display before the progress bar. Defaults to null meaning the prefix specified by [[startProgress()]] will be used. If prefix is specified it will update the prefix that will be used by later calls.
Tags
wrapText()
Word wrap text with indentation to fit the screen size.
public
static wrapText(string $text[, int $indent = 0 ][, bool $refresh = false ]) : string
If screen size could not be detected, or the indentation is greater than the screen size, the text will not be wrapped.
The first line will not be indented, so Console::wrapText("Lorem ipsum dolor sit amet.", 4)
will result in the
following output, given the screen width is 16 characters:
Lorem ipsum
dolor sit
amet.
Parameters
- $text : string
-
the text to be wrapped
- $indent : int = 0
-
number of spaces to use for indentation.
- $refresh : bool = false
-
whether to force refresh of screen size. This will be passed to [[getScreenSize()]].
Tags
Return values
string —the wrapped text.
xtermBgColor()
Returns the ansi format code for xterm background color.
public
static xtermBgColor(int $colorCode) : string
You can pass the return value of this to one of the formatting methods: [[ansiFormat]], [[ansiFormatCode]], [[beginAnsiFormat]].
Parameters
- $colorCode : int
-
xterm color code
Tags
Return values
stringxtermFgColor()
Returns the ansi format code for xterm foreground color.
public
static xtermFgColor(int $colorCode) : string
You can pass the return value of this to one of the formatting methods: [[ansiFormat]], [[ansiFormatCode]], [[beginAnsiFormat]].
Parameters
- $colorCode : int
-
xterm color code
Tags
Return values
stringansiCodesPattern()
private
static ansiCodesPattern() : mixed
collectErrors()
Return array of the validation errors
private
static collectErrors(Model|array<string|int, Model> $models, mixed $showAllErrors) : array<string|int, mixed>
Parameters
- $models : Model|array<string|int, Model>
-
the model(s) whose validation errors are to be displayed.
- $showAllErrors : mixed
-
boolean, if set to true every error message for each attribute will be shown otherwise only the first error message for each attribute will be shown.
Tags
Return values
array<string|int, mixed> —of the validation errors
getProgressbarWidth()
Return width of the progressbar
private
static getProgressbarWidth(string $prefix) : int
Parameters
- $prefix : string
-
an optional string to display before the progress bar.
Tags
Return values
int —screen width
setETA()
Calculate $_progressEta, $_progressEtaLastUpdate and $_progressEtaLastDone
private
static setETA(int $done, int $total) : mixed
Parameters
- $done : int
-
the number of items that are completed.
- $total : int
-
the total value of items that are to be done.