mirror of
https://github.com/cheat/cheat.git
synced 2025-09-02 01:58:29 +02:00
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:
@ -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)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/cheat/cheat/internal/config"
|
||||
)
|
||||
|
||||
const version = "3.0.2"
|
||||
const version = "3.0.3"
|
||||
|
||||
func main() {
|
||||
|
||||
|
Reference in New Issue
Block a user