cheat icon indicating copy to clipboard operation
cheat copied to clipboard

Don't use escape sequences when redirecting output

Open dufferzafar opened this issue 10 years ago • 4 comments

cheat show git > output.txt or cheat show git | xclip

These commands pretty-print the output so escape sequences are printed too. Which just messes up the output. This is how it looks:

[33;5m# To set your identity:[0m
[36;5m(1)[0m git config --global user.name "John Doe"
[36;5m(2)[0m git config --global user.email [email protected]

[33;5m# To set your editor:[0m
[36;5m(3)[0m git config --global core.editor emacs

[33;5m# To enable color:[0m
[36;5m(4)[0m git config --global color.ui true

Is there a way to automatically disable escape codes, when redirecting output, or should we take a command line option like --plain?

dufferzafar avatar Sep 01 '15 16:09 dufferzafar

you can use https://github.com/mattn/go-isatty

mattn avatar Sep 01 '15 16:09 mattn

@mattn isatty worked, but i think having a switch for colored/plain output won't be wrong because there might be some cases where we are piping the output but still want colors, like cheat show git | less (having colors in less would be okay)

dufferzafar avatar Sep 01 '15 17:09 dufferzafar

how about -color=[always|never|auto] like ls command?

mattn avatar Sep 01 '15 17:09 mattn

Yeah, that sounds good.

dufferzafar avatar Sep 01 '15 17:09 dufferzafar