mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-06 04:06:06 -05:00
csi: pick 16 first 256-colors directly from the term struct
The 16 first entries in the 256-color array are the regular and bright colors. However, since they can be changed (eventually) at runtime, we can't statically initialize the 256-color array. Instead, pick the regular+bright colors directly from the terminal struct. I.e. the first 16 entries of the 256-color array are now unused.
This commit is contained in:
parent
7eb6ac1aec
commit
16979927ba
1 changed files with 19 additions and 2 deletions
21
csi.c
21
csi.c
|
|
@ -23,10 +23,12 @@ static uint32_t colors256[256];
|
|||
static void __attribute__((constructor))
|
||||
initialize_colors256(void)
|
||||
{
|
||||
#if 0 /* pick colors from term struct instead, since they can be changed runtime */
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
colors256[i] = colors_regular[i];
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
colors256[8 + i] = colors_bright[i];
|
||||
#endif
|
||||
|
||||
for (size_t r = 0; r < 6; r++) {
|
||||
for (size_t g = 0; g < 6; g++) {
|
||||
|
|
@ -132,7 +134,14 @@ csi_sgr(struct terminal *term)
|
|||
term->vt.params.v[i + 1].value == 5)
|
||||
{
|
||||
uint8_t idx = term->vt.params.v[i + 2].value;
|
||||
term->vt.attrs.foreground = 1 << 31 | colors256[idx];
|
||||
uint32_t color;
|
||||
if (idx < 8)
|
||||
color = term->colors.regular[idx];
|
||||
else if (idx < 16)
|
||||
color = term->colors.bright[idx - 8];
|
||||
else
|
||||
color = colors256[idx];
|
||||
term->vt.attrs.foreground = 1 << 31 | color;
|
||||
i += 2;
|
||||
|
||||
}
|
||||
|
|
@ -194,7 +203,15 @@ csi_sgr(struct terminal *term)
|
|||
term->vt.params.v[i + 1].value == 5)
|
||||
{
|
||||
uint8_t idx = term->vt.params.v[i + 2].value;
|
||||
term->vt.attrs.background = 1 << 31 | colors256[idx];
|
||||
uint32_t color;
|
||||
|
||||
if (idx < 8)
|
||||
color = term->colors.regular[idx];
|
||||
else if (idx < 16)
|
||||
color = term->colors.bright[idx - 8];
|
||||
else
|
||||
color = colors256[idx];
|
||||
term->vt.attrs.background = 1 << 31 | color;
|
||||
i += 2;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue