4 ms·
Seems like it would be easy to make a program that strips color controls from stdin and pipes everything else to stdout
by brundolf 5y ago
Seems like it would be easy to make a program that strips color controls from stdin and pipes everything else to stdout
- black_knight 5y agoI think Plan9port’s nobs command does this. It is my default pager when using acme or 9term (also from P9P).
- eminence32 5y agoThis is generally the behavior I've seen on my everyday apps that support color in their output. Often they have a `--color auto|never|always` command line option, with "auto" being the default, which detects if the output is a TTY or some other interactive terminal
- brundolf 5y agoAuto-detecting is good, but I was suggesting a third-party program that just takes arbitrary input, strips the control characters, and produces the resulting output, in case the original app can't do what you need as a user
- eminence32 5y agoAh, yes. Sorry, I misread your comment. Yes, that is a good idea :)
- MereInterest 5y agoThis stack overflow post has a sed command that will strip them for you, so no need for a dedicated program. https://stackoverflow.com/a/18000433 https://stackoverflow.com/a/18000433
- joveian 5y agoI did a quick GitHub search and found two of them: https://github.com/kurtbuilds/no-ansi https://github.com/kurtbuilds/no-ansi Written in rust and ultimately uses vte from alacritty to write through a virtual terminal. Can be given a file on the command line. https://github.com/emptymonkey/dumb https://github.com/emptymonkey/dumb Written in Lex and just strips a number of specific escape sequences (written 9 years ago so likely doesn't include a few). Only stdin to stdout. Edit: And now I see the discussion below about nofun and the equivalent sed command that use regex. ... and reading more I see ansi2txt in colorized-logs (the one most likely to be packaged) that also effectively is a regex, although written out in C.