Skip to content

Commit cedb1a3

Browse files
webflogreg-1-anderson
authored andcommitted
Issue #2214: Replace DRUSH_NOCOLOR with OutputInterface::isDecorated (#3259)
1 parent b84b050 commit cedb1a3

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

includes/drush.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ function drush_get_global_options($brief = FALSE) {
145145
$options['ignored-modules'] = ['description' => "Exclude some modules from consideration when searching for drush command files.", 'example-value' => 'token,views'];
146146
$options['no-label'] = ['description' => "Remove the site label that drush includes in multi-site command output (e.g. `drush @site1,@site2 status`)."];
147147
$options['label-separator'] = ['description' => "Specify the separator to use in multi-site command output (e.g. `drush @sites pm-list --label-separator=',' --format=csv`).", 'example-value' => ','];
148-
$options['nocolor'] = ['context' => 'DRUSH_NOCOLOR', 'propagate-cli-value' => TRUE, 'description' => "Suppress color highlighting on log messages."];
149148
$options['show-invoke'] = ['description' => "Show all function names which could have been called for the current command. See drush_invoke()."];
150149
$options['cache-default-class'] = ['description' => "A cache backend class that implements CacheInterface. Defaults to JSONCache.", 'example-value' => 'JSONCache'];
151150
$options['cache-class-<bin>'] = ['description' => "A cache backend class that implements CacheInterface to use for a specific cache bin.", 'example-value' => 'className'];

src/Log/Logger.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function log($level, $message, array $context = [])
5959
drush_backend_packet('log', $entry);
6060
}
6161

62-
if (drush_get_context('DRUSH_NOCOLOR')) {
63-
$red = "[%s]";
64-
$yellow = "[%s]";
65-
$green = "[%s]";
66-
} else {
62+
if ($this->output->isDecorated()) {
6763
$red = "\033[31;40m\033[1m[%s]\033[0m";
6864
$yellow = "\033[1;33;40m\033[1m[%s]\033[0m";
6965
$green = "\033[1;32;40m\033[1m[%s]\033[0m";
66+
} else {
67+
$red = "[%s]";
68+
$yellow = "[%s]";
69+
$green = "[%s]";
7070
}
7171

7272
$verbose = \Drush\Drush::verbose();

src/Preflight/LegacyPreflight.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
use Drush\Drush;
55
use Drush\Config\Environment;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
68
use Webmozart\PathUtil\Path;
79

810
/**
@@ -95,7 +97,7 @@ public static function setContexts(Environment $environment)
9597
drush_set_context('DRUSH_PER_USER_CONFIGURATION', $environment->userConfigPath());
9698
}
9799

98-
public static function setGlobalOptionContexts($input, $output)
100+
public static function setGlobalOptionContexts(InputInterface $input, OutputInterface $output)
99101
{
100102
$verbose = $output->isVerbose();
101103
$debug = $output->isDebug();
@@ -110,18 +112,6 @@ public static function setGlobalOptionContexts($input, $output)
110112

111113
// Pipe implies quiet.
112114
drush_set_context('DRUSH_QUIET', $quiet || $pipe);
113-
114-
// Suppress colored logging if --no-ansi (was --nocolor) option is explicitly given or if
115-
// terminal does not support it.
116-
$nocolor = $input->getOption('no-ansi', false);
117-
if (!$nocolor) {
118-
// Check for colorless terminal. If there is no terminal, then
119-
// 'tput colors 2>&1' will return "tput: No value for $TERM and no -T specified",
120-
// which is not numeric and therefore will put us in no-color mode.
121-
$colors = exec('tput colors 2>&1');
122-
$nocolor = !($colors === false || (is_numeric($colors) && $colors >= 3));
123-
}
124-
drush_set_context('DRUSH_NOCOLOR', $nocolor);
125115
}
126116

127117
/**

0 commit comments

Comments
 (0)