I probably should have provided a more concrete example in my post, but I'm interested in finding out if the program on the other side of a pipe supports color, rather than if my terminal does. Here's an example of what I was going for:
I had less in mind when thinking about this, but I suppose any pager. There's also filter programs like nl and ts that just annotate their input - a whitelist approach would probably work pretty well. One idea I kind of like is modifying ack to detect if it's talking to another ack, and having the second ack change its color to highlight different patterns in the output.
Looking through my notes on this, there's a lot of potential application beyond color - you could have a program tell another what encoding it's using (hey, my input is UTF-16LE!) so it doesn't need to guess, or you could have an implementation of uniq that checks to see if its input is coming from sort or not.
I probably should have provided a more concrete example in my post, but I'm interested in finding out if the program on the other side of a pipe supports color, rather than if my terminal does. Here's an example of what I was going for:
versus
Rob,
How many programs, aside from
less
, actually support color codes read from stdin?I had
less
in mind when thinking about this, but I suppose any pager. There's also filter programs likenl
andts
that just annotate their input - a whitelist approach would probably work pretty well. One idea I kind of like is modifyingack
to detect if it's talking to anotherack
, and having the secondack
change its color to highlight different patterns in the output.Looking through my notes on this, there's a lot of potential application beyond color - you could have a program tell another what encoding it's using (hey, my input is UTF-16LE!) so it doesn't need to guess, or you could have an implementation of
uniq
that checks to see if its input is coming fromsort
or not.Omg, I never knew about
less -R
!!