mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-29 07:58:01 -04:00
term: runtime switch between a ‘fast’ and a ‘generic’ ASCII print function
term_print() is called whenever the client application “prints” something to the grid. It is called for both ASCII and UTF-8 characters, and needs to handle sixels, insert mode and ASCII vs. graphical charsets. Since it’s on the hot path, this becomes unnecessarily slow. This patch adds a “fast” version of term_print(), tailored for the common case: ASCII characters in non-insert mode, without any sixels and non-graphical charsets. A new function, term_update_ascii_printer(), has been added, and must be called whenever: * The currently selected charset *index* changes * The currently selected charset changes (from ASCII to graphical, or vice verse) * Sixels are added to the grid * Sixels are removed from the grid * Insert mode is enabled/disabled
This commit is contained in:
parent
d8f0e701b5
commit
60b3ccc641
5 changed files with 84 additions and 16 deletions
23
vt.c
23
vt.c
|
|
@ -184,11 +184,13 @@ action_execute(struct terminal *term, uint8_t c)
|
|||
case '\x0e':
|
||||
/* SO - shift out */
|
||||
term->charsets.selected = 1; /* G1 */
|
||||
term_update_ascii_printer(term);
|
||||
break;
|
||||
|
||||
case '\x0f':
|
||||
/* SI - shift in */
|
||||
term->charsets.selected = 0; /* G0 */
|
||||
term_update_ascii_printer(term);
|
||||
break;
|
||||
|
||||
/*
|
||||
|
|
@ -230,21 +232,7 @@ action_execute(struct terminal *term, uint8_t c)
|
|||
static void
|
||||
action_print(struct terminal *term, uint8_t c)
|
||||
{
|
||||
/* 0x60 - 0x7e */
|
||||
static const wchar_t vt100_0[] = {
|
||||
L'◆', L'▒', L'␉', L'␌', L'␍', L'␊', L'°', L'±', /* ` - g */
|
||||
L'', L'␋', L'┘', L'┐', L'┌', L'└', L'┼', L'⎺', /* h - o */
|
||||
L'⎻', L'─', L'⎼', L'⎽', L'├', L'┤', L'┴', L'┬', /* p - w */
|
||||
L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */
|
||||
};
|
||||
|
||||
if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) &&
|
||||
c >= 0x60 && c <= 0x7e)
|
||||
{
|
||||
term_print(term, vt100_0[c - 0x60], 1);
|
||||
} else {
|
||||
term_print(term, c, 1);
|
||||
}
|
||||
term->ascii_printer(term, c);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -414,11 +402,13 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
|
|||
case 'N':
|
||||
/* SS2 - Single Shift 2 */
|
||||
term->charsets.selected = 2; /* G2 */
|
||||
term_update_ascii_printer(term);
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
/* SS3 - Single Shift 3 */
|
||||
term->charsets.selected = 3; /* G3 */
|
||||
term_update_ascii_printer(term);
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
|
|
@ -453,6 +443,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
|
|||
'+' ? 3 : -1;
|
||||
xassert(idx != -1);
|
||||
term->charsets.set[idx] = CHARSET_GRAPHIC;
|
||||
term_update_ascii_printer(term);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -465,7 +456,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
|
|||
'+' ? 3 : -1;
|
||||
xassert(idx != -1);
|
||||
term->charsets.set[idx] = CHARSET_ASCII;
|
||||
|
||||
term_update_ascii_printer(term);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue