Skip to content

Commit

Permalink
Colorize --show-diff, only on stdout
Browse files Browse the repository at this point in the history
Don't add colors to the saved `.diff` file.

Related to a41cf3e
  • Loading branch information
TysonAndre committed Aug 13, 2020
1 parent c3ddda4 commit 7be61be
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1774,11 +1774,17 @@ function run_worker(): void
function show_file_block(string $file, string $block, ?string $section = null): void
{
global $cfg;
global $colorize;

if ($cfg['show'][$file]) {
if (is_null($section)) {
$section = strtoupper($file);
}
if ($section === 'DIFF' && $colorize) {
// '-' is Light Red for removal, '+' is Light Green for addition
$block = preg_replace('/^[0-9]+\-\s.*$/m', "\e[1;31m\\0\e[0m", $block);
$block = preg_replace('/^[0-9]+\+\s.*$/m', "\e[1;32m\\0\e[0m", $block);
}

echo "\n========" . $section . "========\n";
echo rtrim($block);
Expand Down

0 comments on commit 7be61be

Please sign in to comment.