4th try at getting ansi colors working with a default of color=yes_please.
Colors will only be used if the TERM env var is set and NO_COLOR is not set. Originally committed as revision 22957 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
0bb848016a
commit
6204402409
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "avutil.h"
|
#include "avutil.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
@ -33,17 +34,23 @@ static
|
|||||||
#endif
|
#endif
|
||||||
int av_log_level = AV_LOG_INFO;
|
int av_log_level = AV_LOG_INFO;
|
||||||
|
|
||||||
#if (!HAVE_ISATTY) || defined(_WIN32)
|
static int use_ansi_color=-1;
|
||||||
#define isatty(s) 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef fprintf
|
#undef fprintf
|
||||||
static void colored_fputs(int color, const char *str){
|
static void colored_fputs(int color, const char *str){
|
||||||
if(isatty(2)){
|
if(use_ansi_color<0){
|
||||||
|
#if HAVE_ISATTY && !defined(_WIN32)
|
||||||
|
use_ansi_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2);
|
||||||
|
#else
|
||||||
|
use_ansi_color= 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if(use_ansi_color){
|
||||||
fprintf(stderr, "\033[%d;3%dm", color>>4, color&15);
|
fprintf(stderr, "\033[%d;3%dm", color>>4, color&15);
|
||||||
}
|
}
|
||||||
fputs(str, stderr);
|
fputs(str, stderr);
|
||||||
if(isatty(2)){
|
if(use_ansi_color){
|
||||||
fprintf(stderr, "\033[0m");
|
fprintf(stderr, "\033[0m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user