mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
vt: utf8: de-duplicate; jump to end of function to print to grid
This commit is contained in:
parent
c0d9f92e1a
commit
e81d1845bf
1 changed files with 25 additions and 26 deletions
51
vt.c
51
vt.c
|
|
@ -631,10 +631,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
|
||||||
if (utf8proc_grapheme_break_stateful(last, wc, &term->vt.grapheme_state) &&
|
if (utf8proc_grapheme_break_stateful(last, wc, &term->vt.grapheme_state) &&
|
||||||
last != 0x200d /* ZWJ */)
|
last != 0x200d /* ZWJ */)
|
||||||
{
|
{
|
||||||
term_reset_grapheme_state(term);
|
goto out;
|
||||||
if (width > 0)
|
|
||||||
term_print(term, wc, width);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -671,9 +668,9 @@ action_utf8_print(struct terminal *term, wchar_t wc)
|
||||||
!base_from_primary ||
|
!base_from_primary ||
|
||||||
!comb_from_primary))
|
!comb_from_primary))
|
||||||
{
|
{
|
||||||
term_reset_grapheme_state(term);
|
wc = precomposed;
|
||||||
term_print(term, precomposed, precomposed_width);
|
width = precomposed_width;
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -717,9 +714,9 @@ action_utf8_print(struct terminal *term, wchar_t wc)
|
||||||
if (cc->chars[wanted_count - 1] != wc)
|
if (cc->chars[wanted_count - 1] != wc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cc->width > 0)
|
wc = CELL_COMB_CHARS_LO + i;
|
||||||
term_print(term, CELL_COMB_CHARS_LO + i, cc->width);
|
width = cc->width;
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate new chain */
|
/* Allocate new chain */
|
||||||
|
|
@ -732,30 +729,32 @@ action_utf8_print(struct terminal *term, wchar_t wc)
|
||||||
new_cc.chars[i] = composed->chars[i];
|
new_cc.chars[i] = composed->chars[i];
|
||||||
new_cc.chars[wanted_count - 1] = wc;
|
new_cc.chars[wanted_count - 1] = wc;
|
||||||
|
|
||||||
if (term->composed_count < CELL_COMB_CHARS_HI) {
|
if (unlikely(term->composed_count >= CELL_COMB_CHARS_HI)) {
|
||||||
int grapheme_width = composed != NULL ? composed->width : base_width;
|
|
||||||
if (wc == 0xfe0f && grapheme_width < 2)
|
|
||||||
grapheme_width = 2;
|
|
||||||
else
|
|
||||||
grapheme_width += width;
|
|
||||||
new_cc.width = grapheme_width;
|
|
||||||
|
|
||||||
term->composed_count++;
|
|
||||||
term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));
|
|
||||||
term->composed[term->composed_count - 1] = new_cc;
|
|
||||||
|
|
||||||
if (grapheme_width > 0)
|
|
||||||
term_print(term, CELL_COMB_CHARS_LO + term->composed_count - 1, grapheme_width);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
/* We reached our maximum number of allowed composed
|
/* We reached our maximum number of allowed composed
|
||||||
* character chains. Fall through here and print the
|
* character chains. Fall through here and print the
|
||||||
* current zero-width character to the current cell */
|
* current zero-width character to the current cell */
|
||||||
LOG_WARN("maximum number of composed characters reached");
|
LOG_WARN("maximum number of composed characters reached");
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int grapheme_width = composed != NULL ? composed->width : base_width;
|
||||||
|
if (wc == 0xfe0f && grapheme_width < 2)
|
||||||
|
grapheme_width = 2;
|
||||||
|
else
|
||||||
|
grapheme_width += width;
|
||||||
|
new_cc.width = grapheme_width;
|
||||||
|
|
||||||
|
term->composed_count++;
|
||||||
|
term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));
|
||||||
|
term->composed[term->composed_count - 1] = new_cc;
|
||||||
|
|
||||||
|
wc = CELL_COMB_CHARS_LO + term->composed_count - 1;
|
||||||
|
width = grapheme_width;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
term_reset_grapheme_state(term);
|
term_reset_grapheme_state(term);
|
||||||
if (width > 0)
|
if (width > 0)
|
||||||
term_print(term, wc, width);
|
term_print(term, wc, width);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue