term: rewrite _term_it_send_csi

Instead of asynchronously printing the sequence as we render it,
construct it once and then write it out synchronously.
This commit is contained in:
fang 2021-03-13 02:15:02 +01:00
parent d355d3b71c
commit 23ec162c2f
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972

View File

@ -433,24 +433,31 @@ _term_it_send_csi(u3_utty *uty_u, c3_c cmd_c, c3_w num_w, ...)
va_list ap; va_list ap;
va_start(ap, num_w); va_start(ap, num_w);
uv_buf_t esc_u = TERM_LIT_BUF("\033["); // allocate for escape sequence (2), command char (1),
_term_it_dump_buf(uty_u, &esc_u); // argument digits (5 per arg) and separators (1 per arg, minus 1).
// freed via _term_it_write.
//
c3_c* pas_c = malloc( sizeof(*pas_c) * (2 + num_w * 6) );
c3_c was_c = 0;
pas_c[was_c++] = '\033';
pas_c[was_c++] = '[';
uv_buf_t sep_u = TERM_LIT_BUF(";"); //REVIEW re-use works fine, but is it?
while ( num_w > 0 ) { while ( num_w > 0 ) {
c3_w par_w = va_arg(ap, c3_w); c3_w par_w = va_arg(ap, c3_w);
c3_c pas_c[5]; was_c += sprintf(pas_c+was_c, "%d", par_w);
c3_c was_c = sprintf(pas_c, "%d", par_w);
uv_buf_t pas_u = uv_buf_init(pas_c, was_c);
_term_it_dump_buf(uty_u, &pas_u);
if ( --num_w > 0 ) { if ( --num_w > 0 ) {
_term_it_dump_buf(uty_u, &sep_u); pas_c[was_c++] = ';';
} }
} }
uv_buf_t cmd_u = uv_buf_init(&cmd_c, 1); pas_c[was_c++] = cmd_c;
_term_it_dump_buf(uty_u, &cmd_u);
uv_buf_t pas_u = uv_buf_init(pas_c, was_c);
_term_it_write(uty_u, &pas_u, pas_c);
va_end(ap);
} }
/* _term_it_free_line(): wipe line stored by _term_it_save_line /* _term_it_free_line(): wipe line stored by _term_it_save_line