From ea851962c1f4f1d30e350de3f4aa7bfbea135dcf Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 14:34:17 +0100 Subject: term: add term_put_char() This function prints a single, non-double width, character to the grid. It handles OSC-8 hyperlinks, but does not: * update the cursor location * erase sixels --- terminal.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index d9d66bac..6119f68c 100644 --- a/terminal.c +++ b/terminal.c @@ -3498,6 +3498,42 @@ print_spacer(struct terminal *term, int col, int remaining) cell->attrs = term->vt.attrs; } +/* + * Puts a character on the grid. Coordinates are in screen coordinates + * (i.e. ‘cursor’ coordinates). + * + * Does NOT: + * - update the cursor + * - linewrap + * - erase sixels + * + * Limitiations: + * - double width characters not supported + */ +void +term_put_char(struct terminal *term, int r, int c, wchar_t wc) +{ + struct row *row = grid_row(term->grid, r); + row->dirty = true; + + struct cell *cell = &row->cells[c]; + cell->wc = wc; + cell->attrs = term->vt.attrs; + + if (unlikely(term->vt.osc8.uri != NULL)) { + grid_row_uri_range_put(row, c, term->vt.osc8.uri, term->vt.osc8.id); + + switch (term->conf->url.osc8_underline) { + case OSC8_UNDERLINE_ALWAYS: + cell->attrs.url = true; + break; + + case OSC8_UNDERLINE_URL_MODE: + break; + } + } +} + void term_print(struct terminal *term, char32_t wc, int width) { -- cgit v1.3 From e6c372b14fa76799ea3c3ff89258a1b905cc9ec0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 14:35:18 +0100 Subject: term: print: spacers may be printed all the way up to the last column --- terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 6119f68c..f814de97 100644 --- a/terminal.c +++ b/terminal.c @@ -3602,7 +3602,7 @@ term_print(struct terminal *term, char32_t wc, int width) grid_row_uri_range_erase(row, col, col + width - 1); /* Advance cursor the 'additional' columns while dirty:ing the cells */ - for (int i = 1; i < width && col < term->cols - 1; i++) { + for (int i = 1; i < width && col < term->cols; i++) { col++; print_spacer(term, col, width - i); } -- cgit v1.3 From b30b8a294498ce765698dd40df4a750f8debe689 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 15:00:13 +0100 Subject: put_char fixup --- terminal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index f814de97..bdbcd9bd 100644 --- a/terminal.c +++ b/terminal.c @@ -3506,6 +3506,7 @@ print_spacer(struct terminal *term, int col, int remaining) * - update the cursor * - linewrap * - erase sixels + * - erase URIs (but it _does_ emit them if one is active) * * Limitiations: * - double width characters not supported -- cgit v1.3 From df5dd94789291290489e7e875dd7f7862aa6dc35 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 15:09:46 +0100 Subject: term: codespell: limitiations -> limitations --- terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index bdbcd9bd..ad20c737 100644 --- a/terminal.c +++ b/terminal.c @@ -3508,7 +3508,7 @@ print_spacer(struct terminal *term, int col, int remaining) * - erase sixels * - erase URIs (but it _does_ emit them if one is active) * - * Limitiations: + * Limitations: * - double width characters not supported */ void -- cgit v1.3 From 189cfd717fd4670a97995ad9b8e08a2352c09099 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 15:59:38 +0100 Subject: term: replace term_put_char() with term_fill() --- csi.c | 11 ++--------- terminal.c | 32 +++++++++++++++++++------------- terminal.h | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) (limited to 'terminal.c') diff --git a/csi.c b/csi.c index 43a358a8..ac03825e 100644 --- a/csi.c +++ b/csi.c @@ -1941,15 +1941,8 @@ csi_dispatch(struct terminal *term, uint8_t final) sixel_overwrite_by_rectangle( term, top, left, bottom - top + 1, right - left + 1); - for (int r = top; r <= bottom; r++) { - struct row *row = grid_row(term->grid, r); - - if (unlikely(row->extra != NULL)) - grid_row_uri_range_erase(row, left, right); - - for (int col = left; col <= right; col++) - term_put_char(term, r, col, (wchar_t)c); - } + for (int r = top; r <= bottom; r++) + term_fill(term, r, left, c, right - left + 1); } break; } diff --git a/terminal.c b/terminal.c index ad20c737..8abe61e8 100644 --- a/terminal.c +++ b/terminal.c @@ -3506,33 +3506,39 @@ print_spacer(struct terminal *term, int col, int remaining) * - update the cursor * - linewrap * - erase sixels - * - erase URIs (but it _does_ emit them if one is active) * * Limitations: * - double width characters not supported */ void -term_put_char(struct terminal *term, int r, int c, wchar_t wc) +term_fill(struct terminal *term, int r, int c, char data, size_t count) { struct row *row = grid_row(term->grid, r); row->dirty = true; - struct cell *cell = &row->cells[c]; - cell->wc = wc; - cell->attrs = term->vt.attrs; + xassert(c + count <= term->cols); - if (unlikely(term->vt.osc8.uri != NULL)) { - grid_row_uri_range_put(row, c, term->vt.osc8.uri, term->vt.osc8.id); + const struct cell *last = &row->cells[c + count]; + for (struct cell *cell = &row->cells[c]; cell < last; cell++) { + cell->wc = data; + cell->attrs = term->vt.attrs; - switch (term->conf->url.osc8_underline) { - case OSC8_UNDERLINE_ALWAYS: - cell->attrs.url = true; - break; + if (unlikely(term->vt.osc8.uri != NULL)) { + grid_row_uri_range_put(row, c, term->vt.osc8.uri, term->vt.osc8.id); - case OSC8_UNDERLINE_URL_MODE: - break; + switch (term->conf->url.osc8_underline) { + case OSC8_UNDERLINE_ALWAYS: + cell->attrs.url = true; + break; + + case OSC8_UNDERLINE_URL_MODE: + break; + } } } + + if (unlikely(row->extra != NULL)) + grid_row_uri_range_erase(row, c, c + count - 1); } void diff --git a/terminal.h b/terminal.h index 8abc1c8e..f56ffdb0 100644 --- a/terminal.h +++ b/terminal.h @@ -797,8 +797,8 @@ void term_cursor_up(struct terminal *term, int count); void term_cursor_down(struct terminal *term, int count); void term_cursor_blink_update(struct terminal *term); -void term_put_char(struct terminal *term, int r, int c, char32_t wc); void term_print(struct terminal *term, char32_t wc, int width); +void term_fill(struct terminal *term, int row, int col, char c, size_t count); void term_scroll(struct terminal *term, int rows); void term_scroll_reverse(struct terminal *term, int rows); -- cgit v1.3 From b3a84ba71b021b484e0ddc023480eb6d9f885991 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 16:05:18 +0100 Subject: term: modify term_fill() to optionally reset the SGR attributes --- csi.c | 2 +- terminal.c | 9 +++++++-- terminal.h | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'terminal.c') diff --git a/csi.c b/csi.c index ac03825e..558c2dc2 100644 --- a/csi.c +++ b/csi.c @@ -1942,7 +1942,7 @@ csi_dispatch(struct terminal *term, uint8_t final) term, top, left, bottom - top + 1, right - left + 1); for (int r = top; r <= bottom; r++) - term_fill(term, r, left, c, right - left + 1); + term_fill(term, r, left, c, right - left + 1, true); } break; } diff --git a/terminal.c b/terminal.c index 8abe61e8..d826282b 100644 --- a/terminal.c +++ b/terminal.c @@ -3511,17 +3511,22 @@ print_spacer(struct terminal *term, int col, int remaining) * - double width characters not supported */ void -term_fill(struct terminal *term, int r, int c, char data, size_t count) +term_fill(struct terminal *term, int r, int c, char data, size_t count, + bool use_sgr_attrs) { struct row *row = grid_row(term->grid, r); row->dirty = true; xassert(c + count <= term->cols); + const struct attributes attrs = use_sgr_attrs + ? term->vt.attrs + : (struct attributes){0}; + const struct cell *last = &row->cells[c + count]; for (struct cell *cell = &row->cells[c]; cell < last; cell++) { cell->wc = data; - cell->attrs = term->vt.attrs; + cell->attrs = attrs; if (unlikely(term->vt.osc8.uri != NULL)) { grid_row_uri_range_put(row, c, term->vt.osc8.uri, term->vt.osc8.id); diff --git a/terminal.h b/terminal.h index f56ffdb0..c8a43c64 100644 --- a/terminal.h +++ b/terminal.h @@ -798,7 +798,8 @@ void term_cursor_down(struct terminal *term, int count); void term_cursor_blink_update(struct terminal *term); void term_print(struct terminal *term, char32_t wc, int width); -void term_fill(struct terminal *term, int row, int col, char c, size_t count); +void term_fill(struct terminal *term, int row, int col, char c, size_t count, + bool use_sgr_attrs); void term_scroll(struct terminal *term, int rows); void term_scroll_reverse(struct terminal *term, int rows); -- cgit v1.3 From 1b13deff048fc10620b26ffe0220fae15549f9b4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 16:08:42 +0100 Subject: term_fill(): make sure the filled cells have their ‘clean’ bit reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terminal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index d826282b..acde951b 100644 --- a/terminal.c +++ b/terminal.c @@ -3519,10 +3519,12 @@ term_fill(struct terminal *term, int r, int c, char data, size_t count, xassert(c + count <= term->cols); - const struct attributes attrs = use_sgr_attrs + struct attributes attrs = use_sgr_attrs ? term->vt.attrs : (struct attributes){0}; + attrs.clean = 0; + const struct cell *last = &row->cells[c + count]; for (struct cell *cell = &row->cells[c]; cell < last; cell++) { cell->wc = data; -- cgit v1.3 From 23908d9277b3c41c294102993875cf485db689cb Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Dec 2021 16:13:05 +0100 Subject: term_fill(): change ‘character’ parameter from char -> uint8_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- csi.c | 35 ++++++++++++++++++----------------- terminal.c | 2 +- terminal.h | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) (limited to 'terminal.c') diff --git a/csi.c b/csi.c index 558c2dc2..494ac957 100644 --- a/csi.c +++ b/csi.c @@ -1924,26 +1924,27 @@ csi_dispatch(struct terminal *term, uint8_t final) } case 'x': { /* DECFRA */ - const char c = vt_param_get(term, 0, 0); - if (likely((c >= 32 && c < 126) || - (c >= 160 && c <= 255))) - { - int top, left, bottom, right; - if (!params_to_rectangular_area( - term, 1, &top, &left, &bottom, &right)) - { - break; - } + const uint8_t c = vt_param_get(term, 0, 0); - /* Erase the entire region at once (MUCH cheaper than - * doing it row by row, or even character by - * character). */ - sixel_overwrite_by_rectangle( - term, top, left, bottom - top + 1, right - left + 1); + if (unlikely(!((c >= 32 && c < 126) || c >= 160))) + break; - for (int r = top; r <= bottom; r++) - term_fill(term, r, left, c, right - left + 1, true); + int top, left, bottom, right; + if (!params_to_rectangular_area( + term, 1, &top, &left, &bottom, &right)) + { + break; } + + /* Erase the entire region at once (MUCH cheaper than + * doing it row by row, or even character by + * character). */ + sixel_overwrite_by_rectangle( + term, top, left, bottom - top + 1, right - left + 1); + + for (int r = top; r <= bottom; r++) + term_fill(term, r, left, c, right - left + 1, true); + break; } diff --git a/terminal.c b/terminal.c index acde951b..1ca581be 100644 --- a/terminal.c +++ b/terminal.c @@ -3511,7 +3511,7 @@ print_spacer(struct terminal *term, int col, int remaining) * - double width characters not supported */ void -term_fill(struct terminal *term, int r, int c, char data, size_t count, +term_fill(struct terminal *term, int r, int c, uint8_t data, size_t count, bool use_sgr_attrs) { struct row *row = grid_row(term->grid, r); diff --git a/terminal.h b/terminal.h index c8a43c64..0dd40c51 100644 --- a/terminal.h +++ b/terminal.h @@ -798,7 +798,7 @@ void term_cursor_down(struct terminal *term, int count); void term_cursor_blink_update(struct terminal *term); void term_print(struct terminal *term, char32_t wc, int width); -void term_fill(struct terminal *term, int row, int col, char c, size_t count, +void term_fill(struct terminal *term, int row, int col, uint8_t c, size_t count, bool use_sgr_attrs); void term_scroll(struct terminal *term, int rows); -- cgit v1.3 From 8d7ab86182c1439e9aa4c436f0ceebe77c7d05a9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 28 Dec 2021 17:15:12 +0100 Subject: term_fill(): no need to set attrs.clean = 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The VT state’s attribute is always 0 --- terminal.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 1ca581be..2248bd02 100644 --- a/terminal.c +++ b/terminal.c @@ -3523,8 +3523,6 @@ term_fill(struct terminal *term, int r, int c, uint8_t data, size_t count, ? term->vt.attrs : (struct attributes){0}; - attrs.clean = 0; - const struct cell *last = &row->cells[c + count]; for (struct cell *cell = &row->cells[c]; cell < last; cell++) { cell->wc = data; -- cgit v1.3