summaryrefslogtreecommitdiffstats
path: root/mp_msg.c
diff options
context:
space:
mode:
Diffstat (limited to 'mp_msg.c')
-rw-r--r--mp_msg.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/mp_msg.c b/mp_msg.c
index d9c28688a4..627ee04187 100644
--- a/mp_msg.c
+++ b/mp_msg.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <unistd.h>
#include "config.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_level_all = MSGL_STATUS;
int verbose = 0;
-int mp_msg_color = 0;
+int mp_msg_color = 1;
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){
#ifdef _WIN32
@@ -74,18 +80,19 @@ void mp_msg_init(void){
stdoutAttrs = cinfo.wAttributes;
#endif
int i;
- char *env = getenv("MPLAYER_VERBOSE");
+ char *env = getenv("MPV_VERBOSE");
if (env)
verbose = atoi(env);
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
#ifdef CONFIG_TRANSLATION
- textdomain("mplayer");
- char *localedir = getenv("MPLAYER_LOCALEDIR");
+ textdomain("mpv");
+ char *localedir = getenv("MPV_LOCALEDIR");
if (localedir == NULL && strlen(MPLAYER_LOCALEDIR))
localedir = MPLAYER_LOCALEDIR;
- bindtextdomain("mplayer", localedir);
- bind_textdomain_codeset("mplayer", "UTF-8");
+ bindtextdomain("mpv", localedir);
+ bind_textdomain_codeset("mpv", "UTF-8");
#endif
}
@@ -96,7 +103,7 @@ int mp_msg_test(int mod, int lev)
static void set_msg_color(FILE* stream, int lev)
{
- static const unsigned char v_colors[10] = {9, 1, 3, 15, 7, 2, 2, 8, 8, 8};
+ static const unsigned char v_colors[10] = {9, 1, 3, 15, 7, 7, 2, 8, 8, 8};
int c = v_colors[lev];
#ifdef MP_ANNOY_ME
/* that's only a silly color test */
@@ -109,7 +116,7 @@ static void set_msg_color(FILE* stream, int lev)
flag = 0;
}
#endif
- if (mp_msg_color)
+ if (mp_msg_docolor())
{
#ifdef _WIN32
HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
@@ -176,16 +183,16 @@ static void print_msg_module(FILE* stream, int mod)
return;
#ifdef _WIN32
HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
- if (mp_msg_color)
+ if (mp_msg_docolor())
SetConsoleTextAttribute(wstream, ansi2win32[c2&7] | FOREGROUND_INTENSITY);
fprintf(stream, "%9s", module_text[mod]);
- if (mp_msg_color)
+ if (mp_msg_docolor())
SetConsoleTextAttribute(wstream, stdoutAttrs);
#else
- if (mp_msg_color)
+ if (mp_msg_docolor())
fprintf(stream, "\033[%d;3%dm", c2 >> 3, c2 & 7);
fprintf(stream, "%9s", module_text[mod]);
- if (mp_msg_color)
+ if (mp_msg_docolor())
fprintf(stream, "\033[0;37m");
#endif
fprintf(stream, ": ");
@@ -194,7 +201,7 @@ static void print_msg_module(FILE* stream, int mod)
void mp_msg_va(int mod, int lev, const char *format, va_list va)
{
char tmp[MSGSIZE_MAX];
- FILE *stream = lev <= MSGL_WARN ? stderr : stdout;
+ FILE *stream = lev == MSGL_STATUS ? stderr : stdout;
static int header = 1;
// indicates if last line printed was a status line
static int statusline;
@@ -208,7 +215,7 @@ void mp_msg_va(int mod, int lev, const char *format, va_list va)
* status line, and does not end with a '\n'. If we're printing a normal
* line instead after the status one print '\n' to change line. */
if (statusline && lev != MSGL_STATUS)
- fprintf(stream, "\n");
+ fprintf(stderr, "\n");
statusline = lev == MSGL_STATUS;
if (header)
@@ -220,7 +227,7 @@ void mp_msg_va(int mod, int lev, const char *format, va_list va)
fprintf(stream, "%s", tmp);
- if (mp_msg_color)
+ if (mp_msg_docolor())
{
#ifdef _WIN32
HANDLE *wstream = lev <= MSGL_WARN ? hSTDERR : hSTDOUT;