From 6183f7f64a10465b429f70c713102ced2e0517bc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 16 Jul 2020 07:41:51 +0200 Subject: vt: utf8: handle multi-column spacer values correctly when combining --- vt.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'vt.c') diff --git a/vt.c b/vt.c index 618611c6..feac9040 100644 --- a/vt.c +++ b/vt.c @@ -540,15 +540,12 @@ action_utf8_print(struct terminal *term, wchar_t wc) if (!term->grid->cursor.lcf) base_col--; + while (row->cells[base_col].wc == CELL_MULT_COL_SPACER && base_col > 0) + base_col--; + assert(base_col >= 0 && base_col < term->cols); wchar_t base = row->cells[base_col].wc; - /* Handle double-column glyphs */ - if (base == 0 && base_col > 0) { - base_col--; - base = row->cells[base_col].wc; - } - const struct composed *composed = (base >= CELL_COMB_CHARS_LO && base < (CELL_COMB_CHARS_LO + term->composed_count)) -- cgit v1.3 From 9508804b18270ab47c750dc61a16384297c06aa7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 16 Jul 2020 08:01:37 +0200 Subject: vt: ignore 0x7f (DEL) in ground state This ensures *all* bytes mapped to action_print() have wcwidth == 1. DEL has wcwidth == -1, and would thus have been ignored by term_print() anwyway. --- vt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'vt.c') diff --git a/vt.c b/vt.c index feac9040..148f2aae 100644 --- a/vt.c +++ b/vt.c @@ -223,6 +223,8 @@ action_print(struct terminal *term, uint8_t c) L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */ }; + assert(wcwidth(c) == 1); + if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) && c >= 0x60 && c <= 0x7e) { @@ -739,7 +741,8 @@ state_ground_switch(struct terminal *term, uint8_t data) case 0x19: case 0x1c ... 0x1f: action_execute(term, data); return STATE_GROUND; - case 0x20 ... 0x7f: action_print(term, data); return STATE_GROUND; + /* modified from 0x20..0x7f to 0x20..0x7e, since 0x7f is DEL, which is a zero-width character */ + case 0x20 ... 0x7e: action_print(term, data); return STATE_GROUND; case 0xc2 ... 0xdf: action_utf8_21(term, data); return STATE_UTF8_21; case 0xe0 ... 0xef: action_utf8_31(term, data); return STATE_UTF8_31; -- cgit v1.3 From 6f2cffd8c0949c2dfa1499c5d0c2594eb645ac26 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 16 Jul 2020 08:04:12 +0200 Subject: vt: never call term_print() with a width <= 0 --- terminal.c | 3 +-- vt.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'vt.c') diff --git a/terminal.c b/terminal.c index 84c9d459..554aa8b2 100644 --- a/terminal.c +++ b/terminal.c @@ -2401,8 +2401,7 @@ print_spacer(struct terminal *term, int col) void term_print(struct terminal *term, wchar_t wc, int width) { - if (unlikely(width <= 0)) - return; + assert(width > 0); print_linewrap(term); print_insert(term, width); diff --git a/vt.c b/vt.c index 148f2aae..f25f26be 100644 --- a/vt.c +++ b/vt.c @@ -663,7 +663,8 @@ action_utf8_print(struct terminal *term, wchar_t wc) } } - term_print(term, wc, width); + if (width > 0) + term_print(term, wc, width); } static void -- cgit v1.3