diff options
author | wm4 <wm4@nowhere> | 2014-01-16 21:23:27 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-01-16 23:06:40 +0100 |
commit | 5b14db5ab1be11f905fbc4afe7fc2e9ff5c29a81 (patch) | |
tree | 8f4f18136e45e592fa5256daaf7f61caa5b16909 /common | |
parent | 26d6eb4a8ab4052d7f873ca0cc2c6b68f3d41a44 (diff) |
msg: print module prefixes even if message contains newlines
This makes
mp_msg(x, y, "a\nb\n")
behave the same as
mp_msg(x, y, "a\n")
mp_msg(x, y, "b\n")
which is probably what one would expect. Before this commit, the "b"
line didn't have a prefix when using ths single mp_msg call.
Diffstat (limited to 'common')
-rw-r--r-- | common/msg.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/common/msg.c b/common/msg.c index 76d2f95872..32bbe8e89e 100644 --- a/common/msg.c +++ b/common/msg.c @@ -197,13 +197,18 @@ void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va) snprintf(tmp, MSGSIZE_MAX, "[fprintf error]\n"); tmp[MSGSIZE_MAX - 2] = '\n'; tmp[MSGSIZE_MAX - 1] = 0; + char *text = tmp; bool header = root->header; - char *terminate = ""; + const char *prefix = log->prefix; + char *terminate = NULL; + + if ((lev >= MSGL_V && lev != MSGL_SMODE) || root->verbose || root->module) + prefix = log->verbose_prefix; if (lev == MSGL_STATUS) { if (root->termosd) { - prepare_status_line(root, tmp); + prepare_status_line(root, text); terminate = "\r"; } else { terminate = "\n"; @@ -211,21 +216,27 @@ void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va) root->header = true; } else { flush_status_line(root); - size_t len = strlen(tmp); - root->header = len && tmp[len - 1] == '\n'; + size_t len = strlen(text); + root->header = len && text[len - 1] == '\n'; } if (root->color) set_msg_color(stream, lev); - if (header) { - if ((lev >= MSGL_V && lev != MSGL_SMODE) || root->verbose || root->module) { - fprintf(stream, "[%s] ", log->verbose_prefix); - } else if (log->prefix) { - fprintf(stream, "[%s] ", log->prefix); - } - } - fprintf(stream, "%s%s", tmp, terminate); + do { + if (header && prefix) + fprintf(stream, "[%s] ", prefix); + + char *next = strchr(text, '\n'); + int len = next ? next - text + 1 : strlen(text); + fprintf(stream, "%.*s", len, text); + text = text + len; + + header = true; + } while (text[0]); + + if (terminate) + fprintf(stream, "%s", terminate); if (root->color) terminal_set_foreground_color(stream, -1); |