Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable colors if NO_COLOR env var set #10560

Merged
merged 5 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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