diff --git a/src/Console/Formatter/OutputFormatter.php b/src/Console/Formatter/OutputFormatter.php
index 5792bef..95f5294 100644
--- a/src/Console/Formatter/OutputFormatter.php
+++ b/src/Console/Formatter/OutputFormatter.php
@@ -2,6 +2,7 @@
namespace Accompli\Console\Formatter;
+use Psr\Log\LogLevel;
use Symfony\Component\Console\Formatter\OutputFormatter as BaseOutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
@@ -23,7 +24,14 @@ public function __construct($decorated = false, array $styles = array())
{
parent::__construct($decorated, $styles);
- $this->setStyle('info', new OutputFormatterStyle());
+ $this->setStyle(LogLevel::EMERGENCY, new OutputFormatterStyle('white', 'red'));
+ $this->setStyle(LogLevel::CRITICAL, new OutputFormatterStyle('white', 'red'));
+ $this->setStyle(LogLevel::ALERT, new OutputFormatterStyle('white', 'red'));
+ $this->setStyle(LogLevel::ERROR, new OutputFormatterStyle('white', 'red'));
+ $this->setStyle(LogLevel::WARNING, new OutputFormatterStyle('white', 'red'));
+ $this->setStyle(LogLevel::NOTICE, new OutputFormatterStyle('white', 'blue'));
+ $this->setStyle(LogLevel::INFO, new OutputFormatterStyle());
+ $this->setStyle(LogLevel::DEBUG, new OutputFormatterStyle('black', 'yellow'));
$this->setStyle('event-name', new OutputFormatterStyle('yellow'));
$this->setStyle('event-task-name', new OutputFormatterStyle('yellow'));
$this->setStyle('event-task-action-in_progress', new OutputFormatterStyle());
diff --git a/src/Console/Logger/ConsoleLogger.php b/src/Console/Logger/ConsoleLogger.php
index b4f9c99..f5908f5 100644
--- a/src/Console/Logger/ConsoleLogger.php
+++ b/src/Console/Logger/ConsoleLogger.php
@@ -35,6 +35,14 @@ class ConsoleLogger extends AbstractLogger
*/
const ANSI_CURSOR_FORWARD_FORMAT = "\e[%dC";
+ /**
+ * ANSI code to move the cursor back by the specified number of columns without changing lines.
+ * If the cursor is already in the leftmost column, this sequence is ignored.
+ *
+ * @var string
+ */
+ const ANSI_CURSOR_BACKWARD_FORMAT = "\e[%dD";
+
/**
* ANSI code to clear the screen from cursor to end of display. The cursor position is unchanged.
*
@@ -227,6 +235,9 @@ private function getMessageSectionsFromContext(array $context)
private function getTaskActionStatusSectionFromContext(array $context)
{
$actionStatusSection = '';
+ if ($this->output->isDecorated()) {
+ $actionStatusSection = sprintf(self::ANSI_CURSOR_BACKWARD_FORMAT, 1);
+ }
if (isset($context['event.task.action']) && isset($this->taskActionStatusToOutputMap[$context['event.task.action']])) {
$actionStatusSection = sprintf('[%2$s]', $context['event.task.action'], $this->taskActionStatusToOutputMap[$context['event.task.action']]);
}
diff --git a/tests/Console/Formatter/OutputFormatterTest.php b/tests/Console/Formatter/OutputFormatterTest.php
index de325dc..6fa14fe 100644
--- a/tests/Console/Formatter/OutputFormatterTest.php
+++ b/tests/Console/Formatter/OutputFormatterTest.php
@@ -4,6 +4,7 @@
use Accompli\Console\Formatter\OutputFormatter;
use PHPUnit_Framework_TestCase;
+use Psr\Log\LogLevel;
/**
* OutputFormatterTest.
@@ -14,15 +15,39 @@ class OutputFormatterTest extends PHPUnit_Framework_TestCase
{
/**
* Tests if constructing a new OutputFormatter sets the styles.
+ *
+ * @dataProvider provideTestConstruct
+ *
+ * @param string $styleName
*/
- public function testConstruct()
+ public function testConstruct($styleName)
{
$formatter = new OutputFormatter();
- $this->assertTrue($formatter->hasStyle('event-name'));
- $this->assertTrue($formatter->hasStyle('event-task-name'));
- $this->assertTrue($formatter->hasStyle('event-task-action-in_progress'));
- $this->assertTrue($formatter->hasStyle('event-task-action-failed'));
- $this->assertTrue($formatter->hasStyle('event-task-action-completed'));
+ $this->assertTrue($formatter->hasStyle($styleName));
+ }
+
+ /**
+ * Returns an array with test cases for @see testConstruct.
+ *
+ * @return array
+ */
+ public function provideTestConstruct()
+ {
+ return array(
+ array(LogLevel::EMERGENCY),
+ array(LogLevel::CRITICAL),
+ array(LogLevel::ALERT),
+ array(LogLevel::ERROR),
+ array(LogLevel::WARNING),
+ array(LogLevel::NOTICE),
+ array(LogLevel::INFO),
+ array(LogLevel::DEBUG),
+ array('event-name'),
+ array('event-task-name'),
+ array('event-task-action-in_progress'),
+ array('event-task-action-failed'),
+ array('event-task-action-completed'),
+ );
}
}
diff --git a/tests/Console/Logger/ConsoleLoggerTest.php b/tests/Console/Logger/ConsoleLoggerTest.php
index 1b54449..09bd0be 100644
--- a/tests/Console/Logger/ConsoleLoggerTest.php
+++ b/tests/Console/Logger/ConsoleLoggerTest.php
@@ -205,7 +205,7 @@ public function testLogReplaceLine()
{
$outputMock = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$outputMock->expects($this->exactly(2))->method('getVerbosity')->willReturn(OutputInterface::VERBOSITY_NORMAL);
- $outputMock->expects($this->exactly(3))->method('isDecorated')->willReturn(true);
+ $outputMock->expects($this->exactly(5))->method('isDecorated')->willReturn(true);
$outputMock->expects($this->exactly(3))
->method('getFormatter')
->willReturn(new OutputFormatter(true));
@@ -215,8 +215,8 @@ public function testLogReplaceLine()
$outputMock->expects($this->exactly(2))
->method('writeln')
->withConsecutive(
- array($this->equalTo('[accompli.test ][TestTask ] message')),
- array($this->equalTo(' message'))
+ array($this->equalTo("[accompli.test ][TestTask ] \e[1D message")),
+ array($this->equalTo(" \e[1D message"))
);
$logger = $this->getMockBuilder('Accompli\Console\Logger\ConsoleLogger')