Skip to content

Commit

Permalink
Disable colors if NO_COLOR env var set (#10560)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojb committed Aug 6, 2021
1 parent 49c81d7 commit 6abc972
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Working version
- #10524: Directive argument type error now shows expected and received type.
(Wiktor Kuchta, review by Gabriel Scherer)

- #10560: Disable colors if the env variable `NO_COLOR` is set. If
`OCAML_COLOR` is set, its setting takes precedence over `NO_COLOR`.
(Nicolás Ojeda Bär, report by Gabriel Scherer, review by Daniel Bünzli,
Gabriel Scherer and David Allsopp)

### Manual and documentation:

- #7812, #10475: reworded the description of the behaviors of
Expand Down
5 changes: 5 additions & 0 deletions driver/compmisc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ let set_from_env flag Clflags.{ parse; usage; env_var } =

let read_clflags_from_env () =
set_from_env Clflags.color Clflags.color_reader;
if
Option.is_none !Clflags.color &&
Option.is_some (Sys.getenv_opt "NO_COLOR")
then
Clflags.color := Some Misc.Color.Never;
set_from_env Clflags.error_style Clflags.error_style_reader;
()

Expand Down
10 changes: 6 additions & 4 deletions man/ocaml.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,17 @@ use heuristics to enable colors only if the output supports them (an
.B never
disable color output.

The default setting is
The environment variable "OCAML_COLOR" is considered if \-color is not
provided. Its values are auto/always/never as above.

If \-color is not provided, "OCAML_COLOR" is not set and the environment
variable "NO_COLOR" is set, then color output is disabled. Otherwise,
the default setting is
.B auto,
and the current heuristic
checks that the "TERM" environment variable exists and is
not empty or "dumb", and that isatty(stderr) holds.

The environment variable "OCAML_COLOR" is considered if \-color is not
provided. Its values are auto/always/never as above.

.TP
.BI \-error\-style \ mode
Control the way error messages and warnings are printed.
Expand Down
10 changes: 6 additions & 4 deletions man/ocamlc.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,17 @@ use heuristics to enable colors only if the output supports them (an
.B never
disable color output.

The default setting is
The environment variable "OCAML_COLOR" is considered if \-color is not
provided. Its values are auto/always/never as above.

If \-color is not provided, "OCAML_COLOR" is not set and the environment
variable "NO_COLOR" is set, then color output is disabled. Otherwise,
the default setting is
.B auto,
and the current heuristic
checks that the "TERM" environment variable exists and is
not empty or "dumb", and that isatty(stderr) holds.

The environment variable "OCAML_COLOR" is considered if \-color is not
provided. Its values are auto/always/never as above.

.TP
.BI \-error\-style \ mode
Control the way error messages and warnings are printed.
Expand Down
10 changes: 6 additions & 4 deletions man/ocamlopt.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,17 @@ use heuristics to enable colors only if the output supports them (an
.B never
disable color output.

The default setting is
The environment variable "OCAML_COLOR" is considered if \-color is not
provided. Its values are auto/always/never as above.

If \-color is not provided, "OCAML_COLOR" is not set and the environment
variable "NO_COLOR" is set, then color output is disabled. Otherwise,
the default setting is
.B auto,
and the current heuristic
checks that the "TERM" environment variable exists and is
not empty or "dumb", and that isatty(stderr) holds.

The environment variable "OCAML_COLOR" is considered if \-color is not
provided. Its values are auto/always/never as above.

.TP
.BI \-error\-style \ mode
Control the way error messages and warnings are printed.
Expand Down
9 changes: 6 additions & 3 deletions manual/src/cmds/unified-options.etex
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ The following modes are supported:
\item["always"] enable colors unconditionally;
\item["never"] disable color output.
\end{description}
The default setting is 'auto', and the current heuristic
checks that the "TERM" environment variable exists and is
not empty or "dumb", and that 'isatty(stderr)' holds.

The environment variable "OCAML_COLOR" is considered if "-color" is not
provided. Its values are auto/always/never as above.

If "-color" is not provided, "OCAML_COLOR" is not set and the environment
variable "NO_COLOR" is set, then color output is disabled. Otherwise,
the default setting is 'auto', and the current heuristic
checks that the "TERM" environment variable exists and is
not empty or "dumb", and that 'isatty(stderr)' holds.
}%notop

\notop{%
Expand Down

0 comments on commit 6abc972

Please sign in to comment.