Showing the changes to common (2 of 9 files). Show all
Unified · Split
| @@ -374,7 +374,7 @@ static bool test_terminal_level(struct mp_log *log, int lev) · 373 unmodified lines | ||
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | static void append_terminal_line(struct mp_log *log, int lev, |
| 377 | − bstr text, bstr *term_msg, int *line_w) | |
| 377 | + bstr text, bstr *term_msg, int *line_w, int term_w) | |
| 378 | 378 | { |
| 379 | 379 | struct mp_log_root *root = log->root; |
| 380 | 380 | |
| @@ -394,8 +394,35 @@ static void append_terminal_line(struct mp_log *log, int lev, · 13 unmodified lines | ||
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | bstr_xappend(root, term_msg, text); |
| 397 | + | |
| 398 | + const unsigned char *cut_pos = NULL; | |
| 399 | + int width = term_disp_width(bstr_splice(*term_msg, start, term_msg->len), | |
| 400 | + term_w - 3, &cut_pos); | |
| 401 | + if (cut_pos) { | |
| 402 | + int new_len = cut_pos - term_msg->start; | |
| 403 | + bstr rem = {(unsigned char *)cut_pos, term_msg->len - new_len}; | |
| 404 | + term_msg->len = new_len; | |
| 405 | + | |
| 406 | + bstr_xappend(root, term_msg, bstr0("...")); | |
| 407 | + | |
| 408 | + while (rem.len) { | |
| 409 | + if (bstr_eatstart0(&rem, "\033[")) { | |
| 410 | + bstr_xappend(root, term_msg, bstr0("\033[")); | |
| 411 | + | |
| 412 | + while (rem.len && !((*rem.start >= '@' && *rem.start <= '~') || *rem.start == 'm')) { | |
| 413 | + bstr_xappend(root, term_msg, bstr_splice(rem, 0, 1)); | |
| 414 | + rem = bstr_cut(rem, 1); | |
| 415 | + } | |
| 416 | + bstr_xappend(root, term_msg, bstr_splice(rem, 0, 1)); | |
| 417 | + } | |
| 418 | + rem = bstr_cut(rem, 1); | |
| 419 | + } | |
| 420 | + | |
| 421 | + bstr_xappend(root, term_msg, bstr0("\n")); | |
| 422 | + width += 3; | |
| 423 | + } | |
| 397 | 424 | *line_w = root->isatty[term_msg_fileno(root, lev)] |
| 398 | − ? term_disp_width(bstr_splice(*term_msg, start, term_msg->len)) : 0; | |
| 425 | + ? width : 0; | |
| 399 | 426 | } |
| 400 | 427 | |
| 401 | 428 | static struct mp_log_buffer_entry *log_buffer_read(struct mp_log_buffer *buffer) |
| @@ -496,7 +523,8 @@ static void write_term_msg(struct mp_log *log, int lev, bstr text, bstr *out) · 94 unmodified lines | ||
| 496 | 523 | |
| 497 | 524 | if (print_term) { |
| 498 | 525 | int line_w; |
| 499 | − append_terminal_line(log, lev, line, &root->term_msg_tmp, &line_w); | |
| 526 | + append_terminal_line(log, lev, line, &root->term_msg_tmp, &line_w, | |
| 527 | + bstr_eatstart0(&line, TERM_MSG_0) ? term_w : INT_MAX); | |
| 500 | 528 | term_msg_lines += (!line_w || !term_w) |
| 501 | 529 | ? 1 : (line_w + term_w - 1) / term_w; |
| 502 | 530 | } |
| @@ -506,7 +534,8 @@ static void write_term_msg(struct mp_log *log, int lev, bstr text, bstr *out) · 3 unmodified lines | ||
| 506 | 534 | if (lev == MSGL_STATUS) { |
| 507 | 535 | int line_w = 0; |
| 508 | 536 | if (str.len && print_term) |
| 509 | − append_terminal_line(log, lev, str, &root->term_msg_tmp, &line_w); | |
| 537 | + append_terminal_line(log, lev, str, &root->term_msg_tmp, &line_w, | |
| 538 | + bstr_eatstart0(&str, TERM_MSG_0) ? term_w : INT_MAX); | |
| 510 | 539 | term_msg_lines += !term_w ? (str.len ? 1 : 0) |
| 511 | 540 | : (line_w + term_w - 1) / term_w; |
| 512 | 541 | } else if (str.len) { |
| @@ -25,6 +25,8 @@ · 24 unmodified lines | ||
| 25 | 25 | |
| 26 | 26 | #include "osdep/compiler.h" |
| 27 | 27 | |
| 28 | +#define TERM_MSG_0 "\xFC" | |
| 29 | + | |
| 28 | 30 | struct mp_log; |
| 29 | 31 | |
| 30 | 32 | // A mp_log instance that never outputs anything. |