mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-18 05:34:02 -04:00
term: use colors256 array for *all* colors
That is, remove the 'regular' and 'bright' color arrays. This is possible since the 256-color array is defined such that the first 16 colors map to the regular and bright colors.
This commit is contained in:
parent
65e4b93a03
commit
631e0c0870
5 changed files with 22 additions and 74 deletions
29
csi.c
29
csi.c
|
|
@ -105,7 +105,7 @@ csi_sgr(struct terminal *term)
|
||||||
case 36:
|
case 36:
|
||||||
case 37:
|
case 37:
|
||||||
term->vt.attrs.have_fg = 1;
|
term->vt.attrs.have_fg = 1;
|
||||||
term->vt.attrs.fg = term->colors.regular[param - 30];
|
term->vt.attrs.fg = term->colors.colors256[param - 30];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 38: {
|
case 38: {
|
||||||
|
|
@ -113,15 +113,8 @@ csi_sgr(struct terminal *term)
|
||||||
term->vt.params.v[i + 1].value == 5)
|
term->vt.params.v[i + 1].value == 5)
|
||||||
{
|
{
|
||||||
uint8_t idx = term->vt.params.v[i + 2].value;
|
uint8_t idx = term->vt.params.v[i + 2].value;
|
||||||
uint32_t color;
|
|
||||||
if (idx < 8)
|
|
||||||
color = term->colors.regular[idx];
|
|
||||||
else if (idx < 16)
|
|
||||||
color = term->colors.bright[idx - 8];
|
|
||||||
else
|
|
||||||
color = term->colors.colors256[idx];
|
|
||||||
term->vt.attrs.have_fg = 1;
|
term->vt.attrs.have_fg = 1;
|
||||||
term->vt.attrs.fg = color;
|
term->vt.attrs.fg = term->colors.colors256[idx];
|
||||||
i += 2;
|
i += 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -175,7 +168,7 @@ csi_sgr(struct terminal *term)
|
||||||
case 46:
|
case 46:
|
||||||
case 47:
|
case 47:
|
||||||
term->vt.attrs.have_bg = 1;
|
term->vt.attrs.have_bg = 1;
|
||||||
term->vt.attrs.bg = term->colors.regular[param - 40];
|
term->vt.attrs.bg = term->colors.colors256[param - 40];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 48: {
|
case 48: {
|
||||||
|
|
@ -183,16 +176,8 @@ csi_sgr(struct terminal *term)
|
||||||
term->vt.params.v[i + 1].value == 5)
|
term->vt.params.v[i + 1].value == 5)
|
||||||
{
|
{
|
||||||
uint8_t idx = term->vt.params.v[i + 2].value;
|
uint8_t idx = term->vt.params.v[i + 2].value;
|
||||||
uint32_t color;
|
|
||||||
|
|
||||||
if (idx < 8)
|
|
||||||
color = term->colors.regular[idx];
|
|
||||||
else if (idx < 16)
|
|
||||||
color = term->colors.bright[idx - 8];
|
|
||||||
else
|
|
||||||
color = term->colors.colors256[idx];
|
|
||||||
term->vt.attrs.have_bg = 1;
|
term->vt.attrs.have_bg = 1;
|
||||||
term->vt.attrs.bg = color;
|
term->vt.attrs.bg = term->colors.colors256[idx];
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,10 +230,10 @@ csi_sgr(struct terminal *term)
|
||||||
case 96:
|
case 96:
|
||||||
case 97:
|
case 97:
|
||||||
term->vt.attrs.have_fg = 1;
|
term->vt.attrs.have_fg = 1;
|
||||||
term->vt.attrs.fg = term->colors.bright[param - 90];
|
term->vt.attrs.fg = term->colors.colors256[param - 90 + 8];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Regular background colors */
|
/* Bright background colors */
|
||||||
case 100:
|
case 100:
|
||||||
case 101:
|
case 101:
|
||||||
case 102:
|
case 102:
|
||||||
|
|
@ -258,7 +243,7 @@ csi_sgr(struct terminal *term)
|
||||||
case 106:
|
case 106:
|
||||||
case 107:
|
case 107:
|
||||||
term->vt.attrs.have_bg = 1;
|
term->vt.attrs.have_bg = 1;
|
||||||
term->vt.attrs.bg = term->colors.bright[param - 100];
|
term->vt.attrs.bg = term->colors.colors256[param - 100 + 8];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
25
main.c
25
main.c
|
|
@ -445,7 +445,7 @@ main(int argc, char *const *argv)
|
||||||
.colors = {
|
.colors = {
|
||||||
.default_fg = conf.colors.fg,
|
.default_fg = conf.colors.fg,
|
||||||
.default_bg = conf.colors.bg,
|
.default_bg = conf.colors.bg,
|
||||||
.default_regular = {
|
.default_colors256 = {
|
||||||
conf.colors.regular[0],
|
conf.colors.regular[0],
|
||||||
conf.colors.regular[1],
|
conf.colors.regular[1],
|
||||||
conf.colors.regular[2],
|
conf.colors.regular[2],
|
||||||
|
|
@ -454,8 +454,7 @@ main(int argc, char *const *argv)
|
||||||
conf.colors.regular[5],
|
conf.colors.regular[5],
|
||||||
conf.colors.regular[6],
|
conf.colors.regular[6],
|
||||||
conf.colors.regular[7],
|
conf.colors.regular[7],
|
||||||
},
|
|
||||||
.default_bright = {
|
|
||||||
conf.colors.bright[0],
|
conf.colors.bright[0],
|
||||||
conf.colors.bright[1],
|
conf.colors.bright[1],
|
||||||
conf.colors.bright[2],
|
conf.colors.bright[2],
|
||||||
|
|
@ -493,6 +492,14 @@ main(int argc, char *const *argv)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LOG_INFO("using %zu rendering threads", term.render.workers.count);
|
||||||
|
|
||||||
|
struct render_worker_context worker_context[term.render.workers.count];
|
||||||
|
|
||||||
|
/* Initialize 'current' colors from the default colors */
|
||||||
|
term.colors.fg = term.colors.default_fg;
|
||||||
|
term.colors.bg = term.colors.default_bg;
|
||||||
|
|
||||||
/* Initialize the 256 gray-scale color cube */
|
/* Initialize the 256 gray-scale color cube */
|
||||||
{
|
{
|
||||||
#if 0 /* pick colors from term struct instead, since they can be changed runtime */
|
#if 0 /* pick colors from term struct instead, since they can be changed runtime */
|
||||||
|
|
@ -517,18 +524,6 @@ main(int argc, char *const *argv)
|
||||||
memcpy(term.colors.colors256, term.colors.default_colors256, sizeof(term.colors.colors256));
|
memcpy(term.colors.colors256, term.colors.default_colors256, sizeof(term.colors.colors256));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("using %zu rendering threads", term.render.workers.count);
|
|
||||||
|
|
||||||
struct render_worker_context worker_context[term.render.workers.count];
|
|
||||||
|
|
||||||
/* Initialize 'current' colors from the default colors */
|
|
||||||
term.colors.fg = term.colors.default_fg;
|
|
||||||
term.colors.bg = term.colors.default_bg;
|
|
||||||
for (size_t i = 0; i < 8; i++) {
|
|
||||||
term.colors.regular[i] = term.colors.default_regular[i];
|
|
||||||
term.colors.bright[i] = term.colors.default_bright[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (term.ptmx == -1) {
|
if (term.ptmx == -1) {
|
||||||
LOG_ERR("failed to open pseudo terminal");
|
LOG_ERR("failed to open pseudo terminal");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
34
osc.c
34
osc.c
|
|
@ -291,11 +291,7 @@ osc_dispatch(struct terminal *term)
|
||||||
|
|
||||||
/* Client queried for current value */
|
/* Client queried for current value */
|
||||||
if (strlen(string) == 1 && string[0] == '?') {
|
if (strlen(string) == 1 && string[0] == '?') {
|
||||||
uint32_t color =
|
uint32_t color = term->colors.colors256[idx];
|
||||||
(idx >= 0 && idx < 8) ? term->colors.regular[idx] :
|
|
||||||
(idx >= 8 && idx < 16) ? term->colors.bright[idx - 8] :
|
|
||||||
term->colors.colors256[idx];
|
|
||||||
|
|
||||||
uint8_t r = (color >> 16) & 0xff;
|
uint8_t r = (color >> 16) & 0xff;
|
||||||
uint8_t g = (color >> 8) & 0xff;
|
uint8_t g = (color >> 8) & 0xff;
|
||||||
uint8_t b = (color >> 0) & 0xff;
|
uint8_t b = (color >> 0) & 0xff;
|
||||||
|
|
@ -311,13 +307,7 @@ osc_dispatch(struct terminal *term)
|
||||||
if (!parse_rgb(string, &color))
|
if (!parse_rgb(string, &color))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (idx >= 0 && idx < 8)
|
term->colors.colors256[idx] = color;
|
||||||
term->colors.regular[idx] = color;
|
|
||||||
else if (idx >= 8 && idx < 16)
|
|
||||||
term->colors.bright[idx - 8] = color;
|
|
||||||
else
|
|
||||||
term->colors.colors256[idx] = color;
|
|
||||||
|
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -373,11 +363,7 @@ osc_dispatch(struct terminal *term)
|
||||||
/* Reset Color Number 'c' (whole table if no parameter) */
|
/* Reset Color Number 'c' (whole table if no parameter) */
|
||||||
|
|
||||||
if (strlen(string) == 0) {
|
if (strlen(string) == 0) {
|
||||||
for (size_t i = 0; i < 8; i++) {
|
for (size_t i = 0; i < 256; i++)
|
||||||
term->colors.regular[i] = term->colors.default_regular[i];
|
|
||||||
term->colors.bright[i] = term->colors.default_bright[i];
|
|
||||||
}
|
|
||||||
for (size_t i = 16; i < 256; i++)
|
|
||||||
term->colors.colors256[i] = term->colors.default_colors256[i];
|
term->colors.colors256[i] = term->colors.default_colors256[i];
|
||||||
} else {
|
} else {
|
||||||
unsigned idx = 0;
|
unsigned idx = 0;
|
||||||
|
|
@ -385,12 +371,7 @@ osc_dispatch(struct terminal *term)
|
||||||
for (; *string != '\0'; string++) {
|
for (; *string != '\0'; string++) {
|
||||||
char c = *string;
|
char c = *string;
|
||||||
if (c == ';') {
|
if (c == ';') {
|
||||||
if (idx >= 0 && idx < 8)
|
term->colors.colors256[idx] = term->colors.default_colors256[idx];
|
||||||
term->colors.regular[idx] = term->colors.default_regular[idx];
|
|
||||||
else if (idx >= 8 && idx < 16)
|
|
||||||
term->colors.bright[idx - 8] = term->colors.default_bright[idx - 8];
|
|
||||||
else if (idx < 256)
|
|
||||||
term->colors.colors256[idx] = term->colors.default_colors256[idx];
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -399,12 +380,7 @@ osc_dispatch(struct terminal *term)
|
||||||
idx += c - '0';
|
idx += c - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx >= 0 && idx < 8)
|
term->colors.colors256[idx] = term->colors.default_colors256[idx];
|
||||||
term->colors.regular[idx] = term->colors.default_regular[idx];
|
|
||||||
else if (idx >= 8 && idx < 16)
|
|
||||||
term->colors.bright[idx - 8] = term->colors.default_bright[idx - 8];
|
|
||||||
else if (idx < 256)
|
|
||||||
term->colors.colors256[idx] = term->colors.default_colors256[idx];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,6 @@ term_reset(struct terminal *term, bool hard)
|
||||||
term->blink.state = BLINK_ON;
|
term->blink.state = BLINK_ON;
|
||||||
term->colors.fg = term->colors.default_fg;
|
term->colors.fg = term->colors.default_fg;
|
||||||
term->colors.bg = term->colors.default_bg;
|
term->colors.bg = term->colors.default_bg;
|
||||||
for (size_t i = 0; i < 8; i++) {
|
|
||||||
term->colors.regular[i] = term->colors.default_regular[i];
|
|
||||||
term->colors.bright[i] = term->colors.default_bright[i];
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < 256; i++)
|
for (size_t i = 0; i < 256; i++)
|
||||||
term->colors.colors256[i] = term->colors.default_colors256[i];
|
term->colors.colors256[i] = term->colors.default_colors256[i];
|
||||||
term->print_needs_wrap = false;
|
term->print_needs_wrap = false;
|
||||||
|
|
|
||||||
|
|
@ -285,15 +285,11 @@ struct terminal {
|
||||||
struct {
|
struct {
|
||||||
uint32_t fg;
|
uint32_t fg;
|
||||||
uint32_t bg;
|
uint32_t bg;
|
||||||
uint32_t regular[8];
|
|
||||||
uint32_t bright[8];
|
|
||||||
uint32_t colors256[256];
|
uint32_t colors256[256];
|
||||||
double alpha;
|
double alpha;
|
||||||
|
|
||||||
uint32_t default_fg;
|
uint32_t default_fg;
|
||||||
uint32_t default_bg;
|
uint32_t default_bg;
|
||||||
uint32_t default_regular[8];
|
|
||||||
uint32_t default_bright[8];
|
|
||||||
uint32_t default_colors256[256];
|
uint32_t default_colors256[256];
|
||||||
} colors;
|
} colors;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue