3 ms·
What about things like ANSI color codes?
by lytedev 5y ago
What about things like ANSI color codes?
- MereInterest 5y agoMy preference would be to leave them in if they're the default, but to have an option to switch entirely to a more machine-readable format. It's a single line of sed to strip them out[0], and it's a bigger pain to figure out why a program has different behavior when debugging. [0] https://superuser.com/a/380778 https://superuser.com/a/380778
- kbrazil 5y agoI typically run the command output through `cat` to see if it does different things when outputting to the terminal vs piping. The biggest changes are typically ANSI color codes and column length. Some programs do strange things, like changing how they escape characters (ls). JC turns off ANSI color codes when it’s output is not a terminal, but that’s it.
- laumars 5y agoChanges in column length isn’t something that can’t be helped. The issue is that when a command outputs to a TTY, you can use that file descriptor to get the width of the TTY (ie your terminal emulator). But if you are piping a command then it’s STDOUT is no longer a TTY and thus you have no idea how wide the terminal is.
- foodstances 5y agoHope it supports NO_COLOR (http://no-color.org/ http://no-color.org/) env NO_COLOR=1 ...
- kbrazil 5y agoI hadn’t seen this before - thanks for sharing!
- b3morales 5y agoGood question; those are more reasonable to me since they aren't visible as characters and don't change the structure. So if I'm looking at the colorized output I can still use that as the basis for a sed or awk script operating on the non-colorized version.
- b3morales 5y agoOh, and I still want `--color=always` or equivalent for when I'm piping into a pager.