Skip to content

Commit 817e21e

Browse files
committed
Rework DefaultTheme, fix output verbosity
1 parent 27614ab commit 817e21e

File tree

8 files changed

+92
-37
lines changed

8 files changed

+92
-37
lines changed

changelog.md

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

3+
- [#130](https://github.com/steevanb/php-parallel-processes/issues/130) Rework execution time output in `DefaultTheme`
4+
- [#236](https://github.com/steevanb/php-parallel-processes/issues/236) Rework verbosity for `DefaultTheme`
5+
- [#237](https://github.com/steevanb/php-parallel-processes/issues/237) Fix `getStandardOutputVerbosity()` and `getErrorOutputVerbosity()`
6+
37
### [0.12.0](../../compare/0.11.0...0.12.0) - 2023-06-01
48

59
- [#227](https://github.com/steevanb/php-parallel-processes/issues/227) Fix TearDownProcess who never start in some cases

src/Console/Application/Theme/DefaultTheme.php

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class DefaultTheme implements ThemeInterface
4141

4242
protected int $executionTimeVerbosity = OutputInterface::VERBOSITY_VERBOSE;
4343

44+
protected int $statusLabelVerbosity = OutputInterface::VERBOSITY_VERBOSE;
45+
4446
public function __construct()
4547
{
4648
$this
@@ -51,9 +53,9 @@ public function __construct()
5153
->setStateErrorColor(new Color('white', 'red'));
5254
}
5355

54-
public function setStateReadyColor(Color $stateReadyColor): static
56+
public function setStateReadyColor(Color $color): static
5557
{
56-
$this->stateReadyColor = $stateReadyColor;
58+
$this->stateReadyColor = $color;
5759

5860
return $this;
5961
}
@@ -63,9 +65,9 @@ public function getStateReadyColor(): Color
6365
return $this->stateReadyColor;
6466
}
6567

66-
public function setStateReadyIcon(string $stateReadyIcon): static
68+
public function setStateReadyIcon(string $icon): static
6769
{
68-
$this->stateReadyIcon = $stateReadyIcon;
70+
$this->stateReadyIcon = $icon;
6971

7072
return $this;
7173
}
@@ -75,9 +77,9 @@ public function getStateReadyIcon(): string
7577
return $this->stateReadyIcon;
7678
}
7779

78-
public function setStateCanceledColor(Color $stateCanceledColor): static
80+
public function setStateCanceledColor(Color $color): static
7981
{
80-
$this->stateCanceledColor = $stateCanceledColor;
82+
$this->stateCanceledColor = $color;
8183

8284
return $this;
8385
}
@@ -87,9 +89,9 @@ public function getStateCanceledColor(): Color
8789
return $this->stateCanceledColor;
8890
}
8991

90-
public function setStateCanceledIcon(string $stateCanceledIcon): static
92+
public function setStateCanceledIcon(string $icon): static
9193
{
92-
$this->stateCanceledIcon = $stateCanceledIcon;
94+
$this->stateCanceledIcon = $icon;
9395

9496
return $this;
9597
}
@@ -99,9 +101,9 @@ public function getStateCanceledIcon(): string
99101
return $this->stateCanceledIcon;
100102
}
101103

102-
public function setStateRunningColor(Color $stateRunningColor): static
104+
public function setStateRunningColor(Color $color): static
103105
{
104-
$this->stateRunningColor = $stateRunningColor;
106+
$this->stateRunningColor = $color;
105107

106108
return $this;
107109
}
@@ -111,9 +113,9 @@ public function getStateRunningColor(): Color
111113
return $this->stateRunningColor;
112114
}
113115

114-
public function setStateRunningIcon(string $stateRunningIcon): static
116+
public function setStateRunningIcon(string $icon): static
115117
{
116-
$this->stateRunningIcon = $stateRunningIcon;
118+
$this->stateRunningIcon = $icon;
117119

118120
return $this;
119121
}
@@ -123,9 +125,9 @@ public function getStateRunningIcon(): string
123125
return $this->stateRunningIcon;
124126
}
125127

126-
public function setStateSuccessfulColor(Color $stateSuccessfulColor): static
128+
public function setStateSuccessfulColor(Color $color): static
127129
{
128-
$this->stateSuccessfulColor = $stateSuccessfulColor;
130+
$this->stateSuccessfulColor = $color;
129131

130132
return $this;
131133
}
@@ -135,9 +137,9 @@ public function getStateSuccessfulColor(): Color
135137
return $this->stateSuccessfulColor;
136138
}
137139

