Revision 4855f867 libavutil/log.c

View differences:

libavutil/log.c
34 34
#endif
35 35
int av_log_level = AV_LOG_INFO;
36 36

  
37
#ifdef _WIN32
38
#include <windows.h>
39
static const uint8_t color[] = {12,12,12,14,7,7,7};
40
static int16_t background, attr_orig;
41
static HANDLE con;
42
#define set_color(x)  SetConsoleTextAttribute(con, background | color[level])
43
#define reset_color() SetConsoleTextAttribute(con, attr_orig)
44
#else
37 45
static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9};
46
#define set_color(x)  fprintf(stderr, "\033[%d;3%dm", color[x]>>4, color[x]&15)
47
#define reset_color() fprintf(stderr, "\033[0m")
48
#endif
38 49
static int use_color=-1;
39 50

  
40 51
#undef fprintf
41 52
static void colored_fputs(int level, const char *str){
42 53
    if(use_color<0){
43
#if HAVE_ISATTY && !defined(_WIN32)
54
#ifdef _WIN32
55
        CONSOLE_SCREEN_BUFFER_INFO con_info;
56
        con = GetStdHandle(STD_ERROR_HANDLE);
57
        use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR");
58
        if (use_color) {
59
            GetConsoleScreenBufferInfo(con, &con_info);
60
            attr_orig  = con_info.wAttributes;
61
            background = attr_orig & 0xF0;
62
        }
63
#elif HAVE_ISATTY
44 64
        use_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2);
45 65
#else
46 66
        use_color= 0;
......
48 68
    }
49 69

  
50 70
    if(use_color){
51
        fprintf(stderr, "\033[%d;3%dm", color[level]>>4, color[level]&15);
71
        set_color(level);
52 72
    }
53 73
    fputs(str, stderr);
54 74
    if(use_color){
55
        fprintf(stderr, "\033[0m");
75
        reset_color();
56 76
    }
57 77
}
58 78

  

Also available in: Unified diff