]> granicus.if.org Git - php/commitdiff
Colorize --show-diff, only on stdout
authorTyson Andre <tysonandre775@hotmail.com>
Wed, 12 Aug 2020 23:27:00 +0000 (19:27 -0400)
committerTyson Andre <tysonandre775@hotmail.com>
Thu, 13 Aug 2020 15:27:32 +0000 (11:27 -0400)
Don't add colors to the saved `.diff` file.

Related to a41cf3e1d2ed3ae38ad6115a8b65e5f14dae0b49

run-tests.php

index c89b6971ebfe62a64cf0f623cca1aaabd84cd9f7..9d7397d615599126d8d587e99e59e27518bdf93d 100755 (executable)
@@ -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);