mirror of
https://github.com/cheat/cheat.git
synced 2024-11-24 15:01:36 +01:00
3afea0972c
- Corrects an error with `--search`. Previously, `--search` was not aware of whether it was outputted to a TTY, and would apply colorization at all times. This resulted in unwanted behavior when, for example, piping search results into a paginator. - Corrects an error with `--color`. Previously, `--color` would be ignored if output was being written to a non-TTY. This made it impossible, for example, to `cheat tar --color | less -R`, as colorization would always be stripped. The behavior of `--color` has been modified such that it now behaves similarly to `--color=always` in other applications.
27 lines
582 B
Go
27 lines
582 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/mattn/go-isatty"
|
|
)
|
|
|
|
// Color indicates whether colorization should be applied to the output
|
|
func (c *Config) Color(opts map[string]interface{}) bool {
|
|
|
|
// default to the colorization specified in the configs...
|
|
colorize := c.Colorize
|
|
|
|
// ... however, only apply colorization if we're writing to a tty...
|
|
if !isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()) {
|
|
colorize = false
|
|
}
|
|
|
|
// ... *unless* the --colorize flag was passed
|
|
if opts["--colorize"] == true {
|
|
colorize = true
|
|
}
|
|
|
|
return colorize
|
|
}
|