diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2024-03-15 09:52:04 +0100 |
---|---|---|
committer | Kacper Michajłow <kasper93@gmail.com> | 2024-03-21 01:47:15 +0100 |
commit | 17a0756ed3536a9b8aa60adaa92859a0dba060ad (patch) | |
tree | 1add30b32a8142676c02f60bac3e16606c0cb8fc /common | |
parent | 188155457dc95b02d09265175b82acc484a4cd40 (diff) | |
download | mpv-17a0756ed3536a9b8aa60adaa92859a0dba060ad.tar.bz2 mpv-17a0756ed3536a9b8aa60adaa92859a0dba060ad.tar.xz |
msg: simplify the line_skip calculation
Make it more straightforward by always calculating top offset first
instead of having two branches, that tries to calc it directly.
This also fixes missing negative check before `\033[%dA` which was in
practice only problem on macOS which was handling negative values, while
in fact it shouldn't.
Fixes: #13484
Diffstat (limited to 'common')
-rw-r--r-- | common/msg.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/common/msg.c b/common/msg.c index 0d77fcc624..52550e9b62 100644 --- a/common/msg.c +++ b/common/msg.c @@ -228,21 +228,15 @@ static void prepare_prefix(struct mp_log_root *root, bstr *out, int lev, int ter bstr up_clear = bstr0("\033[A\033[K"); for (int i = 1; i < root->status_lines; ++i) bstr_xappend(root, out, up_clear); - // Reposition cursor after last message - line_skip = (new_lines ? new_lines : root->blank_lines) - root->status_lines; - line_skip = MPMIN(root->blank_lines - root->status_lines, line_skip); - if (line_skip) - bstr_xappend_asprintf(root, out, "\033[%dA", line_skip); - } else if (new_lines) { - line_skip = new_lines - root->blank_lines; + assert(root->status_lines > 0 && root->blank_lines >= root->status_lines); + line_skip = root->blank_lines - root->status_lines; } - if (line_skip < 0) { - // Reposition cursor to keep status line at the same line - line_skip = MPMIN(root->blank_lines, -line_skip); - if (line_skip) - bstr_xappend_asprintf(root, out, "\033[%dB", line_skip); - } + if (new_lines) + line_skip -= MPMAX(0, root->blank_lines - new_lines); + + if (line_skip) + bstr_xappend_asprintf(root, out, line_skip > 0 ? "\033[%dA" : "\033[%dB", abs(line_skip)); root->blank_lines = MPMAX(0, root->blank_lines - term_lines); root->status_lines = new_lines; |