Skip to content

Commit

Permalink
msg: add newline conditionally
Browse files Browse the repository at this point in the history
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: bf025cd
  • Loading branch information
kasper93 committed Oct 21, 2024
1 parent 0f78584 commit 3cf0f83
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions common/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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["));

Expand All @@ -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)
Expand Down

0 comments on commit 3cf0f83

Please sign in to comment.