From a44ac7648f478f611f913038b5637627014be8b3 Mon Sep 17 00:00:00 2001 From: Boudy de Geer Date: Tue, 23 Jul 2024 16:21:04 +0200 Subject: [PATCH] fix: clean up anoying empty lines and timer for expose listen in terminal --- src/Console/ListenCommand.php | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Console/ListenCommand.php b/src/Console/ListenCommand.php index 608d32f..5a757d7 100644 --- a/src/Console/ListenCommand.php +++ b/src/Console/ListenCommand.php @@ -169,12 +169,46 @@ protected function promptForMissingArgumentsUsing() ]; } + protected function cleanOutput($output) + { + if (preg_match( + '/Remaining time:\s+\d{2}:\d{2}:\d{2}\\n/', + $output, + $matches + )) { + $output = preg_replace('/Remaining time:\s+\d{2}:\d{2}:\d{2}\\n/', '', $output); + } + + if ($output) { + $lines = explode("\n", $output); + $cleaned_lines = []; + + foreach ($lines as $line) { + // Trim leading and trailing whitespace + $line = trim($line); + // Replace multiple spaces with a single space + $line = preg_replace('/\s+/', ' ', $line); + + if (!empty($line)) { + $cleaned_lines[] = $line; + } + } + // Join cleaned lines back into a single string + $output = implode("\n", $cleaned_lines); + } + + return $output; + } + protected function process(array $commands): InvokedProcess { return $this->process = Process::timeout(120) ->start($commands, function (string $type, string $output) { if ($this->option('verbose') || isset($this->webhookId)) { - note($output); + $output = $this->cleanOutput($output); + if ($output) { + note($output); + } } }); }