term: move charset variables into an anonymous struct

This commit is contained in:
Daniel Eklöf 2019-11-17 09:59:12 +01:00
parent 36bcb0dac1
commit ce544776ab
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 23 additions and 14 deletions

View file

@ -823,11 +823,11 @@ term_reset(struct terminal *term, bool hard)
term->focus_events = false; term->focus_events = false;
term->mouse_tracking = MOUSE_NONE; term->mouse_tracking = MOUSE_NONE;
term->mouse_reporting = MOUSE_NORMAL; term->mouse_reporting = MOUSE_NORMAL;
term->selected_charset = 0; term->charsets.selected = 0;
term->charset[0] = CHARSET_ASCII; term->charsets.set[0] = CHARSET_ASCII;
term->charset[1] = CHARSET_ASCII; term->charsets.set[1] = CHARSET_ASCII;
term->charset[2] = CHARSET_ASCII; term->charsets.set[2] = CHARSET_ASCII;
term->charset[3] = CHARSET_ASCII; term->charsets.set[3] = CHARSET_ASCII;
tll_free_and_free(term->window_title_stack, free); tll_free_and_free(term->window_title_stack, free);
free(term->window_title); free(term->window_title);
term->window_title = strdup("foot"); term->window_title = strdup("foot");

View file

@ -178,8 +178,11 @@ struct terminal {
enum mouse_tracking mouse_tracking; enum mouse_tracking mouse_tracking;
enum mouse_reporting mouse_reporting; enum mouse_reporting mouse_reporting;
int selected_charset; struct {
enum charset charset[4]; /* G0-G3 */ int selected;
enum charset set[4]; /* G0-G3 */
} charsets;
char *window_title; char *window_title;
tll(char *) window_title_stack; tll(char *) window_title_stack;

20
vt.c
View file

@ -597,11 +597,17 @@ esc_dispatch(struct terminal *term, uint8_t final)
case '7': case '7':
term->saved_cursor = term->cursor; term->saved_cursor = term->cursor;
term->vt.saved_attrs = term->vt.attrs; term->vt.saved_attrs = term->vt.attrs;
//term->saved_charset = term->selected_charset;
//for (size_t i = 0; i < 4; i++)
// term->saved_charsets[i] = term->charset[i];
break; break;
case '8': case '8':
term_restore_cursor(term); term_restore_cursor(term);
term->vt.attrs = term->vt.saved_attrs; term->vt.attrs = term->vt.saved_attrs;
//term->selected_charset = term->saved_charset;
//for (size_t i = 0; i < 4; i++)
// term->charset[i] = term->saved_charsets[i];
break; break;
case 'c': case 'c':
@ -634,12 +640,12 @@ esc_dispatch(struct terminal *term, uint8_t final)
case 'N': case 'N':
/* SS2 - Single Shift 2 */ /* SS2 - Single Shift 2 */
term->selected_charset = 2; /* G2 */ term->charsets.selected = 2; /* G2 */
break; break;
case 'O': case 'O':
/* SS3 - Single Shift 3 */ /* SS3 - Single Shift 3 */
term->selected_charset = 3; /* G3 */ term->charsets.selected = 3; /* G3 */
break; break;
case '\\': case '\\':
@ -673,7 +679,7 @@ esc_dispatch(struct terminal *term, uint8_t final)
'*' ? 2 : '*' ? 2 :
'+' ? 3 : -1; '+' ? 3 : -1;
assert(idx != -1); assert(idx != -1);
term->charset[idx] = CHARSET_GRAPHIC; term->charsets.set[idx] = CHARSET_GRAPHIC;
break; break;
} }
@ -685,7 +691,7 @@ esc_dispatch(struct terminal *term, uint8_t final)
'*' ? 2 : '*' ? 2 :
'+' ? 3 : -1; '+' ? 3 : -1;
assert(idx != -1); assert(idx != -1);
term->charset[idx] = CHARSET_ASCII; term->charsets.set[idx] = CHARSET_ASCII;
break; break;
} }
@ -814,7 +820,7 @@ action_print(struct terminal *term, uint8_t c)
L'', L'', L'', L'π', L'', L'£', L'·', /* x - ~ */ L'', L'', L'', L'π', L'', L'£', L'·', /* x - ~ */
}; };
if (unlikely(term->charset[term->selected_charset] == CHARSET_GRAPHIC) && if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) &&
c >= 0x60 && c <= 0x7e) c >= 0x60 && c <= 0x7e)
{ {
cell->wc = vt100_0[c - 0x60]; cell->wc = vt100_0[c - 0x60];
@ -884,12 +890,12 @@ action(struct terminal *term, enum action _action, uint8_t c)
case '\x0e': case '\x0e':
/* SO - shift out */ /* SO - shift out */
term->selected_charset = 1; /* G1 */ term->charsets.selected = 1; /* G1 */
break; break;
case '\x0f': case '\x0f':
/* SI - shift in */ /* SI - shift in */
term->selected_charset = 0; /* G0 */ term->charsets.selected = 0; /* G0 */
break; break;
default: default: