GNOME Bugzilla – Bug 474055
Default to using color only when tty
Last modified: 2007-09-13 19:28:14 UTC
The colors on the debug output are nice when displaying to a terminal, but a pain when piping through a pager (as is often the case, because the output is so voluminous.) I would prefer it if the default was to use color only if the output is a terminal. I'm attaching a patch (hopefully; if I figure out how).
Created attachment 95026 [details] [review] Turn off color when stdout not a tty
isatty() is not really portable AFAIK and only exists on Unix-like systems (and needs unistd.h). So the isatty() part must be wrapped in #ifdef HAVE_UNISTD_H.
Also the debug output is sent to stderr, not stdout by default. But I'm not sure that this simple patch is enough, one could register their own debug output functions or set another error message handler for g_printerr() and this could in theory support colors.
Created attachment 95032 [details] [review] updated patch
Both GST_DEBUG=*:5 gst-inspect-0.10 2>&1 | less -R and GST_DEBUG=*:5 gst-inspect-0.10 2>&1 | more show the colours just fine for me, and it'd be nice if that behaviour was kept IMHO. Same for output to file and subsequent viewing in colour-aware pager. Maybe add another environment variable or abuse GST_DEBUG_NO_COLOR in connection with the isatty check?
A new env variable doesn't make sense IMHO, one could simply use the old one to disable the colors then. I guess we can close this bug as there can't be any auto detection of what the user wants
I like Tim's idea. In more detail, it would be either creating a variable GST_DEBUG_COLOR_IF_TTY or GST_DEBUG_COLOR_ONLY_IF_TTY or abusing GST_DEBUG_NO_COLOR by allowing the value notty to mean "no color if not tty" (the double negative is unfortunate). On the other hand, I think I no longer care all that much, because thanks to Tim I now know of the existence of the -R option. And the other time when it's annoying is when I'm running within emacs, and there the tty check won't help anyway. (Yes, I'm sure emacs has a terminal mode that would handle the colors too. But I'd rather not go to that much trouble.)
Ok, let's WONTFIX this then :)
Created attachment 95537 [details] [review] Document less -R for clueless people like me
But that would be too easy! I'm trying to file down all the rough edges I encounter in my explorations of gstreamer, and this was one fairly minor such annoyance. So please consider the attached doc patch so the next person to come along with as little clue as I have won't need to run into the same thing.
Wooh, a docs patch! Thanks, committed: 2007-09-13 Tim-Philipp Müller <tim at centricular dot net> Patch by: Steve Fink <sphink gmail com> * docs/manual/appendix-checklist.xml: Mention less -R switch in the section about debug output (#474055).