msg: add newline conditionally

In idle mode, there is not status line and we sometimes want to have
output without last new line, which were always added after truncation.

Also, make sure we don't overwrite important chars with ellipsis, this
could happen when cut point is near the end.

Fixes: bf025cd289
This commit is contained in:
Kacper Michajłow 2024-10-20 20:40:02 +02:00
parent 0f78584518
commit 3cf0f8309f
1 changed files with 8 additions and 4 deletions

View File

@ -401,12 +401,17 @@ static void append_terminal_line(struct mp_log *log, int lev,
term_w - ellipsis_width, &cut_pos);
if (cut_pos) {
int new_len = cut_pos - term_msg->start;
bstr rem = {(unsigned char *)cut_pos, term_msg->len - new_len};
bstr rem = bstrdup(NULL, (bstr){(unsigned char *)cut_pos, term_msg->len - new_len});
void *ptr = rem.start;
term_msg->len = new_len;
bstr_xappend(root, term_msg, bstr0(".."));
while (rem.len) {
if (bstr_eatstart0(&rem, "\n")) {
bstr_xappend(root, term_msg, bstr0("\n"));
continue;
}
if (bstr_eatstart0(&rem, "\033[")) {
bstr_xappend(root, term_msg, bstr0("\033["));
@ -418,12 +423,11 @@ static void append_terminal_line(struct mp_log *log, int lev,
}
rem = bstr_cut(rem, 1);
}
talloc_free(ptr);
bstr_xappend(root, term_msg, bstr0("\n"));
width += ellipsis_width;
}
*line_w = root->isatty[term_msg_fileno(root, lev)]
? width : 0;
*line_w = root->isatty[term_msg_fileno(root, lev)] ? width : 0;
}
static struct mp_log_buffer_entry *log_buffer_read(struct mp_log_buffer *buffer)