3 ms·
> No default (other than calling isatty) is reasonable, because you don't know (and you don't want to know) what your output is being piped through. Exactly be
by arp242 4y ago
> No default (other than calling isatty) is reasonable, because you don't know (and you don't want to know) what your output is being piped through.
Exactly because you don't know it makes sense to optimize for the common case.
> What happens if "prog" outputs an escape sequence (e.g. set color) on one line, and outputs another one (reset color) a few lines down?
Don't do that then. Or do use isatty() is your escape sequences are complex like that.
> It can, but should it?
Yes, because it's useful.
- rollcat 4y ago> Exactly because you don't know it makes sense to optimize for the common case. What is "common"? What if I want grep to match text that has an escape code in the middle of it - do I have to first inspect the generated escape codes? What if I'm redirecting the output to a file, and opening that file in a program that doesn't process escape codes? Every sane tool I know of calls isatty. It's only those that don't that cause problems. > Yes, because it's useful. Please read the article I've linked about "cat -v". There's no doubt someone (perhaps many people) find it useful; that doesn't mean it isn't a bad idea and/or a poor design.