Skip to content

Commit

Permalink
[ENH] support outputline filter callback
Browse files Browse the repository at this point in the history
  • Loading branch information
n3o77 committed Apr 2, 2022
1 parent 5389dc0 commit 84f9517
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Struct/SubprocessInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SubprocessInfo

private array $outputRows = [];

private $outputRowFilterCb;

public function __construct(
Process $process,
SymfonyStyle $io,
Expand All @@ -48,6 +50,11 @@ public static function create(
return new self($process, $io, $output);
}

public function setOuputRowFilter(callable $callable)
{
$this->outputRowFilterCb = $callable;
}

public function setOutput(ConsoleSectionOutput $output): self
{
$this->output = $output;
Expand Down Expand Up @@ -76,7 +83,16 @@ public function addOutputRow(string $row): void
array_shift($this->outputRows);
}

$this->outputRows[] = trim($row);
if (isset($this->outputRowFilterCb) && is_callable($this->outputRowFilterCb)) {
$cb = $this->outputRowFilterCb;
$nRow = $cb(trim($row));
if ($nRow) {
$this->outputRows[] = $nRow;
}
} else {
$this->outputRows[] = trim($row);
}

$this->lastOutputTime = CarbonImmutable::now();
}

Expand Down

0 comments on commit 84f9517

Please sign in to comment.