Skip to content

Commit 08094a2

Browse files
committed
Issue #78: added option to force colors
1 parent da5763f commit 08094a2

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

parallel-lint.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function showOptions()
2828
--exclude Exclude directory. If you want exclude multiple directories, use
2929
multiple exclude parameters.
3030
-j <num> Run <num> jobs in parallel (default: 10).
31+
--colors Enable colors in console output. (disables auto detection of color support)
3132
--no-colors Disable colors in console output.
3233
--json Output results as JSON string (require PHP 5.4).
3334
--blame Try to show git blame for row with error.

src/ErrorFormatter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ class ErrorFormatter
3838
/** @var bool */
3939
private $useColors;
4040

41+
/** @var bool */
42+
private $forceColors;
43+
4144
/** @var bool */
4245
private $translateTokens;
4346

44-
public function __construct($useColors = false, $translateTokens = false)
47+
public function __construct($useColors = false, $translateTokens = false, $forceColors = false)
4548
{
4649
$this->useColors = $useColors;
50+
$this->forceColors = $forceColors;
4751
$this->translateTokens = $translateTokens;
4852
}
4953

@@ -143,10 +147,10 @@ protected function getColoredCodeSnippet($filePath, $lineNumber, $linesBefore =
143147
}
144148

145149
$colors = new ConsoleColor();
146-
$colors->setForceStyle(true);
150+
$colors->setForceStyle($this->forceColors);
147151
$highlighter = new Highlighter($colors);
148152

149153
$fileContent = file_get_contents($filePath);
150154
return $highlighter->getCodeSnippet($fileContent, $lineNumber, $linesBefore, $linesAfter);
151155
}
152-
}
156+
}

src/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function getDefaultOutput(Settings $settings)
107107
if ($settings->json) {
108108
return new JsonOutput($writer);
109109
} else {
110-
return ($settings->colors ? new TextOutputColored($writer) : new TextOutput($writer));
110+
return ($settings->colors ? new TextOutputColored($writer, $settings->forceColors) : new TextOutput($writer));
111111
}
112112
}
113113

src/Output.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ class TextOutputColored extends TextOutput
320320
/** @var \JakubOnderka\PhpConsoleColor\ConsoleColor */
321321
private $colors;
322322

323-
public function __construct(IWriter $writer)
323+
public function __construct(IWriter $writer, $forceColors = false)
324324
{
325325
parent::__construct($writer);
326326

327327
if (class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor')) {
328328
$this->colors = new \JakubOnderka\PhpConsoleColor\ConsoleColor();
329-
$this->colors->setForceStyle(true);
329+
$this->colors->setForceStyle($forceColors);
330330
}
331331
}
332332

src/Settings.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ class Settings
8080
*/
8181
public $colors = true;
8282

83+
/**
84+
* Do not autodetect if colors are available
85+
* @var bool
86+
*/
87+
public $forceColors = false;
88+
8389
/**
8490
* Output results as JSON string
8591
* @var bool
@@ -158,6 +164,11 @@ public static function parseArguments(array $arguments)
158164
$settings->parallelJobs = max((int) $arguments->getNext(), 1);
159165
break;
160166

167+
case '--colors':
168+
$settings->forceColors = true;
169+
$settings->colors = true;
170+
break;
171+
161172
case '--no-colors':
162173
$settings->colors = false;
163174
break;

0 commit comments

Comments
 (0)