Skip to content

Commit 9b72325

Browse files
committed
Keep isColorSupport() on the Config class
Partially reverts the previous commit to keep isColorSupport() on the Config class as discussed during the PR review.
1 parent 20c8978 commit 9b72325

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

Scripts/FeatureComplete/Config.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ protected function processCliCommand()
271271

272272
if (empty($args)) {
273273
// No options set.
274-
$this->showColored = HelpTextFormatter::isColorSupported();
274+
$this->showColored = $this->isColorSupported();
275275

276276
return;
277277
}
@@ -283,7 +283,7 @@ protected function processCliCommand()
283283
} elseif (isset($argsFlipped['--colors'])) {
284284
$this->showColored = true;
285285
} else {
286-
$this->showColored = HelpTextFormatter::isColorSupported();
286+
$this->showColored = $this->isColorSupported();
287287
}
288288

289289
if (isset($argsFlipped['-h'])
@@ -360,6 +360,41 @@ static function ($subdir) {
360360
}
361361
}
362362

363+
/**
364+
* Detect whether or not the CLI supports colored output.
365+
*
366+
* @codeCoverageIgnore
367+
*
368+
* @return bool
369+
*/
370+
protected function isColorSupported()
371+
{
372+
// Windows.
373+
if (\DIRECTORY_SEPARATOR === '\\') {
374+
if (\getenv('ANSICON') !== false || \getenv('ConEmuANSI') === 'ON') {
375+
return true;
376+
}
377+
378+
if (\function_exists('sapi_windows_vt100_support')) {
379+
// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound
380+
return @\sapi_windows_vt100_support(\STDOUT);
381+
}
382+
383+
return false;
384+
}
385+
386+
if (\getenv('GITHUB_ACTIONS')) {
387+
return true;
388+
}
389+
390+
// Linux/MacOS.
391+
if (\function_exists('posix_isatty')) {
392+
return @\posix_isatty(\STDOUT);
393+
}
394+
395+
return false;
396+
}
397+
363398
/**
364399
* Retrieve the version number of this script.
365400
*

Scripts/Utils/HelpTextFormatter.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace PHPCSDevTools\Scripts\Utils;
1212

1313
/**
14-
* Helper class for formatting help text and detecting color support.
14+
* Helper class for formatting help text.
1515
*
1616
* ---------------------------------------------------------------------------------------------
1717
* This class is not part of the public API. Backward compatibility is not guaranteed.
@@ -99,39 +99,4 @@ public static function format(array $helpTexts, $showColored)
9999

100100
return $output;
101101
}
102-
103-
/**
104-
* Detect whether or not the CLI supports colored output.
105-
*
106-
* @codeCoverageIgnore
107-
*
108-
* @return bool
109-
*/
110-
public static function isColorSupported()
111-
{
112-
// Windows.
113-
if (\DIRECTORY_SEPARATOR === '\\') {
114-
if (\getenv('ANSICON') !== false || \getenv('ConEmuANSI') === 'ON') {
115-
return true;
116-
}
117-
118-
if (\function_exists('sapi_windows_vt100_support')) {
119-
// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound
120-
return @\sapi_windows_vt100_support(\STDOUT);
121-
}
122-
123-
return false;
124-
}
125-
126-
if (\getenv('GITHUB_ACTIONS')) {
127-
return true;
128-
}
129-
130-
// Linux/MacOS.
131-
if (\function_exists('posix_isatty')) {
132-
return @\posix_isatty(\STDOUT);
133-
}
134-
135-
return false;
136-
}
137102
}

0 commit comments

Comments
 (0)