Skip to content

Commit fddd83c

Browse files
gamlerhartlolgablefou
authored
Honor the NO_COLOR env variable (#4246)
When the NO_COLOR env variable is set, then avoid coloring the terminal. --color argument does overrides the env variable Inspired by https://no-color.org and asked in discussion: #4170 Pull request: #4246 --------- Co-authored-by: Lorenzo Gabriele <[email protected]> Co-authored-by: Tobias Roeser <[email protected]>
1 parent 08de61b commit fddd83c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

docs/modules/ROOT/pages/cli/flags.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To see a cheat sheet of all the command line flags that Mill supports, you can u
2727

2828
```scala
2929
$ ./mill --help
30-
Mill Build Tool, version 0.12.0
30+
Mill Build Tool, version 0.12.5-13-0e02e6
3131
Usage: mill [options] task [task-options] [+ task ...]
3232

3333
task cheat sheet:
@@ -60,6 +60,7 @@ options:
6060
-b --bell Ring the bell once if the run completes successfully, twice if it fails.
6161
--bsp Enable BSP server mode.
6262
--color <bool> Toggle colored output; by default enabled only if the console is interactive
63+
and NO_COLOR environment variable is not set
6364
-d --debug Show debug output on STDOUT
6465
--disable-callgraph Disables fine-grained invalidation of tasks based on analyzing code changes.
6566
If passed, you need to manually run `clean` yourself after build changes.

runner/src/mill/runner/MillCliConfig.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ case class MillCliConfig(
106106
doc = """The name or a pattern of the tasks(s) you want to build."""
107107
)
108108
leftoverArgs: Leftover[String] = Leftover(),
109-
@arg(doc = """Toggle colored output; by default enabled only if the console is interactive""")
109+
@arg(doc =
110+
"""Toggle colored output; by default enabled only if the console is interactive and NO_COLOR environment variable is not set"""
111+
)
110112
color: Option[Boolean] = None,
111113
@arg(
112114
name = "disable-callgraph",

runner/src/mill/runner/MillMain.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ object MillMain {
162162
(false, RunnerState.empty)
163163

164164
case Right(config) =>
165-
val colored = config.color.getOrElse(mainInteractive)
165+
val noColorViaEnv = env.get("NO_COLOR").exists(_.nonEmpty)
166+
val colored = config.color.getOrElse(mainInteractive && !noColorViaEnv)
166167
val colors = if (colored) mill.util.Colors.Default else mill.util.Colors.BlackWhite
167168

168169
if (!config.silent.value) {

0 commit comments

Comments
 (0)