Skip to content
PHP Ecosystem
Explore

Console

API reference › yii › helpers › Console

classyii\helpers\Console
ExtendsBaseConsole
Since2.0
Sourceframework/helpers/Console.php

Console helper provides useful methods for command line related tasks such as getting input or formatting and coloring output.

MethodDescriptionDefined by
ansiColorizedSubstr() staticReturns the portion with ANSI color codes of string specified by the start and length parameters.BaseConsole
ansiFormat() staticWill return a string formatted with the given ANSI style.BaseConsole
ansiFormatCode() staticReturns the ANSI format code.BaseConsole
ansiStrlen() staticReturns the length of the string without ANSI color codes.BaseConsole
ansiStrwidth() staticReturns the width of the string without ANSI color codes.BaseConsole
ansiToHtml() staticConverts an ANSI formatted string to HTML.BaseConsole
beginAnsiFormat() staticEchoes an ANSI format code that affects the formatting of any text that is printed afterwards.BaseConsole
clearLine() staticClears the line, the cursor is currently on by sending ANSI control code EL with argument 2 to the terminal.BaseConsole
clearLineAfterCursor() staticClears text from cursor position to the end of the line by sending ANSI control code EL with argument 0 to the terminal.BaseConsole
clearLineBeforeCursor() staticClears text from cursor position to the beginning of the line by sending ANSI control code EL with argument 1 to the terminal.BaseConsole
clearScreen() staticClears entire screen content by sending ANSI control code ED with argument 2 to the terminal.BaseConsole
clearScreenAfterCursor() staticClears text from cursor to the end of the screen by sending ANSI control code ED with argument 0 to the terminal.BaseConsole
clearScreenBeforeCursor() staticClears text from cursor to the beginning of the screen by sending ANSI control code ED with argument 1 to the terminal.BaseConsole
confirm() staticAsks user to confirm by typing y or n.BaseConsole
endAnsiFormat() staticResets any ANSI format set by previous method beginAnsiFormat() Any output after this will have default text format.BaseConsole
endProgress() staticEnds a progress bar that has been started by startProgress().BaseConsole
error() staticPrints text to STDERR appended with a carriage return (PHP_EOL).BaseConsole
errorSummary() staticGenerates a summary of the validation errors.BaseConsole
escape() staticEscapes % so they don’t get interpreted as color codes when the string is parsed by renderColoredString().BaseConsole
getScreenSize() staticReturns terminal screen size.BaseConsole
hideCursor() staticHides the cursor by sending ANSI DECTCEM code ?25l to the terminal.BaseConsole
input() staticAsks the user for input. Ends when the user types a carriage return (PHP_EOL). Optionally, It also provides a prompt.BaseConsole
isRunningOnWindows() staticReturns true if the console is running on windows.BaseConsole
markdownToAnsi() staticConverts Markdown to be better readable in console environments by applying some ANSI format.BaseConsole
moveCursorBackward() staticMoves the terminal cursor backward by sending ANSI control code CUB to the terminal.BaseConsole
moveCursorDown() staticMoves the terminal cursor down by sending ANSI control code CUD to the terminal.BaseConsole
moveCursorForward() staticMoves the terminal cursor forward by sending ANSI control code CUF to the terminal.BaseConsole
moveCursorNextLine() staticMoves the terminal cursor to the beginning of the next line by sending ANSI control code CNL to the terminal.BaseConsole
moveCursorPrevLine() staticMoves the terminal cursor to the beginning of the previous line by sending ANSI control code CPL to the terminal.BaseConsole
moveCursorTo() staticMoves the cursor to an absolute position given as column and row by sending ANSI control code CUP or CHA to the terminal.BaseConsole
moveCursorUp() staticMoves the terminal cursor up by sending ANSI control code CUU to the terminal.BaseConsole
output() staticPrints text to STDOUT appended with a carriage return (PHP_EOL).BaseConsole
prompt() staticPrompts the user for input and validates it.BaseConsole
renderColoredString() staticConverts a string to ansi formatted by replacing patterns like %y (for yellow) with ansi control codes.BaseConsole
restoreCursorPosition() staticRestores the cursor position saved with saveCursorPosition() by sending ANSI control code RCP to the terminal.BaseConsole
saveCursorPosition() staticSaves the current cursor position by sending ANSI control code SCP to the terminal.BaseConsole
scrollDown() staticScrolls whole page down by sending ANSI control code SD to the terminal.BaseConsole
scrollUp() staticScrolls whole page up by sending ANSI control code SU to the terminal.BaseConsole
select() staticGives the user an option to choose from. Giving ’?’ as an input will show a list of options to choose from and their explanations.BaseConsole
showCursor() staticWill show a cursor again when it has been hidden by hideCursor() by sending ANSI DECTCEM code ?25h to the terminal.BaseConsole
startProgress() staticStarts display of a progress bar on screen.BaseConsole
stderr() staticPrints a string to STDERR.BaseConsole
stdin() staticGets input from STDIN and returns a string right-trimmed for EOLs.BaseConsole
stdout() staticPrints a string to STDOUT.BaseConsole
streamSupportsAnsiColors() staticReturns true if the stream supports colorization. ANSI colors are disabled if not supported by the stream.BaseConsole
stripAnsiFormat() staticStrips ANSI control codes from a string.BaseConsole
updateProgress() staticUpdates a progress bar that has been started by startProgress().BaseConsole
wrapText() staticWord wrap text with indentation to fit the screen size.BaseConsole
xtermBgColor() staticReturns the ansi format code for xterm background color.BaseConsole
xtermFgColor() staticReturns the ansi format code for xterm foreground color.BaseConsole