Skip to content

Commit 7be61be

Browse files
committed
Colorize --show-diff, only on stdout
Don't add colors to the saved `.diff` file. Related to a41cf3e
1 parent c3ddda4 commit 7be61be

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

run-tests.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,11 +1774,17 @@ function run_worker(): void
17741774
function show_file_block(string $file, string $block, ?string $section = null): void
17751775
{
17761776
global $cfg;
1777+
global $colorize;
17771778

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

17831789
echo "\n========" . $section . "========\n";
17841790
echo rtrim($block);

0 commit comments

Comments
 (0)