summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorEvan Purkhiser <evanpurkhiser@gmail.com>2014-04-10 04:01:38 -0400
committerwm4 <wm4@nowhere>2014-04-12 11:37:53 +0200
commit5cfb180a8957f9f2fefbec3cd4e7dddf8d856896 (patch)
tree767db0c440068394cd9a8d0faa3b5b9fbbdd06c6 /common
parent2370ef9d22aeaaeb34910826dbed5a852f957af7 (diff)
downloadmpv-5cfb180a8957f9f2fefbec3cd4e7dddf8d856896.tar.bz2
mpv-5cfb180a8957f9f2fefbec3cd4e7dddf8d856896.tar.xz
terminal: pretty print modules for --msgmodule
Diffstat (limited to 'common')
-rw-r--r--common/msg.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/common/msg.c b/common/msg.c
index a8ff492e7a..6f6194f468 100644
--- a/common/msg.c
+++ b/common/msg.c
@@ -204,6 +204,25 @@ static void set_msg_color(FILE* stream, int lev)
terminal_set_foreground_color(stream, v_colors[lev]);
}
+static void pretty_print_module(FILE* stream, const char *prefix, bool use_color, int lev)
+{
+ // Use random color based on the name of the module
+ if (use_color) {
+ size_t prefix_len = strlen(prefix);
+ unsigned int mod = 0;
+ for (int i = 0; i < prefix_len; ++i)
+ mod = mod * 33 + prefix[i];
+ terminal_set_foreground_color(stream, (mod + 1) % 15 + 1);
+ }
+
+ fprintf(stream, "%10s", prefix);
+ if (use_color)
+ terminal_set_foreground_color(stream, -1);
+ fprintf(stream, ": ");
+ if (use_color)
+ set_msg_color(stream, lev);
+}
+
static void print_msg_on_terminal(struct mp_log *log, int lev, char *text)
{
struct mp_log_root *root = log->root;
@@ -246,8 +265,13 @@ static void print_msg_on_terminal(struct mp_log *log, int lev, char *text)
if (header) {
if (root->show_time)
fprintf(stream, "[%" PRId64 "] ", mp_time_us());
- if (prefix)
- fprintf(stream, "[%s] ", prefix);
+
+ if (prefix) {
+ if (root->module)
+ pretty_print_module(stream, prefix, root->color, lev);
+ else if (root->verbose)
+ fprintf(stream, "[%s] ", prefix);
+ }
}
char *next = strchr(text, '\n');