## 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.

1. // Create the output handler
2. $out=new ezcConsoleOutput ();
4. // Set the verbosity to level 10
5. $out->options->verbosityLevel=10;
6. // Enable auto wrapping of lines after 40 characters
7. $out->options->autobreak=40;
9. // Set the color of the default output format to green
10. $out->formats->default-> color ='green';
12. // Set the color of the output format named 'success' to white
13. $out->formats->success-> color ='white';
14. // Set the style of the output format named 'success' to bold
15. $out->formats->success-> style =array('bold');
17. // Set the color of the output format named 'failure' to red
18. $out->formats->failure-> color ='red';
19. // Set the style of the output format named 'failure' to bold
20. $out->formats->failure-> style =array('bold');
21. // Set the background color of the output format named 'failure' to blue
22. $out->formats->failure-> bgcolor ='blue';
24. // Output text with default format
25. $out-> outputText ('This is default text ');
26. // Output text with format 'success'
27. $out-> outputText ('including success message','success');
28. // Some more output with default output.
29. $out-> outputText ("and a manual linebreak.\n");
31. // Manipulate the later output
32. $out->formats->success-> color ='green';
33. $out->formats->default-> color ='blue';
35. // This is visible, since we set verbosityLevel to 10, and printed in default format (now blue)
36. $out-> outputText ("Some verbose output.\n",null,10);
37. // This is not visible, since we set verbosityLevel to 10
38. $out-> outputText ("Some more verbose output.\n",null,20);
39. // This is visible, since we set verbosityLevel to 10, and printed in format 'failure'
40. $out-> outputText ("And some not so verbose, failure output.\n",'failure',5);

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

static bool isValidFormatCode( string $type , string $key )

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

ezcConsoleOutput __construct( [ezcConsoleOutputFormats $formats = null] , [ $options = array()] )

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

string buildSequence( [string $format = 'default'] )

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

string formatText( string $text , [string $format = 'default'] )

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

int getFormatCode( string $type , string $key )

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

ezcConsoleOutputOptions getOptions( )

Returns the current options.

Returns the options currently set for this output handler.

#### outputLine

void outputLine( [string $text = ''] , [string $format = 'default'] , [int $verbosityLevel = 1] )

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

void outputText( string $text , [string $format = 'default'] , [int $verbosityLevel = 1] )

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

void restorePos( )

Restores a cursor position.

Restores the cursor position last saved using ezcConsoleOutput::storePos().

##### Exceptions:

Type | Description
--- | ---
`ezcConsoleNoPositionStoredException` | If no position is saved.

#### setOptions

void setOptions( ezcConsoleOutputOptions $options )

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

void 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

void toPos( [int $column = 1] )

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.

Documentation generated by phpDocumentor 1.4.3