[FFmpeg-devel] [PATCH] add colours to warnings and errors

Michael Niedermayer michaelni
Sun Apr 25 00:00:25 CEST 2010


On Sat, Apr 24, 2010 at 11:35:31PM +0200, James Darnley wrote:
> On 24 April 2010 23:18, Michael Niedermayer <michaelni at gmx.at> wrote:
> > On Sat, Apr 24, 2010 at 03:03:58AM +0200, James Darnley wrote:
> >> Attached is hopefully the final revision.
> >> It should not alter the behavior when _WIN32 is not defined at compile time.
> >> When it is, colour will be printed in:
> >> ?- "plain" cmd.exe
> >> ?- cygwin and msys cmd.exe terminals when "tty" is not in the CYGWIN
> >> environment variable
> >>
> >> Other terminals in which you might run a native Windows executable
> >> look like they are SOL. ?If they get changed so that isatty() returns
> >> true when you would expect it to then they should start working
> >> without any change to ffmpeg.
> >>
> >> If someone wanted to try and make a hack for isatty() then I suggest
> >> this as a starting point:
> >> http://www.cygwin.com/ml/cygwin/2007-03/msg00663.html
> >> Some state of the stderr pipe might let you find if it is attached to
> >> a cygwin tty. ?I tried to recreate that myself but I wasn't very
> >> successful. ?I also think that I showed that you can't know whether it
> >> is rxvt or another program using the pipe, perl or python for example.
> >
> >> ?log.c | ? 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >> ?1 file changed, 69 insertions(+)
> >> 7b72f819a31ca8429b43432c8a57be878f1ea3ec ?colours.diff
> >> Index: libavutil/log.c
> >> ===================================================================
> >> --- libavutil/log.c ? (revision 22957)
> >> +++ libavutil/log.c ? (working copy)
> >> @@ -24,6 +24,10 @@
> >> ? * logging functions
> >> ? */
> >>
> >> +#ifdef _WIN32
> >> +#include <windows.h>
> >> +#include <string.h>
> >> +#endif
> >> ?#include <unistd.h>
> >> ?#include <stdlib.h>
> >> ?#include "avutil.h"
> >> @@ -35,9 +39,73 @@
> >> ?int av_log_level = AV_LOG_INFO;
> >>
> >> ?static int use_ansi_color=-1;
> >
> >> +#ifdef _WIN32
     ^^^^^^^^^^^^^
> >> +static int use_win_color=-1;
> >> +static int16_t attr, attr_orig;
> >> +static HANDLE con;
> >> +#endif
> >>
> >> +/* FIXME: On Windows isatty() returns true when ANSI color codes won't work.
> >> +Some hack to detect output to other terminals would be good, fixing the other
> >> +terminals would be better. One probable exception is when the user has
> >> +ANSI.SYS loaded but the Windows API should then still work. */
> >> +
> >> ?#undef fprintf
> >> ?static void colored_fputs(int color, const char *str){
> >> +#ifdef _WIN32
      ^^^^^^^^^^^^^
> >
> > these 2 ifdefs can be merged
> >
> 
> I'm sorry... Which two can be merged?  The header includes, the

marked above
the static variables can be inside the function


> variables or the one after the function declaration?
> 
> >
> > ? ?if(use_win_color){
> > ? ?...
> > ? ?}else
> > #else
> > ? ?{
> > ? ? ? ?if(use_ansi_color<0){
> > ? ?#if HAVE_ISATTY && !defined(_WIN32)
> > ? ? ? ? ? ?use_ansi_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2);
> > @@ -53,6 +121,7 @@
> > ? ? ? ?if(use_ansi_color){
> > ? ? ? ? ? ?fprintf(stderr, "\033[0m");
> > ? ? ? ?}
> > ? ?}
> > #endif
> >
> 
> Was this a hint that you want if(use_win_color) before if(use_ansi_color)?

no, i just meant to reduce the ifdefery and reduce the duplication of the
ansi printing


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100425/5c4bdc10/attachment.pgp>



More information about the ffmpeg-devel mailing list