Skip to content

Commit

Permalink
Support $NO_COLOR
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Jun 8, 2024
1 parent 66abef6 commit 9312993
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/src/output-colorization.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ described below:

* Suppression/unsuppression:

* `export MLR_NO_COLOR=true` means Miller won't color even when it normally would.
* `export MLR_NO_COLOR=true` or `export NO_COLOR=true` means Miller won't color even when it normally would.
* `export MLR_ALWAYS_COLOR=true` means Miller will color even when it normally would not. For example, you might want to use this when piping `mlr` output to `less -r`.
* Command-line flags `--no-color` or `-M`, `--always-color` or `-C`.
* On Windows, replace `export` with `set`
Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference-main-env-vars.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
The following environment variables affect how Miller works:

* `MLRRC`: see [Customization](customization.md).
* `MLR_NO_COLOR`, `MLR_ALWAYS_COLOR`, `MLR_KEY_COLOR`, `MLR_VALUE_COLOR`, `MLR_PASS_COLOR`, `MLR_FAIL_COLOR`, `MLR_REPL_PS1_COLOR`, `MLR_REPL_PS2_COLOR`, `MLR_HELP_COLOR`: see [Output Colorization](output-colorization.md).
* `MLR_NO_COLOR`, `NO_COLOR`, `MLR_ALWAYS_COLOR`, `MLR_KEY_COLOR`, `MLR_VALUE_COLOR`, `MLR_PASS_COLOR`, `MLR_FAIL_COLOR`, `MLR_REPL_PS1_COLOR`, `MLR_REPL_PS2_COLOR`, `MLR_HELP_COLOR`: see [Output Colorization](output-colorization.md).
* `MLR_REPL_PS1`, `MLR_REPL_PS2`: see [REPL](repl.md).

4 changes: 2 additions & 2 deletions pkg/cli/option_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2715,8 +2715,8 @@ Mechanisms for coloring:
How you can control colorization:
* Suppression/unsuppression:
* Environment variable ` + "`export MLR_NO_COLOR=true`" + ` means don't color
even if stdout+TTY.
* Environment variable ` + "`export MLR_NO_COLOR=true` or `export NO_COLOR=true`" + `
means don't color even if stdout+TTY.
* Environment variable ` + "`export MLR_ALWAYS_COLOR=true`" + ` means do color
even if not stdout+TTY.
For example, you might want to use this when piping mlr output to ` + "`less -r`" + `.
Expand Down
3 changes: 2 additions & 1 deletion pkg/colorizer/colorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ var stdoutIsATTY = getStdoutIsATTY()
// Read environment variables at startup time. These can be overridden
// afterward using command-line flags.
func init() {
if os.Getenv("MLR_NO_COLOR") != "" {
if os.Getenv("MLR_NO_COLOR") != "" || os.Getenv("NO_COLOR") != "" {
colorization = ColorizeOutputNever
colorization = ColorizeOutputNever
} else if os.Getenv("MLR_ALWAYS_COLOR") != "" {
colorization = ColorizeOutputAlways
Expand Down

0 comments on commit 9312993

Please sign in to comment.