diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2013-04-26 15:12:05 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-04-03 20:04:34 +0200 |
commit | 061e340c05bde91ac988677e47bc562b04be5c20 (patch) | |
tree | b4270d05955bc020515548c80b0ca634a74cc427 /libavutil | |
parent | 4169d8f6014e25cf1309850526e17028034c9e72 (diff) | |
download | ffmpeg-061e340c05bde91ac988677e47bc562b04be5c20.tar.gz |
log: Factorize check_color_terminal() out
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/log.c | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/libavutil/log.c b/libavutil/log.c index a0bb5e468b..af293e724b 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -113,33 +113,36 @@ static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = { #endif static int use_color = -1; -static void colored_fputs(int level, const char *str) +static void check_color_terminal(void) { - if (!*str) - return; - - if (use_color < 0) { #if HAVE_SETCONSOLETEXTATTRIBUTE - CONSOLE_SCREEN_BUFFER_INFO con_info; - con = GetStdHandle(STD_ERROR_HANDLE); - use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && - !getenv("AV_LOG_FORCE_NOCOLOR"); - if (use_color) { - GetConsoleScreenBufferInfo(con, &con_info); - attr_orig = con_info.wAttributes; - background = attr_orig & 0xF0; - } + CONSOLE_SCREEN_BUFFER_INFO con_info; + con = GetStdHandle(STD_ERROR_HANDLE); + use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && + !getenv("AV_LOG_FORCE_NOCOLOR"); + if (use_color) { + GetConsoleScreenBufferInfo(con, &con_info); + attr_orig = con_info.wAttributes; + background = attr_orig & 0xF0; + } #elif HAVE_ISATTY - use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && - (getenv("TERM") && isatty(2) || - getenv("AV_LOG_FORCE_COLOR")); - if (getenv("AV_LOG_FORCE_256COLOR")) - use_color *= 256; + use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && + (getenv("TERM") && isatty(2) || getenv("AV_LOG_FORCE_COLOR")); + if (getenv("AV_LOG_FORCE_256COLOR")) + use_color *= 256; #else - use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && - !getenv("AV_LOG_FORCE_NOCOLOR"); + use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && + !getenv("AV_LOG_FORCE_NOCOLOR"); #endif - } +} + +static void colored_fputs(int level, const char *str) +{ + if (!*str) + return; + + if (use_color < 0) + check_color_terminal(); #if HAVE_SETCONSOLETEXTATTRIBUTE if (use_color && level != AV_LOG_INFO/8) |