mirror of
https://github.com/mpv-player/mpv
synced 2025-03-01 03:40:43 +00:00
mp_msg: enable --msgcolor by default; force it off if stdout is no tty
This commit is contained in:
parent
65adad50ab
commit
2f1bc6beb6
21
mp_msg.c
21
mp_msg.c
@ -20,6 +20,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "osdep/getch2.h"
|
#include "osdep/getch2.h"
|
||||||
@ -59,8 +60,13 @@ static const unsigned char ansi2win32[10] = {
|
|||||||
int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized to -2
|
int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized to -2
|
||||||
int mp_msg_level_all = MSGL_STATUS;
|
int mp_msg_level_all = MSGL_STATUS;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
int mp_msg_color = 0;
|
int mp_msg_color = 1;
|
||||||
int mp_msg_module = 0;
|
int mp_msg_module = 0;
|
||||||
|
int mp_msg_cancolor = 0;
|
||||||
|
|
||||||
|
static int mp_msg_docolor(void) {
|
||||||
|
return mp_msg_cancolor && mp_msg_color;
|
||||||
|
}
|
||||||
|
|
||||||
void mp_msg_init(void){
|
void mp_msg_init(void){
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -78,6 +84,7 @@ void mp_msg_init(void){
|
|||||||
if (env)
|
if (env)
|
||||||
verbose = atoi(env);
|
verbose = atoi(env);
|
||||||
for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2;
|
for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2;
|
||||||
|
mp_msg_cancolor = isatty(fileno(stdout));
|
||||||
mp_msg_levels[MSGT_IDENTIFY] = -1; // no -identify output by default
|
mp_msg_levels[MSGT_IDENTIFY] = -1; // no -identify output by default
|
||||||
#ifdef CONFIG_TRANSLATION
|
#ifdef CONFIG_TRANSLATION
|
||||||
textdomain("mplayer");
|
textdomain("mplayer");
|
||||||
@ -109,7 +116,7 @@ static void set_msg_color(FILE* stream, int lev)
|
|||||||
flag = 0;
|
flag = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (mp_msg_color)
|
if (mp_msg_docolor())
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
|
HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
|
||||||
@ -176,16 +183,16 @@ static void print_msg_module(FILE* stream, int mod)
|
|||||||
return;
|
return;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
|
HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
|
||||||
if (mp_msg_color)
|
if (mp_msg_docolor())
|
||||||
SetConsoleTextAttribute(wstream, ansi2win32[c2&7] | FOREGROUND_INTENSITY);
|
SetConsoleTextAttribute(wstream, ansi2win32[c2&7] | FOREGROUND_INTENSITY);
|
||||||
fprintf(stream, "%9s", module_text[mod]);
|
fprintf(stream, "%9s", module_text[mod]);
|
||||||
if (mp_msg_color)
|
if (mp_msg_docolor())
|
||||||
SetConsoleTextAttribute(wstream, stdoutAttrs);
|
SetConsoleTextAttribute(wstream, stdoutAttrs);
|
||||||
#else
|
#else
|
||||||
if (mp_msg_color)
|
if (mp_msg_docolor())
|
||||||
fprintf(stream, "\033[%d;3%dm", c2 >> 3, c2 & 7);
|
fprintf(stream, "\033[%d;3%dm", c2 >> 3, c2 & 7);
|
||||||
fprintf(stream, "%9s", module_text[mod]);
|
fprintf(stream, "%9s", module_text[mod]);
|
||||||
if (mp_msg_color)
|
if (mp_msg_docolor())
|
||||||
fprintf(stream, "\033[0;37m");
|
fprintf(stream, "\033[0;37m");
|
||||||
#endif
|
#endif
|
||||||
fprintf(stream, ": ");
|
fprintf(stream, ": ");
|
||||||
@ -220,7 +227,7 @@ void mp_msg_va(int mod, int lev, const char *format, va_list va)
|
|||||||
|
|
||||||
fprintf(stream, "%s", tmp);
|
fprintf(stream, "%s", tmp);
|
||||||
|
|
||||||
if (mp_msg_color)
|
if (mp_msg_docolor())
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE *wstream = lev <= MSGL_WARN ? hSTDERR : hSTDOUT;
|
HANDLE *wstream = lev <= MSGL_WARN ? hSTDERR : hSTDOUT;
|
||||||
|
Loading…
Reference in New Issue
Block a user