138-
public function setStateSuccessfulIcon(string $stateSuccessfulIcon): static
140+
public function setStateSuccessfulIcon(string $icon): static
139141
{
140-
$this->stateSuccessfulIcon = $stateSuccessfulIcon;
142+
$this->stateSuccessfulIcon = $icon;
141143

142144
return $this;
143145
}
@@ -147,9 +149,9 @@ public function getStateSuccessfulIcon(): string
147149
return $this->stateSuccessfulIcon;
148150
}
149151

150-
public function setStateErrorColor(Color $stateErrorColor): static
152+
public function setStateErrorColor(Color $color): static
151153
{
152-
$this->stateErrorColor = $stateErrorColor;
154+
$this->stateErrorColor = $color;
153155

154156
return $this;
155157
}
@@ -159,9 +161,9 @@ public function getStateErrorColor(): Color
159161
return $this->stateErrorColor;
160162
}
161163

162-
public function setStateErrorIcon(string $stateErrorIcon): static
164+
public function setStateErrorIcon(string $icon): static
163165
{
164-
$this->stateErrorIcon = $stateErrorIcon;
166+
$this->stateErrorIcon = $icon;
165167

166168
return $this;
167169
}
@@ -171,9 +173,9 @@ public function getStateErrorIcon(): string
171173
return $this->stateErrorIcon;
172174
}
173175

174-
public function setExecutionTimeVerbosity(int $executionTimeVerbosity): static
176+
public function setExecutionTimeVerbosity(int $verbosity): static
175177
{
176-
$this->executionTimeVerbosity = $executionTimeVerbosity;
178+
$this->executionTimeVerbosity = $verbosity;
177179

178180
return $this;
179181
}
@@ -183,6 +185,18 @@ public function getExecutionTimeVerbosity(): int
183185
return $this->executionTimeVerbosity;
184186
}
185187

