You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1) fatih/color supports automatic TTY detection, but doesn't automatically detect when running in a CI environment. fatih/color also assumes that if stdout is not a TTY, then stderr is also not a TTY, which may not be true.
34
-
2) fatih/color supports Windows 10, but you need to write to a special stream.
35
-
3) auora supports nested styles via its custom `Sprintf()`, but you can't convert things to a string first - need to keep everything as aurora `Value`s.
36
-
4) aurora and mgutz/ansi both support 256 color output, but they don't detect whether the terminal supports it or not, and won't automatically convert 256 color output to 16 color output if it doesn't.
1. fatih/color supports automatic TTY detection, but assumes that if stdout is not a TTY, then stderr is also not a TTY, which may not be true.
34
+
2. fatih/color supports Windows 10, but you need to write to a special stream.
35
+
3. aurora supports nested styles via its custom `Sprintf()`, but you can't convert things to a string first - need to keep everything as aurora `Value`s.
36
+
4. aurora and mgutz/ansi both support 256 color output, but they don't detect whether the terminal supports it or not, and won't automatically convert 256 color output to 16 color output if it doesn't.
@@ -135,9 +135,7 @@ fmt.Println(gawk.StyleMust("bold", "red")("This is also bold and red."))
135
135
136
136
### gawk.SetLevel(level) and gawk.GetLevel()
137
137
138
-
Specifies the level of color support. Color support is automatically detected using [supportscolor](https://github.com/jwalton/go-supportscolor), and [flags and command line arguments](https://github.com/jwalton/go-supportscolor#info) supported by supportscolor are also supported here. For example, the environment variable `FORCE_COLOR=1` will force the application to use LevelBasic (see table below), or passing the command line argument `--no-color` will force your program to run without color.
139
-
140
-
You can override the detected level by calling `SetLevel()`. You should however only do this in your own application, as it applies globally to all gawk consumers. If you need to change this in a library, create a new instance:
138
+
Specifies the level of color support. See [the section on color detection](https://github.com/jwalton/gawk#color-detection) for details about how gawk auto-detects color support. You can override the detected level by calling `SetLevel()`. You should however only do this in your own application, as it applies globally to all gawk consumers. If you need to change this in a library, create a new instance:
@@ -154,7 +152,7 @@ var myGawk = gawk.New(gawk.ForceLevel(gawk.LevelNone))
154
152
155
153
`gawk.Stderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`.
156
154
157
-
Stdout and stderr can be different in cases where the user is piping output. For example, if a user runs:
155
+
Stdout and stderr can be different in cases where the user is piping output. For example, if a user runs:
158
156
159
157
```sh
160
158
myprogram > out.txt
@@ -249,6 +247,24 @@ Gawk is cross-platform, and will work on Linux and MacOS systems, but will also
249
247
250
248
Many ANSI color libraries for Go do a poor job of handling colors in Windows. This is because historically, Windows has not supported ANSI color codes, so hacks like ansicon or [go-colorable](https://github.com/mattn/go-colorable) were required. However, Windows 10 has supported ANSI escape codes since 2017 (build 10586 for 256 color support, and build 14931 for 16.7 million true color support). In [Windows Terminal](https://github.com/Microsoft/Terminal) this is enabled by default, but in `CMD.EXE` or PowerShell, ANSI support must be enabled via [`ENABLE_VIRTUAL_TERMINAL_PROCESSING`](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences). Gawk, of course, takes care of all of this for you. This functionality is also availabile in the [supportscolor](https://github.com/jwalton/go-supportscolor) library if you're an ANSI library author and you'd like to add this functionality to your own project.
251
249
250
+
## Color Detection
251
+
252
+
Color support is automatically detected using [supportscolor](https://github.com/jwalton/go-supportscolor), and [flags and command line arguments](https://github.com/jwalton/go-supportscolor#info) supported by supportscolor are also supported here. Gawk will automatically obey all the recommendations from [Command Line Interface Guidelines](https://clig.dev/#output). The following will disable color:
253
+
254
+
- stdout is not a TTY. (Or, for `gawk.Stderr`, stderr is not a TTY.)
255
+
- The `NO_COLOR` environment variable is set.
256
+
- The `TERM` variable has the value `dumb`.
257
+
- The user passes the option `--no-color`, `--no-colors`, `--color=false`, or `--color=never`.
258
+
- The `FORCE_COLOR` environment variable is 0.
259
+
260
+
Color support will be forcefully enabled if:
261
+
262
+
- The `FORCE_COLOR` environment variable is set to `1`, `2`, or `3` (for 16 color, 256 color, and 16.7m color support, respectively).
263
+
- The `FORCE_COLOR` environment variable is set with no value, or with `true`.
264
+
- The uses passes the option `--color`, `--colors`, `--color=true`, or `--color=always`.
265
+
266
+
Gawk will also support colored output when run from popular CI environments, including Travis, CircleCI, Appveyor, GitlabCI, GitHub Actions, Buildkite, Drone, and TeamCity.
267
+
252
268
## Related
253
269
254
270
-[ansistyles](https://github.com/jwalton/gawk/tree/master/pkg/ansistyles) - A low level library for generating ANSI escape codes, ported from Node.js's [ansi-styles](https://github.com/chalk/ansi-styles).
0 commit comments