[FFmpeg-devel] [PATCH] add colours to warnings and errors
Michael Niedermayer
michaelni
Sun May 2 12:01:14 CEST 2010
On Tue, Apr 27, 2010 at 12:56:50AM +0200, James Darnley wrote:
> 2010/4/27 M?ns Rullg?rd <mans at mansr.com>:
> > James Darnley <james.darnley at gmail.com> writes:
> >
> >> 2010/4/27 M?ns Rullg?rd <mans at mansr.com>:
> >>> James Darnley <james.darnley at gmail.com> writes:
> >>>
> >>>> Right. ?See attached
> >>>>
> >>>> Index: libavutil/log.c
> >>>> ===================================================================
> >>>> --- libavutil/log.c ? (revision 22960)
> >>>> +++ 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"
> >>>> @@ -34,18 +38,76 @@
> >>>> ?#endif
> >>>> ?int av_log_level = AV_LOG_INFO;
> >>>>
> >>>> +/* 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. */
> >>>
> >>> You still have a FIXME here. ?That's not acceptable.
> >>
> >> I'll delete it then if that'll satisfy you. ?Or would you prefer the
> >> whole text to be gone.
> >
> > I want the hack to be gone.
> >
>
> What hack would that be?
>
> >> Then people will just be unaware of this limitation. ?Perhaps you
> >> want the ansi-color-on-windows gone too since at present it will
> >> never get used.
> >
> > Code that will never run has no place in FFmpeg.
> >
>
> Gone
> log.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 47 insertions(+), 1 deletion(-)
> 696d0230dbc0bcaeb45e8b857060ac1167c02313 colours.diff
> Index: libavutil/log.c
> ===================================================================
> --- libavutil/log.c (revision 22960)
> +++ 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"
> @@ -38,14 +42,56 @@
>
> #undef fprintf
> static void colored_fputs(int color, const char *str){
> +#ifdef _WIN32
> + static int use_win_color=-1;
> + static int16_t attr, attr_orig;
> + static HANDLE console;
> + static const int16_t win_color_conv[] = {
> + 0,
> + FOREGROUND_RED,
> + FOREGROUND_GREEN,
> + FOREGROUND_RED |FOREGROUND_GREEN,
> + FOREGROUND_BLUE,
> + FOREGROUND_RED |FOREGROUND_BLUE,
> + FOREGROUND_GREEN|FOREGROUND_BLUE,
> + FOREGROUND_RED |FOREGROUND_GREEN|FOREGROUND_BLUE
> + };
> +
> + use_ansi_color = 0;
> + if (use_win_color<0) {
> + CONSOLE_SCREEN_BUFFER_INFO con_info;
> +
> + console = GetStdHandle( STD_ERROR_HANDLE );
> + if (console != INVALID_HANDLE_VALUE) {
> + GetConsoleScreenBufferInfo( console, &con_info );
> + attr_orig = con_info.wAttributes;
> +
> + attr = attr_orig&0xF0;
> + attr |= (attr_orig&BACKGROUND_INTENSITY) ? 0 : FOREGROUND_INTENSITY;
> +
> + use_win_color = 1;
> + } else
> + use_win_color = 0;
> + }
> +
> + if (use_win_color) {
> + SetConsoleTextAttribute( console,
> + (color&15)==9 ? attr_orig : attr|win_color_conv[color&15]
> + );
> + fputs(str, stderr);
> + SetConsoleTextAttribute( console, attr_orig );
> + return;
> + }
> +#else
> if(use_ansi_color<0){
> -#if HAVE_ISATTY && !defined(_WIN32)
> +#if HAVE_ISATTY
> use_ansi_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2);
> #else
> use_ansi_color= 0;
> #endif
> }
>
> +#endif
> if(use_ansi_color){
> fprintf(stderr, "\033[%d;3%dm", color>>4, color&15);
> }
This patch now makes ansi and win32 exclusive so that ansi is not possible
on win32 anymore.
Is this intended?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- 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/20100502/1472bb2b/attachment.pgp>
More information about the ffmpeg-devel
mailing list