mirror of
https://github.com/cheat/cheat.git
synced 2024-11-29 17:26:53 +01:00
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
|
||
|
}
|