log: Factorize check_color_terminal() out

This commit is contained in:
Luca Barbato 2013-04-26 15:12:05 +02:00 committed by Michael Niedermayer
parent 4169d8f601
commit 061e340c05
1 changed files with 25 additions and 22 deletions

View File

@ -113,12 +113,8 @@ 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);
@ -131,8 +127,7 @@ static void colored_fputs(int level, const char *str)
}
#elif HAVE_ISATTY
use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") &&
(getenv("TERM") && isatty(2) ||
getenv("AV_LOG_FORCE_COLOR"));
(getenv("TERM") && isatty(2) || getenv("AV_LOG_FORCE_COLOR"));
if (getenv("AV_LOG_FORCE_256COLOR"))
use_color *= 256;
#else
@ -141,6 +136,14 @@ static void colored_fputs(int level, const char *str)
#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)
SetConsoleTextAttribute(con, background | color[level]);