# Console

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

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [helpers](/docs/api/yii/helpers/index.md) › Console

| class | `yii\helpers\Console` |
| --- | --- |
| Extends | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| Since | 2.0 |
| Source | [`framework/helpers/Console.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/helpers/Console.php#L18) |

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

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-ansiColorizedSubstr"></span>[`ansiColorizedSubstr()`](/docs/api/yii/helpers/baseconsole/index.md#method-ansiColorizedSubstr) static | Returns the portion with ANSI color codes of string specified by the start and length parameters. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-ansiFormat"></span>[`ansiFormat()`](/docs/api/yii/helpers/baseconsole/index.md#method-ansiFormat) static | Will return a string formatted with the given ANSI style. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-ansiFormatCode"></span>[`ansiFormatCode()`](/docs/api/yii/helpers/baseconsole/index.md#method-ansiFormatCode) static | Returns the ANSI format code. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-ansiStrlen"></span>[`ansiStrlen()`](/docs/api/yii/helpers/baseconsole/index.md#method-ansiStrlen) static | Returns the length of the string without ANSI color codes. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-ansiStrwidth"></span>[`ansiStrwidth()`](/docs/api/yii/helpers/baseconsole/index.md#method-ansiStrwidth) static | Returns the width of the string without ANSI color codes. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-ansiToHtml"></span>[`ansiToHtml()`](/docs/api/yii/helpers/baseconsole/index.md#method-ansiToHtml) static | Converts an ANSI formatted string to HTML. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-beginAnsiFormat"></span>[`beginAnsiFormat()`](/docs/api/yii/helpers/baseconsole/index.md#method-beginAnsiFormat) static | Echoes an ANSI format code that affects the formatting of any text that is printed afterwards. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-clearLine"></span>[`clearLine()`](/docs/api/yii/helpers/baseconsole/index.md#method-clearLine) static | Clears the line, the cursor is currently on by sending ANSI control code EL with argument 2 to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-clearLineAfterCursor"></span>[`clearLineAfterCursor()`](/docs/api/yii/helpers/baseconsole/index.md#method-clearLineAfterCursor) static | Clears text from cursor position to the end of the line by sending ANSI control code EL with argument 0 to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-clearLineBeforeCursor"></span>[`clearLineBeforeCursor()`](/docs/api/yii/helpers/baseconsole/index.md#method-clearLineBeforeCursor) static | Clears text from cursor position to the beginning of the line by sending ANSI control code EL with argument 1 to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-clearScreen"></span>[`clearScreen()`](/docs/api/yii/helpers/baseconsole/index.md#method-clearScreen) static | Clears entire screen content by sending ANSI control code ED with argument 2 to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-clearScreenAfterCursor"></span>[`clearScreenAfterCursor()`](/docs/api/yii/helpers/baseconsole/index.md#method-clearScreenAfterCursor) static | Clears text from cursor to the end of the screen by sending ANSI control code ED with argument 0 to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-clearScreenBeforeCursor"></span>[`clearScreenBeforeCursor()`](/docs/api/yii/helpers/baseconsole/index.md#method-clearScreenBeforeCursor) static | Clears text from cursor to the beginning of the screen by sending ANSI control code ED with argument 1 to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-confirm"></span>[`confirm()`](/docs/api/yii/helpers/baseconsole/index.md#method-confirm) static | Asks user to confirm by typing y or n. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-endAnsiFormat"></span>[`endAnsiFormat()`](/docs/api/yii/helpers/baseconsole/index.md#method-endAnsiFormat) static | Resets any ANSI format set by previous method [`beginAnsiFormat()`](/docs/api/yii/helpers/baseconsole/index.md#method-beginAnsiFormat) Any output after this will have default text format. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-endProgress"></span>[`endProgress()`](/docs/api/yii/helpers/baseconsole/index.md#method-endProgress) static | Ends a progress bar that has been started by [`startProgress()`](/docs/api/yii/helpers/baseconsole/index.md#method-startProgress). | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-error"></span>[`error()`](/docs/api/yii/helpers/baseconsole/index.md#method-error) static | Prints text to STDERR appended with a carriage return (PHP_EOL). | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-errorSummary"></span>[`errorSummary()`](/docs/api/yii/helpers/baseconsole/index.md#method-errorSummary) static | Generates a summary of the validation errors. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-escape"></span>[`escape()`](/docs/api/yii/helpers/baseconsole/index.md#method-escape) static | Escapes % so they don't get interpreted as color codes when the string is parsed by [`renderColoredString()`](/docs/api/yii/helpers/baseconsole/index.md#method-renderColoredString). | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-getScreenSize"></span>[`getScreenSize()`](/docs/api/yii/helpers/baseconsole/index.md#method-getScreenSize) static | Returns terminal screen size. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-hideCursor"></span>[`hideCursor()`](/docs/api/yii/helpers/baseconsole/index.md#method-hideCursor) static | Hides the cursor by sending ANSI DECTCEM code ?25l to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-input"></span>[`input()`](/docs/api/yii/helpers/baseconsole/index.md#method-input) static | Asks the user for input. Ends when the user types a carriage return (PHP_EOL). Optionally, It also provides a prompt. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-isRunningOnWindows"></span>[`isRunningOnWindows()`](/docs/api/yii/helpers/baseconsole/index.md#method-isRunningOnWindows) static | Returns true if the console is running on windows. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-markdownToAnsi"></span>[`markdownToAnsi()`](/docs/api/yii/helpers/baseconsole/index.md#method-markdownToAnsi) static | Converts Markdown to be better readable in console environments by applying some ANSI format. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-moveCursorBackward"></span>[`moveCursorBackward()`](/docs/api/yii/helpers/baseconsole/index.md#method-moveCursorBackward) static | Moves the terminal cursor backward by sending ANSI control code CUB to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-moveCursorDown"></span>[`moveCursorDown()`](/docs/api/yii/helpers/baseconsole/index.md#method-moveCursorDown) static | Moves the terminal cursor down by sending ANSI control code CUD to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-moveCursorForward"></span>[`moveCursorForward()`](/docs/api/yii/helpers/baseconsole/index.md#method-moveCursorForward) static | Moves the terminal cursor forward by sending ANSI control code CUF to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-moveCursorNextLine"></span>[`moveCursorNextLine()`](/docs/api/yii/helpers/baseconsole/index.md#method-moveCursorNextLine) static | Moves the terminal cursor to the beginning of the next line by sending ANSI control code CNL to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-moveCursorPrevLine"></span>[`moveCursorPrevLine()`](/docs/api/yii/helpers/baseconsole/index.md#method-moveCursorPrevLine) static | Moves the terminal cursor to the beginning of the previous line by sending ANSI control code CPL to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-moveCursorTo"></span>[`moveCursorTo()`](/docs/api/yii/helpers/baseconsole/index.md#method-moveCursorTo) static | Moves the cursor to an absolute position given as column and row by sending ANSI control code CUP or CHA to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-moveCursorUp"></span>[`moveCursorUp()`](/docs/api/yii/helpers/baseconsole/index.md#method-moveCursorUp) static | Moves the terminal cursor up by sending ANSI control code CUU to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-output"></span>[`output()`](/docs/api/yii/helpers/baseconsole/index.md#method-output) static | Prints text to STDOUT appended with a carriage return (PHP_EOL). | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-prompt"></span>[`prompt()`](/docs/api/yii/helpers/baseconsole/index.md#method-prompt) static | Prompts the user for input and validates it. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-renderColoredString"></span>[`renderColoredString()`](/docs/api/yii/helpers/baseconsole/index.md#method-renderColoredString) static | Converts a string to ansi formatted by replacing patterns like %y (for yellow) with ansi control codes. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-restoreCursorPosition"></span>[`restoreCursorPosition()`](/docs/api/yii/helpers/baseconsole/index.md#method-restoreCursorPosition) static | Restores the cursor position saved with [`saveCursorPosition()`](/docs/api/yii/helpers/baseconsole/index.md#method-saveCursorPosition) by sending ANSI control code RCP to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-saveCursorPosition"></span>[`saveCursorPosition()`](/docs/api/yii/helpers/baseconsole/index.md#method-saveCursorPosition) static | Saves the current cursor position by sending ANSI control code SCP to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-scrollDown"></span>[`scrollDown()`](/docs/api/yii/helpers/baseconsole/index.md#method-scrollDown) static | Scrolls whole page down by sending ANSI control code SD to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-scrollUp"></span>[`scrollUp()`](/docs/api/yii/helpers/baseconsole/index.md#method-scrollUp) static | Scrolls whole page up by sending ANSI control code SU to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-select"></span>[`select()`](/docs/api/yii/helpers/baseconsole/index.md#method-select) static | Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-showCursor"></span>[`showCursor()`](/docs/api/yii/helpers/baseconsole/index.md#method-showCursor) static | Will show a cursor again when it has been hidden by [`hideCursor()`](/docs/api/yii/helpers/baseconsole/index.md#method-hideCursor)  by sending ANSI DECTCEM code ?25h to the terminal. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-startProgress"></span>[`startProgress()`](/docs/api/yii/helpers/baseconsole/index.md#method-startProgress) static | Starts display of a progress bar on screen. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-stderr"></span>[`stderr()`](/docs/api/yii/helpers/baseconsole/index.md#method-stderr) static | Prints a string to STDERR. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-stdin"></span>[`stdin()`](/docs/api/yii/helpers/baseconsole/index.md#method-stdin) static | Gets input from STDIN and returns a string right-trimmed for EOLs. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-stdout"></span>[`stdout()`](/docs/api/yii/helpers/baseconsole/index.md#method-stdout) static | Prints a string to STDOUT. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-streamSupportsAnsiColors"></span>[`streamSupportsAnsiColors()`](/docs/api/yii/helpers/baseconsole/index.md#method-streamSupportsAnsiColors) static | Returns true if the stream supports colorization. ANSI colors are disabled if not supported by the stream. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-stripAnsiFormat"></span>[`stripAnsiFormat()`](/docs/api/yii/helpers/baseconsole/index.md#method-stripAnsiFormat) static | Strips ANSI control codes from a string. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-updateProgress"></span>[`updateProgress()`](/docs/api/yii/helpers/baseconsole/index.md#method-updateProgress) static | Updates a progress bar that has been started by [`startProgress()`](/docs/api/yii/helpers/baseconsole/index.md#method-startProgress). | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-wrapText"></span>[`wrapText()`](/docs/api/yii/helpers/baseconsole/index.md#method-wrapText) static | Word wrap text with indentation to fit the screen size. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-xtermBgColor"></span>[`xtermBgColor()`](/docs/api/yii/helpers/baseconsole/index.md#method-xtermBgColor) static | Returns the ansi format code for xterm background color. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="method-xtermFgColor"></span>[`xtermFgColor()`](/docs/api/yii/helpers/baseconsole/index.md#method-xtermFgColor) static | Returns the ansi format code for xterm foreground color. | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-FG_BLACK"></span>[`FG_BLACK`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_BLACK) | `30` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FG_RED"></span>[`FG_RED`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_RED) | `31` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FG_GREEN"></span>[`FG_GREEN`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_GREEN) | `32` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FG_YELLOW"></span>[`FG_YELLOW`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_YELLOW) | `33` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FG_BLUE"></span>[`FG_BLUE`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_BLUE) | `34` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FG_PURPLE"></span>[`FG_PURPLE`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_PURPLE) | `35` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FG_CYAN"></span>[`FG_CYAN`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_CYAN) | `36` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FG_GREY"></span>[`FG_GREY`](/docs/api/yii/helpers/baseconsole/index.md#const-FG_GREY) | `37` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_BLACK"></span>[`BG_BLACK`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_BLACK) | `40` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_RED"></span>[`BG_RED`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_RED) | `41` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_GREEN"></span>[`BG_GREEN`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_GREEN) | `42` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_YELLOW"></span>[`BG_YELLOW`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_YELLOW) | `43` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_BLUE"></span>[`BG_BLUE`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_BLUE) | `44` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_PURPLE"></span>[`BG_PURPLE`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_PURPLE) | `45` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_CYAN"></span>[`BG_CYAN`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_CYAN) | `46` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BG_GREY"></span>[`BG_GREY`](/docs/api/yii/helpers/baseconsole/index.md#const-BG_GREY) | `47` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-RESET"></span>[`RESET`](/docs/api/yii/helpers/baseconsole/index.md#const-RESET) | `0` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-NORMAL"></span>[`NORMAL`](/docs/api/yii/helpers/baseconsole/index.md#const-NORMAL) | `0` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BOLD"></span>[`BOLD`](/docs/api/yii/helpers/baseconsole/index.md#const-BOLD) | `1` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-ITALIC"></span>[`ITALIC`](/docs/api/yii/helpers/baseconsole/index.md#const-ITALIC) | `3` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-UNDERLINE"></span>[`UNDERLINE`](/docs/api/yii/helpers/baseconsole/index.md#const-UNDERLINE) | `4` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-BLINK"></span>[`BLINK`](/docs/api/yii/helpers/baseconsole/index.md#const-BLINK) | `5` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-NEGATIVE"></span>[`NEGATIVE`](/docs/api/yii/helpers/baseconsole/index.md#const-NEGATIVE) | `7` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-CONCEALED"></span>[`CONCEALED`](/docs/api/yii/helpers/baseconsole/index.md#const-CONCEALED) | `8` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-CROSSED_OUT"></span>[`CROSSED_OUT`](/docs/api/yii/helpers/baseconsole/index.md#const-CROSSED_OUT) | `9` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-FRAMED"></span>[`FRAMED`](/docs/api/yii/helpers/baseconsole/index.md#const-FRAMED) | `51` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-ENCIRCLED"></span>[`ENCIRCLED`](/docs/api/yii/helpers/baseconsole/index.md#const-ENCIRCLED) | `52` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |
| <span id="const-OVERLINED"></span>[`OVERLINED`](/docs/api/yii/helpers/baseconsole/index.md#const-OVERLINED) | `53` |  | [`BaseConsole`](/docs/api/yii/helpers/baseconsole/index.md) |