188+
public function setStatusLabelVerbosity(int $verbosity): static
189+
{
190+
$this->statusLabelVerbosity = $verbosity;
191+
192+
return $this;
193+
}
194+
195+
public function getStatusLabelVerbosity(): int
196+
{
197+
return $this->statusLabelVerbosity;
198+
}
199+
186200
public function resetOutput(OutputInterface $output, ProcessInterfaceCollection $processes): static
187201
{
188202
for ($reset = 0; $reset < $processes->count(); $reset++) {
@@ -241,15 +255,15 @@ protected function outputProcessSummary(OutputInterface $output, ProcessInterfac
241255
$this->mergeProcessOutput(
242256
$output,
243257
$process->getOutputSummaryPrefix(),
244-
$process->getErrorOutput(),
258+
$process->getOutput(),
245259
$lines
246260
);
247261
}
248262
if ($process->getErrorOutputVerbosity() <= $output->getVerbosity()) {
249263
$this->mergeProcessOutput(
250264
$output,
251265
$process->getOutputSummaryPrefix(),
252-
$process->getOutput(),
266+
$process->getErrorOutput(),
253267
$lines
254268
);
255269
}
@@ -337,8 +351,13 @@ protected function outputProcessState(
337351
}
338352

339353
$title = $process->getName();
354+
355+
if ($output->getVerbosity() >= $this->getStatusLabelVerbosity()) {
356+
$title .= ' - ' . $this->getStatusLabel($process);
357+
}
358+
340359
if ($output->getVerbosity() >= $this->getExecutionTimeVerbosity() && $process->isStarted()) {
341-
$title .= ' (' . $process->getExecutionTime() . 'ms)';
360+
$title .= ' - ' . $this->getExecutionTimeLabel($process->getExecutionTime());
342361
}
343362

344363
if ($isSummary && $this->processWillHaveOutput($output, $process) && $output->isDecorated()) {
@@ -415,6 +434,38 @@ protected function getProcessStateIcon(ProcessInterface $process): string
415434
return $return;
416435
}
417436

437+
protected function getStatusLabel(ProcessInterface $process): string
438+
{
439+
if ($process->isCanceled()) {
440+
$return = 'Canceled';
441+
} elseif ($process->getStatus() === Process::STATUS_READY) {
442+
$return = 'Waiting';
443+
} elseif ($process->isRunning()) {
444+
$return = 'Running';
445+
} elseif ($process->isTerminated() && $process->isSuccessful()) {
446+
$return = 'Success';
447+
} elseif ($process->isTerminated() && $process->isSuccessful() === false) {
448+
$return = 'Error';
449+
} else {
450+
throw new \Exception('Unknown process state.');
451+
}
452+
453+
return $return;
454+
}
455+
456+
protected function getExecutionTimeLabel(int $executionTime): string
457+
{
458+
if ($executionTime >= 60000) {
459+
$return = number_format($executionTime / 60000, 2) . ' min';
460+
} elseif ($executionTime >= 1000) {
461+
$return = number_format($executionTime / 1000, 1) . ' sec';
462+
} else {
463+
$return = $executionTime . ' ms';
464+
}
465+
466+
return $return;
467+
}
468+
418469
protected function writeBufferedLines(OutputInterface $output): static
419470
{
420471
if ($output instanceof ConsoleBufferedOutput) {

src/Process/Process.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class Process extends SymfonyProcess implements ProcessInterface
1616

1717
protected ?string $outputSummaryPrefix = null;
1818

19-
protected int $standardOutputVerbosity = OutputInterface::VERBOSITY_VERBOSE;
19+
protected int $standardOutputVerbosity = OutputInterface::VERBOSITY_VERY_VERBOSE;
2020

21-
protected int $errorOutputVerbosity = OutputInterface::VERBOSITY_VERBOSE;
21+
protected int $errorOutputVerbosity = OutputInterface::VERBOSITY_VERY_VERBOSE;
2222

23-
protected int $canceledOutputVerbosity = OutputInterface::VERBOSITY_VERBOSE;
23+
protected int $canceledOutputVerbosity = OutputInterface::VERBOSITY_VERY_VERBOSE;
2424

2525
protected int $failureStandardOutputVerbosity = OutputInterface::VERBOSITY_NORMAL;
2626

tests/Process/Process/CanceledOutputVerbosityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class CanceledOutputVerbosityTest extends TestCase
1919
public function testSet(): void
2020
{
2121
$process = $this->createLsProcess();
22-
static::assertSame(64, $process->getCanceledOutputVerbosity());
22+
static::assertSame(128, $process->getCanceledOutputVerbosity());
2323

2424
$process->setCanceledOutputVerbosity(32);
2525
static::assertSame(32, $process->getCanceledOutputVerbosity());

tests/Process/Process/ConstructTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public function testDefaultValues(): void
2626
static::assertSame('ls', $process->getName());
2727
$process->getStartCondition();
2828
$this->addToAssertionCount(1);
29-
static::assertSame(64, $process->getStandardOutputVerbosity());
30-
static::assertSame(64, $process->getErrorOutputVerbosity());
31-
static::assertSame(64, $process->getCanceledOutputVerbosity());
29+
static::assertSame(128, $process->getStandardOutputVerbosity());
30+
static::assertSame(128, $process->getErrorOutputVerbosity());
31+
static::assertSame(128, $process->getCanceledOutputVerbosity());
3232
static::assertSame(32, $process->getFailureStandardOutputVerbosity());
3333
static::assertSame(32, $process->getFailureErrorOutputVerbosity());
3434
static::assertFalse($process->isCanceled());

tests/Process/Process/ErrorOutputVerbosityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class ErrorOutputVerbosityTest extends TestCase
1919
public function testSet(): void
2020
{
2121
$process = $this->createLsProcess();
22-
static::assertSame(64, $process->getErrorOutputVerbosity());
22+
static::assertSame(128, $process->getErrorOutputVerbosity());
2323

2424
$process->setErrorOutputVerbosity(32);
2525
static::assertSame(32, $process->getErrorOutputVerbosity());

tests/Process/Process/StandardOutputVerbosityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class StandardOutputVerbosityTest extends TestCase
1919
public function testSet(): void
2020
{
2121
$process = $this->createLsProcess();
22-
static::assertSame(64, $process->getStandardOutputVerbosity());
22+
static::assertSame(128, $process->getStandardOutputVerbosity());
2323

2424
$process->setStandardOutputVerbosity(32);
2525
static::assertSame(32, $process->getStandardOutputVerbosity());

tests/Processes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
$rootDir = dirname(__DIR__, 2);
2121

22-
$process1 = new Process(['pwd'], $rootDir);
22+
$process1 = new Process(['sleep', '63'], $rootDir);
2323

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

2727
$process3 = new Process(['pwd'], $rootDir);
@@ -31,5 +31,5 @@
3131
->addProcess($process1)
3232
->addProcess($process2)
3333
->addProcess($process3)
34-
->setRefreshInterval(1)
34+
->setRefreshInterval(1000000)
3535
->run();

0 commit comments

Comments
 (0)