Skip to content

Commit

Permalink
Fixes consolidation#354: Use standard 7-bit ASCII characters for prom…
Browse files Browse the repository at this point in the history
…pt in --no-ansi mode. Also disable the progress bar in --no-ansi mode, since this mode disables the cursor-moving sequences necessary for it to work right.
  • Loading branch information
greg-1-anderson committed Aug 1, 2016
1 parent 628f807 commit 45edbfd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/Common/IO.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@ protected function getInput()
return Robo::input();
}

protected function decorationCharacter($nonDecorated, $decorated)
{
if (!$this->getOutput()->isDecorated() || (strncasecmp(PHP_OS, 'WIN', 3) == 0)) {
return $nonDecorated;
}
return $decorated;
}

protected function say($text)
{
$char = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? '>' : '';
$char = $this->decorationCharacter('>', '');
$this->writeln("$char $text");
}

protected function yell($text, $length = 40, $color = 'green')
{
$char = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? ' ' : '';
$char = $this->decorationCharacter(' ', '');
$format = "$char <fg=white;bg=$color;options=bold>%s</fg=white;bg=$color;options=bold>";
$text = str_pad($text, $length, ' ', STR_PAD_BOTH);
$len = strlen($text) + 2;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/ProgressIndicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function startProgressIndicator($totalSteps, $owner)

public function autoShowProgressIndicator()
{
if (($this->autoDisplayInterval < 0) || !isset($this->progressBar)) {
if (($this->autoDisplayInterval < 0) || !isset($this->progressBar) || !$this->output->isDecorated()) {
return;
}
if ($this->autoDisplayInterval <= $this->getExecutionTime()) {
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ protected function _before()
public function testSay()
{
$this->say('Hello, world!');
$char = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? '>' : '';
$this->guy->seeInOutput($char . ' Hello, world!');
$this->guy->seeInOutput('> Hello, world!');
}

public function testAskReply()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testRunnerTryArgs()
$this->runner->execute($argv);

$expected = <<<EOT
The parameters passed are:
> The parameters passed are:
array (
0 => 'a',
1 => 'b',
Expand Down

0 comments on commit 45edbfd

Please sign in to comment.