Doctrine 1.2.4
Doctrine_Cli_AnsiColorFormatter Class Reference

Inherits Doctrine_Cli_Formatter.

Public Member Functions

 excerpt ($text, $size=null)
 
 format ($text= '', $parameters=array(), $stream=STDOUT)
 
 formatSection ($section, $text, $size=null)
 
 setMaxLineSize ($size)
 
 setStyle ($name, $options=array())
 
 supportsColors ($stream)
 

Detailed Description

Definition at line 43 of file AnsiColorFormatter.php.

Member Function Documentation

Doctrine_Cli_AnsiColorFormatter::excerpt (   $text,
  $size = null 
)

Truncates a line.

Parameters
stringThe text
integerThe maximum size of the returned string (65 by default)
Returns
string The truncated string

Definition at line 129 of file AnsiColorFormatter.php.

{
if ( ! $size) {
$size = $this->size;
}
if (strlen($text) < $size) {
return $text;
}
$subsize = floor(($size - 3) / 2);
return substr($text, 0, $subsize) . $this->format('...', 'INFO').substr($text, -$subsize);
}
Doctrine_Cli_AnsiColorFormatter::format (   $text = '',
  $parameters = array(),
  $stream = STDOUT 
)

Formats a text according to the given style or parameters.

Parameters
stringThe test to style
mixedAn array of options or a style name
Returns
string The styled text

Definition at line 75 of file AnsiColorFormatter.php.

{
if ( ! $this->supportsColors($stream)) {
return $text;
}
if ( ! is_array($parameters) && 'NONE' == $parameters) {
return $text;
}
if ( ! is_array($parameters) && isset($this->_styles[$parameters])) {
$parameters = $this->_styles[$parameters];
}
$codes = array();
if (isset($parameters['fg'])) {
$codes[] = $this->_foreground[$parameters['fg']];
}
if (isset($parameters['bg'])) {
$codes[] = $this->_background[$parameters['bg']];
}
foreach ($this->_options as $option => $value) {
if (isset($parameters[$option]) && $parameters[$option]) {
$codes[] = $value;
}
}
return "\033[".implode(';', $codes).'m'.$text."\033[0m";
}
Doctrine_Cli_AnsiColorFormatter::formatSection (   $section,
  $text,
  $size = null 
)

Formats a message within a section.

Parameters
stringThe section name
stringThe text message
integerThe maximum size allowed for a line (65 by default)

Definition at line 114 of file AnsiColorFormatter.php.

{
$width = 9 + strlen($this->format('', 'INFO'));
return sprintf(">> %-${width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size));
}
Doctrine_Cli_Formatter::setMaxLineSize (   $size)
inherited

Sets the maximum line size.

Parameters
integerThe maximum line size for a message

Definition at line 112 of file Formatter.php.

{
$this->_size = $size;
}
Doctrine_Cli_AnsiColorFormatter::setStyle (   $name,
  $options = array() 
)

Sets a new style.

Parameters
stringThe style name
arrayAn array of options

Definition at line 62 of file AnsiColorFormatter.php.

{
$this->_styles[$name] = $options;
}
Doctrine_Cli_AnsiColorFormatter::supportsColors (   $stream)

Returns true if the stream supports colorization.

Colorization is disabled if not supported by the stream:

  • windows
  • non tty consoles
Parameters
mixedA stream
Returns
Boolean true if the stream supports colorization, false otherwise

Definition at line 156 of file AnsiColorFormatter.php.

{
return DIRECTORY_SEPARATOR != '\\' && function_exists('posix_isatty') && @posix_isatty($stream);
}

The documentation for this class was generated from the following file: