Permalink
Browse files

terminal: pretty print modules for --msgmodule

  • Loading branch information...
EvanPurkhiser authored and wm4 committed Apr 10, 2014
1 parent 2370ef9 commit 5cfb180a8957f9f2fefbec3cd4e7dddf8d856896
Showing with 26 additions and 2 deletions.
  1. +26 −2 common/msg.c
View
@@ -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');

0 comments on commit 5cfb180

Please sign in to comment.