|
8 | 8 | * License: GNU/GPLv2 |
9 | 9 | * @see LICENSE.txt |
10 | 10 | * |
11 | | - * This file: The scanner (last modified: 2025.10.03). |
| 11 | + * This file: The scanner (last modified: 2025.10.07). |
12 | 12 | */ |
13 | 13 |
|
14 | 14 | namespace phpMussel\Core; |
@@ -56,6 +56,12 @@ class Scanner |
56 | 56 | */ |
57 | 57 | private $HeuristicMode = false; |
58 | 58 |
|
| 59 | + /** |
| 60 | + * @var bool Whether to use colours for CLI output. |
| 61 | + * @link https://no-color.org/ |
| 62 | + */ |
| 63 | + private $NoColor = false; |
| 64 | + |
59 | 65 | /** |
60 | 66 | * Construct the scanner. |
61 | 67 | * |
@@ -158,6 +164,8 @@ public function __construct(\phpMussel\Core\Loader &$Loader) |
158 | 164 | $this->Loader->logRotation($this->Loader->Configuration['core']['scan_log']); |
159 | 165 | return true; |
160 | 166 | }); |
| 167 | + |
| 168 | + $this->NoColor = !empty(getenv('NO_COLOR')); |
161 | 169 | } |
162 | 170 |
|
163 | 171 | /** |
@@ -691,7 +699,7 @@ public function atHit(string $Hash, int $Size = -1, string $Name = '', string $T |
691 | 699 | } |
692 | 700 | } |
693 | 701 |
|
694 | | - if ($this->CalledFrom === 'CLI') { |
| 702 | + if ($this->CalledFrom === 'CLI' && !$this->NoColor) { |
695 | 703 | if ($Code === 1) { |
696 | 704 | $Text = "\033[0;92m" . $Text . "\033[0;33m"; |
697 | 705 | } elseif ($Code === 2 || $Code < 0) { |
@@ -810,6 +818,17 @@ function_exists('gzinflate') && |
810 | 818 | return trim($str); |
811 | 819 | } |
812 | 820 |
|
| 821 | + /** |
| 822 | + * Set CLI text colour if colours are enabled. |
| 823 | + * |
| 824 | + * @param string $In The colour to set. |
| 825 | + * @return string The colour to set. |
| 826 | + */ |
| 827 | + public function cliColour(string $Colour): string |
| 828 | + { |
| 829 | + return $this->NoColor ? '' : $Colour; |
| 830 | + } |
| 831 | + |
813 | 832 | /** |
814 | 833 | * Responsible for recursing through any files given to it to be scanned, which |
815 | 834 | * may be necessary for the case of archives and directories. It performs the |
|
0 commit comments