Skip to content

Commit

Permalink
msg: clear status line only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper93 committed May 19, 2024
1 parent 895dd9e commit a16f653
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion common/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ static inline FILE *term_msg_fp(struct mp_log_root *root, int lev)
return term_msg_fileno(root, lev) == STDERR_FILENO ? stderr : stdout;
}

static inline bool is_status_output(struct mp_log_root *root, int lev)
{
if (lev == MSGL_STATUS)
return true;
int msg_out = term_msg_fileno(root, lev);
int status_out = term_msg_fileno(root, MSGL_STATUS);
if (msg_out != status_out && root->isatty[msg_out] != root->isatty[status_out])
return false;
return true;
}

// Reposition cursor and clear lines for outputting the status line. In certain
// cases, like term OSD and subtitle display, the status can consist of
// multiple lines.
Expand All @@ -210,6 +221,9 @@ static void prepare_prefix(struct mp_log_root *root, bstr *out, int lev, int ter
int new_lines = lev == MSGL_STATUS ? term_lines : 0;
out->len = 0;

if (!is_status_output(root, lev))
return;

if (!root->isatty[term_msg_fileno(root, lev)]) {
if (root->status_lines)
bstr_xappend(root, out, bstr0("\n"));
Expand Down Expand Up @@ -563,7 +577,7 @@ void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va)

root->term_status_msg.len = 0;
if (lev != MSGL_STATUS && root->status_line.len && root->status_log &&
test_terminal_level(root->status_log, MSGL_STATUS))
is_status_output(root, lev) && test_terminal_level(root->status_log, MSGL_STATUS))
{
write_term_msg(root->status_log, MSGL_STATUS, root->status_line,
&root->term_status_msg);
Expand Down

0 comments on commit a16f653

Please sign in to comment.