Skip to content

Commit 1391922

Browse files
committed
Fix --no-ansi
1 parent e48287b commit 1391922

File tree

7 files changed

+154
-11
lines changed

7 files changed

+154
-11
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### master
22

3+
- Fix `--no-ansi`
4+
35
### [0.8.0](../../compare/0.7.2...0.8.0) - 2022-03-14
46

57
- Fix `StartCondition::isCanceled()` when a previous process has been canceled

src/Console/Application/Theme/DefaultTheme.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,22 @@ protected function outputProcessSummary(OutputInterface $output, Process $proces
237237
if ($process->isTerminated()) {
238238
if ($process->isSuccessful()) {
239239
if ($process->getStandardOutputVerbosity() <= $output->getVerbosity()) {
240-
$this->mergeProcessOutput($process->getErrorOutput(), $lines);
240+
$this->mergeProcessOutput($output, $process->getErrorOutput(), $lines);
241241
}
242242
if ($process->getErrorOutputVerbosity() <= $output->getVerbosity()) {
243-
$this->mergeProcessOutput($process->getOutput(), $lines);
243+
$this->mergeProcessOutput($output, $process->getOutput(), $lines);
244244
}
245245
} else {
246246
if ($process->getFailureStandardOutputVerbosity() <= $output->getVerbosity()) {
247-
$this->mergeProcessOutput($process->getOutput(), $lines);
247+
$this->mergeProcessOutput($output, $process->getOutput(), $lines);
248248
}
249249
if ($process->getFailureErrorOutputVerbosity() <= $output->getVerbosity()) {
250-
$this->mergeProcessOutput($process->getErrorOutput(), $lines);
250+
$this->mergeProcessOutput($output, $process->getErrorOutput(), $lines);
251251
}
252252
}
253253
} elseif ($process->isCanceled()) {
254254
if ($process->getCanceledOutputVerbosity() <= $output->getVerbosity()) {
255-
$this->mergeProcessOutput('Process has not beend started due to start conditions.', $lines);
255+
$this->mergeProcessOutput($output, 'Process has not beend started due to start conditions.', $lines);
256256
}
257257
} else {
258258
throw new ParallelProcessException('Unknown process state.');
@@ -267,12 +267,12 @@ protected function outputProcessSummary(OutputInterface $output, Process $proces
267267
return $this;
268268
}
269269

270-
protected function mergeProcessOutput(string $processOutput, StringArray $lines): self
270+
protected function mergeProcessOutput(OutputInterface $output, string $processOutput, StringArray $lines): self
271271
{
272272
$lines->merge(
273273
new StringArray(
274274
array_map(
275-
fn(string $line): string => ' ' . $line,
275+
fn(string $line): string => $output->isDecorated() ? ' ' . $line : ' ' . $line,
276276
explode("\n", $processOutput)
277277
)
278278
)
@@ -296,14 +296,20 @@ protected function removeLastEmptyLines(StringArray $lines): self
296296

297297
protected function outputProcessState(OutputInterface $output, Process $process, bool $isSummary = false): self
298298
{
299-
$state = $this->getProcessStateColor($process)->apply(' ' . $this->getProcessStateIcon($process) . ' ') . ' ';
299+
if ($output->isDecorated()) {
300+
$state = $this
301+
->getProcessStateColor($process)
302+
->apply(' ' . $this->getProcessStateIcon($process) . ' ') . ' ';
303+
} else {
304+
$state = $this->getProcessStateIcon($process) . ' ';
305+
}
300306

301307
$title = $process->getName();
302308
if ($output->getVerbosity() >= $this->getExecutionTimeVerbosity() && $process->isStarted()) {
303309
$title .= ' (' . $process->getExecutionTime() . 'ms)';
304310
}
305311

306-
if ($isSummary && $this->processWillHaveOutput($output, $process)) {
312+
if ($isSummary && $this->processWillHaveOutput($output, $process) && $output->isDecorated()) {
307313
$state .= $this->getProcessStateColor($process)->apply(
308314
' ' . $title . str_repeat(' ', 79 - strlen($title))
309315
);

tests/Console/Application/Theme/DefaultTheme/OutputProcessStateTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ public function testEmptyNotStarted(): void
2828
static::assertSame('', $output->getOutputed());
2929
}
3030

31+
public function testEmptyNotStartedDecorated(): void
32+
{
33+
$output = (new TestOutput())->setDecorated(true);
34+
(new DefaultTheme())->outputProcessesState(
35+
$output,
36+
new ProcessArray()
37+
);
38+
39+
static::assertSame('', $output->getOutputed());
40+
}
41+
3142
public function testNotStarted(): void
3243
{
3344
$output = new TestOutput();
@@ -36,6 +47,20 @@ public function testNotStarted(): void
3647
new ProcessArray([$this->createLsProcess()])
3748
);
3849

50+
static::assertSame(
51+
"\e[1A\e[K> ls\n",
52+
$output->getOutputed()
53+
);
54+
}
55+
56+
public function testNotStartedDecorated(): void
57+
{
58+
$output = (new TestOutput())->setDecorated(true);
59+
(new DefaultTheme())->outputProcessesState(
60+
$output,
61+
new ProcessArray([$this->createLsProcess()])
62+
);
63+
3964
static::assertSame(
4065
"\e[1A\e[K\e[37;45m > \e[39;49m ls\n",
4166
$output->getOutputed()
@@ -56,6 +81,26 @@ public function testStarted(): void
5681

5782
(new DefaultTheme())->outputProcessesState($output, $processes);
5883

84+
static::assertSame(
85+
"\e[1A\e[K\e[1A\e[K✓ ls\n✓ ls\n",
86+
$output->getOutputed()
87+
);
88+
}
89+
90+
public function testStartedDecorated(): void
91+
{
92+
$process1 = $this->createLsProcess();
93+
$process1->mustRun();
94+
95+
$process2 = $this->createLsProcess();
96+
$process2->mustRun();
97+
98+
$processes = new ProcessArray([$process1, $process2]);
99+
100+
$output = (new TestOutput())->setDecorated(true);
101+
102+
(new DefaultTheme())->outputProcessesState($output, $processes);
103+
59104
static::assertSame(
60105
"\e[1A\e[K\e[1A\e[K\e[37;42m ✓ \e[39;49m ls\n\e[37;42m ✓ \e[39;49m ls\n",
61106
$output->getOutputed()

tests/Console/Application/Theme/DefaultTheme/OutputStartTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ public function testEmptyNotStarted(): void
2828
static::assertSame('', $output->getOutputed());
2929
}
3030

31+
public function testEmptyNotStartedDecorated(): void
32+
{
33+
$output = (new TestOutput())->setDecorated(true);
34+
(new DefaultTheme())->outputStart(
35+
$output,
36+
new ProcessArray()
37+
);
38+
39+
static::assertSame('', $output->getOutputed());
40+
}
41+
3142
public function testNotStarted(): void
3243
{
3344
$output = new TestOutput();
@@ -36,6 +47,20 @@ public function testNotStarted(): void
3647
new ProcessArray([$this->createLsProcess()])
3748
);
3849

50+
static::assertSame(
51+
"> ls\n",
52+
$output->getOutputed()
53+
);
54+
}
55+
56+
public function testNotStartedDecorated(): void
57+
{
58+
$output = (new TestOutput())->setDecorated(true);
59+
(new DefaultTheme())->outputStart(
60+
$output,
61+
new ProcessArray([$this->createLsProcess()])
62+
);
63+
3964
static::assertSame(
4065
"\e[37;45m > \e[39;49m ls\n",
4166
$output->getOutputed()
@@ -56,6 +81,26 @@ public function testStarted(): void
5681

5782
(new DefaultTheme())->outputStart($output, $processes);
5883

84+
static::assertSame(
85+
"✓ ls\n✓ ls\n",
86+
$output->getOutputed()
87+
);
88+
}
89+
90+
public function testStartedDecorated(): void
91+
{
92+
$process1 = $this->createLsProcess();
93+
$process1->mustRun();
94+
95+
$process2 = $this->createLsProcess();
96+
$process2->mustRun();
97+
98+
$processes = new ProcessArray([$process1, $process2]);
99+
100+
$output = (new TestOutput())->setDecorated(true);
101+
102+
(new DefaultTheme())->outputStart($output, $processes);
103+
59104
static::assertSame(
60105
"\e[37;42m ✓ \e[39;49m ls\n\e[37;42m ✓ \e[39;49m ls\n",
61106
$output->getOutputed()

tests/Console/Application/Theme/DefaultTheme/OutputSummaryTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ public function testEmptyNotStarted(): void
2929
static::assertSame('', $output->getOutputed());
3030
}
3131

32+
public function testEmptyNotStartedDecorated(): void
33+
{
34+
$output = (new TestOutput())->setDecorated(true);
35+
(new DefaultTheme())->outputSummary(
36+
$output,
37+
new ProcessArray()
38+
);
39+
40+
static::assertSame('', $output->getOutputed());
41+
}
42+
3243
public function testNotStarted(): void
3344
{
3445
$this->expectException(ParallelProcessException::class);
@@ -41,6 +52,18 @@ public function testNotStarted(): void
4152
);
4253
}
4354

55+
public function testNotStartedDecorated(): void
56+
{
57+
$this->expectException(ParallelProcessException::class);
58+
$this->expectExceptionMessage('Unknown process state.');
59+
$this->expectExceptionCode(0);
60+
61+
(new DefaultTheme())->outputSummary(
62+
(new TestOutput())->setDecorated(true),
63+
new ProcessArray([$this->createLsProcess()])
64+
);
65+
}
66+
4467
public function testStarted(): void
4568
{
4669
$process1 = $this->createLsProcess();
@@ -55,6 +78,26 @@ public function testStarted(): void
5578

5679
(new DefaultTheme())->outputSummary($output, $processes);
5780

81+
static::assertSame(
82+
"\e[1A\e[K\e[1A\e[K✓ ls\n✓ ls\n",
83+
$output->getOutputed()
84+
);
85+
}
86+
87+
public function testStartedDecorated(): void
88+
{
89+
$process1 = $this->createLsProcess();
90+
$process1->mustRun();
91+
92+
$process2 = $this->createLsProcess();
93+
$process2->mustRun();
94+
95+
$processes = new ProcessArray([$process1, $process2]);
96+
97+
$output = (new TestOutput())->setDecorated(true);
98+
99+
(new DefaultTheme())->outputSummary($output, $processes);
100+
58101
static::assertSame(
59102
"\e[1A\e[K\e[1A\e[K\e[37;42m ✓ \e[39;49m ls\n\e[37;42m ✓ \e[39;49m ls\n",
60103
$output->getOutputed()

tests/Console/Output/TestOutput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ public function isDebug(): bool
8080
return $this->getVerbosity() === static::VERBOSITY_DEBUG;
8181
}
8282

83-
public function setDecorated(bool $decorated): void
83+
public function setDecorated(bool $decorated): self
8484
{
8585
$this->decorated = $decorated;
86+
87+
return $this;
8688
}
8789

8890
public function isDecorated(): bool

tests/Processes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
$process1 = new Process(['pwd'], $rootDir);
2424

25-
$process2 = new Process(['pwd'], $rootDir);
25+
$process2 = new Process(['commandNotFound'], $rootDir);
2626
$process2->getStartCondition()->addProcessSuccessful($process1);
2727

2828
$process3 = new Process(['pwd'], $rootDir);

0 commit comments

Comments
 (0)