fix: removed colorization on non-tty

Fixes a bug whereby `cheat` would apply ANSI colorization even when
outputting into a non-TTY.
This commit is contained in:
Chris Lane
2019-10-29 19:47:56 -04:00
parent 10af84dc10
commit 33ac3d34d1
242 changed files with 55375 additions and 13277 deletions

View File

@ -6,6 +6,7 @@ import (
"strings"
"github.com/alecthomas/chroma/quick"
"github.com/mattn/go-isatty"
"github.com/cheat/cheat/internal/config"
"github.com/cheat/cheat/internal/sheets"
@ -43,8 +44,20 @@ func cmdView(opts map[string]interface{}, conf config.Config) {
os.Exit(0)
}
// if colorization is not desired, output un-colorized text and exit
if conf.Colorize == false && opts["--colorize"] == false {
// apply colorization if so configured ...
colorize := conf.Colorize
// ... or if --colorized were passed ...
if opts["--colorize"] == true {
colorize = true
}
// ... unless we're outputting to a non-TTY
if !isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()) {
colorize = false
}
if !colorize {
fmt.Print(sheet.Text)
os.Exit(0)
}

View File

@ -13,7 +13,7 @@ import (
"github.com/cheat/cheat/internal/config"
)
const version = "3.0.2"
const version = "3.0.3"
func main() {