diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php index f0bbd383727e2..b5457ef8b8e20 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -21,31 +21,31 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface { private static $availableForegroundColors = array( - 'black' => 30, - 'red' => 31, - 'green' => 32, - 'yellow' => 33, - 'blue' => 34, - 'magenta' => 35, - 'cyan' => 36, - 'white' => 37 + 'black' => array('set' => 30, 'unset' => 39), + 'red' => array('set' => 31, 'unset' => 39), + 'green' => array('set' => 32, 'unset' => 39), + 'yellow' => array('set' => 33, 'unset' => 39), + 'blue' => array('set' => 34, 'unset' => 39), + 'magenta' => array('set' => 35, 'unset' => 39), + 'cyan' => array('set' => 36, 'unset' => 39), + 'white' => array('set' => 37, 'unset' => 39) ); private static $availableBackgroundColors = array( - 'black' => 40, - 'red' => 41, - 'green' => 42, - 'yellow' => 43, - 'blue' => 44, - 'magenta' => 45, - 'cyan' => 46, - 'white' => 47 + 'black' => array('set' => 40, 'unset' => 49), + 'red' => array('set' => 41, 'unset' => 49), + 'green' => array('set' => 42, 'unset' => 49), + 'yellow' => array('set' => 43, 'unset' => 49), + 'blue' => array('set' => 44, 'unset' => 49), + 'magenta' => array('set' => 45, 'unset' => 49), + 'cyan' => array('set' => 46, 'unset' => 49), + 'white' => array('set' => 47, 'unset' => 49) ); private static $availableOptions = array( - 'bold' => 1, - 'underscore' => 4, - 'blink' => 5, - 'reverse' => 7, - 'conceal' => 8 + 'bold' => array('set' => 1, 'unset' => 21), + 'underscore' => array('set' => 4, 'unset' => 24), + 'blink' => array('set' => 5, 'unset' => 25), + 'reverse' => array('set' => 7, 'unset' => 27), + 'conceal' => array('set' => 8, 'unset' => 28) ); private $foreground; @@ -201,22 +201,28 @@ public function setOptions(array $options) */ public function apply($text) { - $codes = array(); + $setCodes = array(); + $unsetCode = array(); if (null !== $this->foreground) { - $codes[] = $this->foreground; + $setCodes[] = $this->foreground['set']; + $unsetCodes[] = $this->foreground['unset']; } if (null !== $this->background) { - $codes[] = $this->background; + $setCodes[] = $this->background['set']; + $unsetCodes[] = $this->background['unset']; } if (count($this->options)) { - $codes = array_merge($codes, $this->options); + foreach ($this->options as $option) { + $setCodes[] = $option['set']; + $unsetCodes[] = $option['unset']; + } } - if (0 === count($codes)) { + if (0 === count($setCodes)) { return $text; } - return sprintf("\033[%sm%s\033[0m", implode(';', $codes), $text); + return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes)); } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt index 4bdcd772caae2..b44d50b0ed04f 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt @@ -1,27 +1,27 @@ -[37;41m [0m -[37;41m [Exception] [0m -[37;41m Third exception [0m[34;41mcomment[0m[37;41m [0m -[37;41m [0m +[37;41m [39;49m +[37;41m [Exception] [39;49m +[37;41m Third exception [39;49m[34;41mcomment[39;49m[37;41m [39;49m +[37;41m [39;49m -[37;41m [0m -[37;41m [Exception] [0m -[37;41m Second exception [0m[33mcomment[0m[37;41m [0m -[37;41m [0m +[37;41m [39;49m +[37;41m [Exception] [39;49m +[37;41m Second exception [39;49m[33mcomment[39m[37;41m [39;49m +[37;41m [39;49m -[37;41m [0m -[37;41m [Exception] [0m -[37;41m First exception [0m[37;41m
[0m[37;41mthis is html[0m[37;41m
[0m[37;41m [0m -[37;41m [0m +[37;41m [39;49m +[37;41m [Exception] [39;49m +[37;41m First exception [39;49m[37;41m[39;49m[37;41mthis is html[39;49m[37;41m
[39;49m[37;41m [39;49m +[37;41m [39;49m -[32mfoo3:bar[0m +[32mfoo3:bar[39m diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php index 6890a9b839e88..c9e21fdce0dc2 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php @@ -18,13 +18,13 @@ class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase public function testConstructor() { $style = new OutputFormatterStyle('green', 'black', array('bold', 'underscore')); - $this->assertEquals("\033[32;40;1;4mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[32;40;1;4mfoo\033[39;49;21;24m", $style->apply('foo')); $style = new OutputFormatterStyle('red', null, array('blink')); - $this->assertEquals("\033[31;5mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[31;5mfoo\033[39;25m", $style->apply('foo')); $style = new OutputFormatterStyle(null, 'white'); - $this->assertEquals("\033[47mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[47mfoo\033[49m", $style->apply('foo')); } public function testForeground() @@ -32,10 +32,10 @@ public function testForeground() $style = new OutputFormatterStyle(); $style->setForeground('black'); - $this->assertEquals("\033[30mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[30mfoo\033[39m", $style->apply('foo')); $style->setForeground('blue'); - $this->assertEquals("\033[34mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[34mfoo\033[39m", $style->apply('foo')); $this->setExpectedException('InvalidArgumentException'); $style->setForeground('undefined-color'); @@ -46,10 +46,10 @@ public function testBackground() $style = new OutputFormatterStyle(); $style->setBackground('black'); - $this->assertEquals("\033[40mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[40mfoo\033[49m", $style->apply('foo')); $style->setBackground('yellow'); - $this->assertEquals("\033[43mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[43mfoo\033[49m", $style->apply('foo')); $this->setExpectedException('InvalidArgumentException'); $style->setBackground('undefined-color'); @@ -60,19 +60,19 @@ public function testOptions() $style = new OutputFormatterStyle(); $style->setOptions(array('reverse', 'conceal')); - $this->assertEquals("\033[7;8mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[7;8mfoo\033[27;28m", $style->apply('foo')); $style->setOption('bold'); - $this->assertEquals("\033[7;8;1mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[7;8;1mfoo\033[27;28;21m", $style->apply('foo')); $style->unsetOption('reverse'); - $this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[8;1mfoo\033[28;21m", $style->apply('foo')); $style->setOption('bold'); - $this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[8;1mfoo\033[28;21m", $style->apply('foo')); $style->setOptions(array('bold')); - $this->assertEquals("\033[1mfoo\033[0m", $style->apply('foo')); + $this->assertEquals("\033[1mfoo\033[21m", $style->apply('foo')); try { $style->setOption('foo'); diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index c8f0b987afd14..c36c08ba5ae3c 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -31,7 +31,7 @@ public function testLGCharEscaping() $this->assertEquals("\\\033[0m\033[32msingle-char tag\033[0m\033[32m
\033[0m", $formatter->format('single-char tag
\033[39m\033[32msingle-char tag\033[39m\033[32m
\033[39m", $formatter->format('single-char tag