Apache Zeta Components Manual :: Docs For Class ezcConsoleOutput
ConsoleTools::ezcConsoleOutput
Class ezcConsoleOutput
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.
- // Create the output handler
- // Set the verbosity to level 10
- $out->options->verbosityLevel = 10;
- // Enable auto wrapping of lines after 40 characters
- $out->options->autobreak = 40;
- // Set the color of the default output format to green
- // Set the color of the output format named 'success' to white
- // Set the style of the output format named 'success' to bold
- // Set the color of the output format named 'failure' to red
- // Set the style of the output format named 'failure' to bold
- // Set the background color of the output format named 'failure' to blue
- // Output text with default format
- // Output text with format 'success'
- // Some more output with default output.
- // Manipulate the later output
- // This is visible, since we set verbosityLevel to 10, and printed in default format (now blue)
- // This is not visible, since we set verbosityLevel to 10
- // This is visible, since we set verbosityLevel to 10, and printed in format 'failure'
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// |
Constants
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. |
Properties
ezcConsoleOutputFormats | read/write |
$formats
Contains the output formats. |
ezcConsoleOutputOptions | read/write |
$options
Contains the options for this class. |
Member Variables
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 |
Method Summary
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. |
Methods
isValidFormatCode
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').
Parameters:
Name | Type | Description |
---|---|---|
$type |
string | Formating type. |
$key |
string | Format option name. |
__construct
Create a new console output handler.
Parameters:
Name | Type | Description |
---|---|---|
$formats |
ezcConsoleOutputFormats | Formats to be used for output. |
$options |
array(string=>string) | Options to set. |
buildSequence
Returns the escape sequence for a specific format.
Returns the default format escape sequence, if the requested format does not exist.
Parameters:
Name | Type | Description |
---|---|---|
$format |
string | Name of the format. |
formatText
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.
Parameters:
Name | Type | Description |
---|---|---|
$text |
string | Text to apply style to. |
$format |
string | Format chosen to be applied. |
getFormatCode
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.
Parameters:
Name | Type | Description |
---|---|---|
$type |
string | Formatting type. |
$key |
string | Format option name. |
getOptions
Returns the current options.
Returns the options currently set for this output handler.
outputLine
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).
Parameters:
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. |
outputText
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).
Parameters:
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. |
Exceptions:
Type | Description |
---|---|
ezcConsoleInvalidOutputTargetException |
If the given target (ezcConsoleOutputFormat) could not be opened for writing or writing failed. |
restorePos
Restores a cursor position.
Restores the cursor position last saved using ezcConsoleOutput::storePos().
Exceptions:
Type | Description |
---|---|
ezcConsoleNoPositionStoredException |
If no position is saved. |
setOptions
Set new options.
This method allows you to change the options of an output handler.
Parameters:
Name | Type | Description |
---|---|---|
$options |
ezcConsoleOutputOptions | The options to set. |
Exceptions:
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. |
storePos
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.
toPos
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).
Parameters:
Name | Type | Description |
---|---|---|
$column |
int | Column to jump to. |