git.cweiske.de
/
php-sqllint.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8abc23a
)
Automatically detect if we should enable colors or not
author
Christian Weiske
<
[email protected]
>
Thu, 17 Dec 2015 05:38:26 +0000
(06:38 +0100)
committer
Christian Weiske
<
[email protected]
>
Thu, 17 Dec 2015 05:38:26 +0000
(06:38 +0100)
src/phpsqllint/Cli.php
patch
|
blob
|
history
diff --git
a/src/phpsqllint/Cli.php
b/src/phpsqllint/Cli.php
index 129a9257d736826bc43bfec9599c376b1e99f211..2f2473fa7cf7867b2a9a2ffeb447d6c7e1407725 100644
(file)
--- a/
src/phpsqllint/Cli.php
+++ b/
src/phpsqllint/Cli.php
@@
-168,11
+168,17
@@
class Cli
$parser->addOption(
'colors',
array(
$parser->addOption(
'colors',
array(
- 'short_name' => '-c',
- 'long_name' => '--colors',
+ 'long_name' => '--color',
'description' => 'Use colors in formatting output',
'action' => 'StoreTrue',
'description' => 'Use colors in formatting output',
'action' => 'StoreTrue',
- 'default' => false,
+ )
+ );
+ $parser->addOption(
+ 'nocolors',
+ array(
+ 'long_name' => '--nocolor',
+ 'description' => 'Disable colors in formatting output',
+ 'action' => 'StoreTrue',
)
);
$parser->addOption(
)
);
$parser->addOption(
@@
-219,7
+225,21
@@
class Cli
$this->renderer = new $rendClass();
$this->format = $result->options['format'];
$this->renderer = new $rendClass();
$this->format = $result->options['format'];
- $this->colors = $result->options['colors'];
+
+ if ($result->options['colors'] !== null) {
+ $this->colors = $result->options['colors'];
+ } else if ($result->options['nocolors'] !== null) {
+ $this->colors = !$result->options['nocolors'];
+ } else {
+ //default coloring to enabled, except
+ // when piping | to another tool
+ $this->colors = true;
+ if (function_exists('posix_isatty')
+ && !posix_isatty(STDOUT)
+ ) {
+ $this->colors = false;
+ }
+ }
foreach ($result->args['sql_files'] as $filename) {
if ($filename == '-') {
foreach ($result->args['sql_files'] as $filename) {
if ($filename == '-') {