Merge branch 'charset-shift-fixes'

This commit is contained in:
Craig Barnes 2021-06-09 10:18:52 +01:00
commit 2a75da4143
4 changed files with 47 additions and 14 deletions

View file

@ -61,6 +61,8 @@
_Private Usage Area_ codepoints to be treated as double-width _Private Usage Area_ codepoints to be treated as double-width
characters. characters.
* OSC 9 desktop notifications (iTerm2 compatible). * OSC 9 desktop notifications (iTerm2 compatible).
* Support for LS2 and LS3 (locking shift) escape sequences
(https://codeberg.org/dnkl/foot/issues/581).
### Changed ### Changed
@ -166,6 +168,8 @@
* Restore `SIGHUP` in spawned processes. * Restore `SIGHUP` in spawned processes.
* Text reflow performance (https://codeberg.org/dnkl/foot/issues/504). * Text reflow performance (https://codeberg.org/dnkl/foot/issues/504).
* IL+DL (`CSI Ps L` + `CSI Ps M`) now moves the cursor to column 0. * IL+DL (`CSI Ps L` + `CSI Ps M`) now moves the cursor to column 0.
* SS2 and SS3 (single shift) escape sequences behaving like locking
shifts (https://codeberg.org/dnkl/foot/issues/580).
### Security ### Security

View file

@ -1606,11 +1606,11 @@ term_reset(struct terminal *term, bool hard)
term->bell_action_enabled = true; term->bell_action_enabled = true;
term->mouse_tracking = MOUSE_NONE; term->mouse_tracking = MOUSE_NONE;
term->mouse_reporting = MOUSE_NORMAL; term->mouse_reporting = MOUSE_NORMAL;
term->charsets.selected = 0; term->charsets.selected = G0;
term->charsets.set[0] = CHARSET_ASCII; term->charsets.set[G0] = CHARSET_ASCII;
term->charsets.set[1] = CHARSET_ASCII; term->charsets.set[G1] = CHARSET_ASCII;
term->charsets.set[2] = CHARSET_ASCII; term->charsets.set[G2] = CHARSET_ASCII;
term->charsets.set[3] = CHARSET_ASCII; term->charsets.set[G3] = CHARSET_ASCII;
term->saved_charsets = term->charsets; term->saved_charsets = term->charsets;
tll_free_and_free(term->window_title_stack, free); tll_free_and_free(term->window_title_stack, free);
term_set_window_title(term, term->conf->title); term_set_window_title(term, term->conf->title);
@ -2839,6 +2839,14 @@ ascii_printer_fast(struct terminal *term, wchar_t wc)
xassert(!term->grid->cursor.lcf); xassert(!term->grid->cursor.lcf);
} }
static void
ascii_printer_single_shift(struct terminal *term, wchar_t wc)
{
ascii_printer_generic(term, wc);
term->charsets.selected = term->charsets.saved;
term_update_ascii_printer(term);
}
void void
term_update_ascii_printer(struct terminal *term) term_update_ascii_printer(struct terminal *term)
{ {
@ -2860,6 +2868,14 @@ term_update_ascii_printer(struct terminal *term)
term->ascii_printer = new_printer; term->ascii_printer = new_printer;
} }
void
term_single_shift(struct terminal *term, enum charset_designator idx)
{
term->charsets.saved = term->charsets.selected;
term->charsets.selected = idx;
term->ascii_printer = &ascii_printer_single_shift;
}
enum term_surface enum term_surface
term_surface_kind(const struct terminal *term, const struct wl_surface *surface) term_surface_kind(const struct terminal *term, const struct wl_surface *surface)
{ {

View file

@ -189,9 +189,11 @@ enum cursor_origin { ORIGIN_ABSOLUTE, ORIGIN_RELATIVE };
enum cursor_keys { CURSOR_KEYS_DONTCARE, CURSOR_KEYS_NORMAL, CURSOR_KEYS_APPLICATION }; enum cursor_keys { CURSOR_KEYS_DONTCARE, CURSOR_KEYS_NORMAL, CURSOR_KEYS_APPLICATION };
enum keypad_keys { KEYPAD_DONTCARE, KEYPAD_NUMERICAL, KEYPAD_APPLICATION }; enum keypad_keys { KEYPAD_DONTCARE, KEYPAD_NUMERICAL, KEYPAD_APPLICATION };
enum charset { CHARSET_ASCII, CHARSET_GRAPHIC }; enum charset { CHARSET_ASCII, CHARSET_GRAPHIC };
enum charset_designator { G0, G1, G2, G3 };
struct charsets { struct charsets {
int selected; enum charset_designator selected;
enum charset_designator saved;
enum charset set[4]; /* G0-G3 */ enum charset set[4]; /* G0-G3 */
}; };
@ -605,6 +607,7 @@ bool term_shutdown(struct terminal *term);
int term_destroy(struct terminal *term); int term_destroy(struct terminal *term);
void term_update_ascii_printer(struct terminal *term); void term_update_ascii_printer(struct terminal *term);
void term_single_shift(struct terminal *term, enum charset_designator idx);
void term_reset(struct terminal *term, bool hard); void term_reset(struct terminal *term, bool hard);
bool term_to_slave(struct terminal *term, const void *data, size_t len); bool term_to_slave(struct terminal *term, const void *data, size_t len);

26
vt.c
View file

@ -234,13 +234,13 @@ action_execute(struct terminal *term, uint8_t c)
case '\x0e': case '\x0e':
/* SO - shift out */ /* SO - shift out */
term->charsets.selected = 1; /* G1 */ term->charsets.selected = G1;
term_update_ascii_printer(term); term_update_ascii_printer(term);
break; break;
case '\x0f': case '\x0f':
/* SI - shift in */ /* SI - shift in */
term->charsets.selected = 0; /* G0 */ term->charsets.selected = G0;
term_update_ascii_printer(term); term_update_ascii_printer(term);
break; break;
@ -426,6 +426,18 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
term_reset(term, true); term_reset(term, true);
break; break;
case 'n':
/* LS2 - Locking Shift 2 */
term->charsets.selected = G2;
term_update_ascii_printer(term);
break;
case 'o':
/* LS3 - Locking Shift 3 */
term->charsets.selected = G3;
term_update_ascii_printer(term);
break;
case 'D': case 'D':
term_linefeed(term); term_linefeed(term);
break; break;
@ -452,14 +464,12 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
case 'N': case 'N':
/* SS2 - Single Shift 2 */ /* SS2 - Single Shift 2 */
term->charsets.selected = 2; /* G2 */ term_single_shift(term, G2);
term_update_ascii_printer(term);
break; break;
case 'O': case 'O':
/* SS3 - Single Shift 3 */ /* SS3 - Single Shift 3 */
term->charsets.selected = 3; /* G3 */ term_single_shift(term, G3);
term_update_ascii_printer(term);
break; break;
case '\\': case '\\':
@ -488,7 +498,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
switch (final) { switch (final) {
case '0': { case '0': {
size_t idx = term->vt.private - '('; size_t idx = term->vt.private - '(';
xassert(idx <= 3); xassert(idx <= G3);
term->charsets.set[idx] = CHARSET_GRAPHIC; term->charsets.set[idx] = CHARSET_GRAPHIC;
term_update_ascii_printer(term); term_update_ascii_printer(term);
break; break;
@ -496,7 +506,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
case 'B': { case 'B': {
size_t idx = term->vt.private - '('; size_t idx = term->vt.private - '(';
xassert(idx <= 3); xassert(idx <= G3);
term->charsets.set[idx] = CHARSET_ASCII; term->charsets.set[idx] = CHARSET_ASCII;
term_update_ascii_printer(term); term_update_ascii_printer(term);
break; break;