From 931299329d98a6f2ff7df744acad192ab76a379b Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 8 Jun 2024 12:59:31 -0400 Subject: [PATCH 1/2] Support `$NO_COLOR` --- docs/src/output-colorization.md.in | 2 +- docs/src/reference-main-env-vars.md.in | 2 +- pkg/cli/option_parse.go | 4 ++-- pkg/colorizer/colorizer.go | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/src/output-colorization.md.in b/docs/src/output-colorization.md.in index e60a53887..8c32c3f9b 100644 --- a/docs/src/output-colorization.md.in +++ b/docs/src/output-colorization.md.in @@ -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` diff --git a/docs/src/reference-main-env-vars.md.in b/docs/src/reference-main-env-vars.md.in index 5c74638a1..869c73f3f 100644 --- a/docs/src/reference-main-env-vars.md.in +++ b/docs/src/reference-main-env-vars.md.in @@ -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). diff --git a/pkg/cli/option_parse.go b/pkg/cli/option_parse.go index 24f525fcc..a17d4658f 100644 --- a/pkg/cli/option_parse.go +++ b/pkg/cli/option_parse.go @@ -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`" + `. diff --git a/pkg/colorizer/colorizer.go b/pkg/colorizer/colorizer.go index 3bc4525ad..cd012cffa 100644 --- a/pkg/colorizer/colorizer.go +++ b/pkg/colorizer/colorizer.go @@ -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 From 5801a93d14a0f115da637afb427b76e9c02c751b Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 8 Jun 2024 13:01:53 -0400 Subject: [PATCH 2/2] run `make dev` --- docs/src/manpage.md | 6 +++--- docs/src/manpage.txt | 6 +++--- docs/src/output-colorization.md | 2 +- docs/src/reference-main-env-vars.md | 2 +- docs/src/reference-main-flag-list.md | 4 ++-- man/manpage.txt | 6 +++--- man/mlr.1 | 8 ++++---- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/src/manpage.md b/docs/src/manpage.md index 6f4ab1bbd..db104861d 100644 --- a/docs/src/manpage.md +++ b/docs/src/manpage.md @@ -648,8 +648,8 @@ This is simply a copy of what you should see on running `man mlr` at a command p 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`. @@ -3730,5 +3730,5 @@ This is simply a copy of what you should see on running `man mlr` at a command p MIME Type for Comma-Separated Values (CSV) Files, the Miller docsite https://miller.readthedocs.io - 2024-05-11 4mMILLER24m(1) + 2024-06-08 4mMILLER24m(1) diff --git a/docs/src/manpage.txt b/docs/src/manpage.txt index 199946d45..4ff577844 100644 --- a/docs/src/manpage.txt +++ b/docs/src/manpage.txt @@ -627,8 +627,8 @@ 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`. @@ -3709,4 +3709,4 @@ MIME Type for Comma-Separated Values (CSV) Files, the Miller docsite https://miller.readthedocs.io - 2024-05-11 4mMILLER24m(1) + 2024-06-08 4mMILLER24m(1) diff --git a/docs/src/output-colorization.md b/docs/src/output-colorization.md index 6282d2172..e94cfe91a 100644 --- a/docs/src/output-colorization.md +++ b/docs/src/output-colorization.md @@ -50,7 +50,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` diff --git a/docs/src/reference-main-env-vars.md b/docs/src/reference-main-env-vars.md index 3b3302b8c..295973d58 100644 --- a/docs/src/reference-main-env-vars.md +++ b/docs/src/reference-main-env-vars.md @@ -19,6 +19,6 @@ Quick links: 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). diff --git a/docs/src/reference-main-flag-list.md b/docs/src/reference-main-flag-list.md index e684ef1f6..e9a47af63 100644 --- a/docs/src/reference-main-flag-list.md +++ b/docs/src/reference-main-flag-list.md @@ -328,8 +328,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`. diff --git a/man/manpage.txt b/man/manpage.txt index 199946d45..4ff577844 100644 --- a/man/manpage.txt +++ b/man/manpage.txt @@ -627,8 +627,8 @@ 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`. @@ -3709,4 +3709,4 @@ MIME Type for Comma-Separated Values (CSV) Files, the Miller docsite https://miller.readthedocs.io - 2024-05-11 4mMILLER24m(1) + 2024-06-08 4mMILLER24m(1) diff --git a/man/mlr.1 b/man/mlr.1 index f5b66e015..c39347089 100644 --- a/man/mlr.1 +++ b/man/mlr.1 @@ -2,12 +2,12 @@ .\" Title: mlr .\" Author: [see the "AUTHOR" section] .\" Generator: ./mkman.rb -.\" Date: 2024-05-11 +.\" Date: 2024-06-08 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "MILLER" "1" "2024-05-11" "\ \&" "\ \&" +.TH "MILLER" "1" "2024-06-08" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Portability definitions .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -756,8 +756,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`.