Class for handling console output.
The ezcConsoleOutput class provides an interface to output text to the console. It deals with formating text in different ways and offers some comfortable options to deal with console text output.
For a list of valid colors, style attributes and background colors, please refer to ezcConsoleOutputFormat.
ATTENTION: Windows operating systems do not support styling of text on the console. Therefore no styling sequences are generated on any version of this operating system.
Source for this file: /ConsoleTools/src/output.php
Version: | //autogen// |
TARGET_OUTPUT
= "php://output"
|
Target to print to standard out, with output buffering possibility. |
TARGET_STDERR
= "php://stderr"
|
Target to print to standard error. |
TARGET_STDOUT
= "php://stdout"
|
Target to print to standard out. |
ezcConsoleOutputFormats | read/write |
$formats
Contains the output formats. |
ezcConsoleOutputOptions | read/write |
$options
Contains the options for this class. |
protected static array(string=>int) |
$bgcolor
Stores the mapping of bgcolor names to their escape sequence values. |
protected static array(string=>int) |
$color
Stores the mapping of color names to their escape sequence values. |
protected static array(string=>int) |
$style
Stores the mapping of styles names to their escape sequence values. |
protected bool |
$positionStored
= false
Whether a position has been stored before, using the storePos() method. |
protected array(string=>mixed) |
$properties
Container to hold the properties |
public static bool |
isValidFormatCode(
$type
, $key
)
Returns if a format code is valid for the specific formating option. |
public ezcConsoleOutput |
__construct(
[ $formats
= null] , [ $options
= array()] )
Create a new console output handler. |
protected string |
buildSequence(
[ $format
= 'default'] )
Returns the escape sequence for a specific format. |
public string |
formatText(
$text
, [ $format
= 'default'] )
Returns a formated version of the text. |
protected int |
getFormatCode(
$type
, $key
)
Returns the code for a given formating option of a given type. |
public ezcConsoleOutputOptions |
getOptions(
)
Returns the current options. |
public void |
outputLine(
[ $text
= ''] , [ $format
= 'default'] , [ $verbosityLevel
= 1] )
Print text to the console and automatically append a line break. |
public void |
outputText(
$text
, [ $format
= 'default'] , [ $verbosityLevel
= 1] )
Print text to the console. |
public void |
restorePos(
)
Restores a cursor position. |
public void |
setOptions(
$options
)
Set new options. |
public void |
storePos(
)
Stores the current cursor position. |
public void |
toPos(
[ $column
= 1] )
Move the cursor to a specific column of the current line. |
Returns if a format code is valid for the specific formating option.
This method determines if a given code is valid for a specific formatting option ('color', 'bgcolor' or 'style').
Name | Type | Description |
---|---|---|
$type |
string | Formating type. |
$key |
string | Format option name. |
Create a new console output handler.
Name | Type | Description |
---|---|---|
$formats |
ezcConsoleOutputFormats | Formats to be used for output. |
$options |
array(string=>string) | Options to set. |
Returns the escape sequence for a specific format.
Returns the default format escape sequence, if the requested format does not exist.
Name | Type | Description |
---|---|---|
$format |
string | Name of the format. |
Returns a formated version of the text.
If $format parameter is omitted, the default style is chosen. The format must be a valid registered format definition. For information on the formats, see ezcConsoleOutput::$formats.
Name | Type | Description |
---|---|---|
$text |
string | Text to apply style to. |
$format |
string | Format chosen to be applied. |
Returns the code for a given formating option of a given type.
$type is the type of formating ('color', 'bgcolor' or 'style'), $key the name of the format to lookup. Returns the numeric code for the requested format or 0 if format or type do not exist.
Name | Type | Description |
---|---|---|
$type |
string | Formatting type. |
$key |
string | Format option name. |
Returns the current options.
Returns the options currently set for this output handler.
Print text to the console and automatically append a line break.
This method acts similar to ezcConsoleOutput::outputText(), in fact it even uses it. The difference is, that outputLine() automatically appends a manual line break to the printed text. Besides that, you can leave out the $text parameter of outputLine() to only print a line break.
The $format parameter defines the name of a format. Formats are defined through the $formats proprty, which contains format definitions in form of ezcConsoleOutputFormat objects. The format influences the outer appearance of a message (e.g. color) as well as the target the message is printed to (e.g. STDERR).
Name | Type | Description |
---|---|---|
$text |
string | The text to print. |
$format |
string | Format chosen for printing. |
$verbosityLevel |
int | On which verbose level to output this message. |
Print text to the console.
Output a string to the console. If $format parameter is omitted, the default style is chosen. Style can either be a special style ezcConsoleOutput::$options, a style name ezcConsoleOutput::$formats or 'default' to print with the default styling.
The $format parameter defines the name of a format. Formats are defined through the $formats proprty, which contains format definitions in form of ezcConsoleOutputFormat objects. The format influences the outer appearance of a message (e.g. color) as well as the target the message is printed to (e.g. STDERR).
Name | Type | Description |
---|---|---|
$text |
string | The text to print. |
$format |
string | Format chosen for printing. |
$verbosityLevel |
int | On which verbose level to output this message. |
Type | Description |
---|---|
ezcConsoleInvalidOutputTargetException |
If the given target (ezcConsoleOutputFormat) could not be opened for writing or writing failed. |
Restores a cursor position.
Restores the cursor position last saved using ezcConsoleOutput::storePos().
Type | Description |
---|---|
ezcConsoleNoPositionStoredException |
If no position is saved. |
Set new options.
This method allows you to change the options of an output handler.
Name | Type | Description |
---|---|---|
$options |
ezcConsoleOutputOptions | The options to set. |
Type | Description |
---|---|
ezcBaseSettingNotFoundException |
If you tried to set a non-existent option value. |
ezcBaseSettingValueException |
If the value is not valid for the desired option. |
ezcBaseValueException |
If you submit neither an array nor an instance of ezcConsoleOutputOptions. |
Stores the current cursor position.
Saves the current cursor position to return to it using ezcConsoleOutput::restorePos(). Multiple calls to this method will override each other. Only the last position is saved.
Move the cursor to a specific column of the current line.
Moves the cursor to a specific column index of the current line (default is 1).
Name | Type | Description |
---|---|---|
$column |
int | Column to jump to. |