Skip to content

Commit 551c67d

Browse files
committed
CLI update.
Changelog excerpt: - Added support for NO_COLOR.
1 parent b72f6ff commit 551c67d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,8 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
185185
### v3.7.0
186186

187187
- [2025.07.08]: Added the ability to route all outbound requests through a proxy, and two new configuration directives, `request_proxy` and `request_proxyauth`.
188+
189+
### v3.7.1
190+
191+
- [2025.10.03]: Optimised some iterators.
192+
- [2025.10.07]: Added support for NO_COLOR.

src/Scanner.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The scanner (last modified: 2025.10.03).
11+
* This file: The scanner (last modified: 2025.10.07).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -56,6 +56,12 @@ class Scanner
5656
*/
5757
private $HeuristicMode = false;
5858

59+
/**
60+
* @var bool Whether to use colours for CLI output.
61+
* @link https://no-color.org/
62+
*/
63+
private $NoColor = false;
64+
5965
/**
6066
* Construct the scanner.
6167
*
@@ -158,6 +164,8 @@ public function __construct(\phpMussel\Core\Loader &$Loader)
158164
$this->Loader->logRotation($this->Loader->Configuration['core']['scan_log']);
159165
return true;
160166
});
167+
168+
$this->NoColor = !empty(getenv('NO_COLOR'));
161169
}
162170

163171
/**
@@ -691,7 +699,7 @@ public function atHit(string $Hash, int $Size = -1, string $Name = '', string $T
691699
}
692700
}
693701

694-
if ($this->CalledFrom === 'CLI') {
702+
if ($this->CalledFrom === 'CLI' && !$this->NoColor) {
695703
if ($Code === 1) {
696704
$Text = "\033[0;92m" . $Text . "\033[0;33m";
697705
} elseif ($Code === 2 || $Code < 0) {
@@ -810,6 +818,17 @@ function_exists('gzinflate') &&
810818
return trim($str);
811819
}
812820

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+
813832
/**
814833
* Responsible for recursing through any files given to it to be scanned, which
815834
* may be necessary for the case of archives and directories. It performs the

0 commit comments

Comments
 (0)