[Console] Added getters to output formatter style (and its interface).
This commit is contained in:
parent
48e6b49201
commit
93ffe54886
@ -102,6 +102,22 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
$this->foreground = static::$availableForegroundColors[$color];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets style foreground color.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getForeground()
|
||||
{
|
||||
if (null === $this->foreground) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$names = array_flip(static::$availableForegroundColors);
|
||||
|
||||
return $names[$this->foreground];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets style background color.
|
||||
*
|
||||
@ -130,6 +146,22 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
$this->background = static::$availableBackgroundColors[$color];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets style background color.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBackground()
|
||||
{
|
||||
if (null === $this->background) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$names = array_flip(static::$availableBackgroundColors);
|
||||
|
||||
return $names[$this->background];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets some specific style option.
|
||||
*
|
||||
@ -192,6 +224,23 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets specific style options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
$names = array_flip(static::$availableOptions);
|
||||
$options = array();
|
||||
|
||||
foreach ($this->options as $code) {
|
||||
$options[] = $names[$code];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the style to a given text.
|
||||
*
|
||||
@ -200,6 +249,16 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
* @return string
|
||||
*/
|
||||
public function apply($text)
|
||||
{
|
||||
return sprintf("%s%s\033[0m", $this->getTerminalSequence(), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets terminal colorization sequence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTerminalSequence()
|
||||
{
|
||||
$codes = array();
|
||||
|
||||
@ -216,6 +275,6 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
$codes = array(0);
|
||||
}
|
||||
|
||||
return sprintf("\033[%sm%s\033[0m", implode(';', $codes), $text);
|
||||
return sprintf("\033[%sm", implode(';', $codes));
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,13 @@ interface OutputFormatterStyleInterface
|
||||
*/
|
||||
function setForeground($color = null);
|
||||
|
||||
/**
|
||||
* Gets style foreground color.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function getForeground();
|
||||
|
||||
/**
|
||||
* Sets style background color.
|
||||
*
|
||||
@ -38,6 +45,13 @@ interface OutputFormatterStyleInterface
|
||||
*/
|
||||
function setBackground($color = null);
|
||||
|
||||
/**
|
||||
* Gets style background color.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function getBackground();
|
||||
|
||||
/**
|
||||
* Sets some specific style option.
|
||||
*
|
||||
@ -61,6 +75,20 @@ interface OutputFormatterStyleInterface
|
||||
*/
|
||||
function setOptions(array $options);
|
||||
|
||||
/**
|
||||
* Gets specific style options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getOptions();
|
||||
|
||||
/**
|
||||
* Gets terminal colorization sequence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getTerminalSequence();
|
||||
|
||||
/**
|
||||
* Applies the style to a given text.
|
||||
*
|
||||
|
Reference in New Issue
Block a user