aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-08-21 16:47:48 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-08-21 16:47:48 +0000
commit631e0c0870d98a4b3f97c90a8f3d07d549fdf8fb (patch)
tree9de02fa30d0ff9fe42e794ea4a036cc472726601
parentosc: fix indexing into 'bright' color array (diff)
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.
-rw-r--r--csi.c29
-rw-r--r--main.c25
-rw-r--r--osc.c34
-rw-r--r--terminal.c4
-rw-r--r--terminal.h4
5 files changed, 22 insertions, 74 deletions
diff --git a/csi.c b/csi.c
index 52772e7d..9eb50dae 100644
--- a/csi.c
+++ b/csi.c
@@ -105,7 +105,7 @@ csi_sgr(struct terminal *term)
case 36:
case 37:
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;
case 38: {
@@ -113,15 +113,8 @@ csi_sgr(struct terminal *term)
term->vt.params.v[i + 1].value == 5)
{
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.fg = color;
+ term->vt.attrs.fg = term->colors.colors256[idx];
i += 2;
}
@@ -175,7 +168,7 @@ csi_sgr(struct terminal *term)
case 46:
case 47:
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;
case 48: {
@@ -183,16 +176,8 @@ csi_sgr(struct terminal *term)
term->vt.params.v[i + 1].value == 5)
{
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.bg = color;
+ term->vt.attrs.bg = term->colors.colors256[idx];
i += 2;
}
@@ -245,10 +230,10 @@ csi_sgr(struct terminal *term)
case 96:
case 97:
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;
- /* Regular background colors */
+ /* Bright background colors */
case 100:
case 101:
case 102:
@@ -258,7 +243,7 @@ csi_sgr(struct terminal *term)
case 106:
case 107:
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;
default:
diff --git a/main.c b/main.c
index 720729db..2185dbbd 100644
--- a/main.c
+++ b/main.c
@@ -445,7 +445,7 @@ main(int argc, char *const *argv)
.colors = {
.default_fg = conf.colors.fg,
.default_bg = conf.colors.bg,
- .default_regular = {
+ .default_colors256 = {
conf.colors.regular[0],
conf.colors.regular[1],
conf.colors.regular[2],
@@ -454,8 +454,7 @@ main(int argc, char *const *argv)
conf.colors.regular[5],
conf.colors.regular[6],
conf.colors.regular[7],
- },
- .default_bright = {
+
conf.colors.bright[0],
conf.colors.bright[1],
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 */
{
#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));
}
- 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) {
LOG_ERR("failed to open pseudo terminal");
goto out;
diff --git a/osc.c b/osc.c
index 64ea481d..2fd1e08f 100644
--- a/osc.c
+++ b/osc.c
@@ -291,11 +291,7 @@ osc_dispatch(struct terminal *term)
/* Client queried for current value */
if (strlen(string) == 1 && string[0] == '?') {
- uint32_t color =
- (idx >= 0 && idx < 8) ? term->colors.regular[idx] :
- (idx >= 8 && idx < 16) ? term->colors.bright[idx - 8] :
- term->colors.colors256[idx];
-
+ uint32_t color = term->colors.colors256[idx];
uint8_t r = (color >> 16) & 0xff;
uint8_t g = (color >> 8) & 0xff;
uint8_t b = (color >> 0) & 0xff;
@@ -311,13 +307,7 @@ osc_dispatch(struct terminal *term)
if (!parse_rgb(string, &color))
break;
- if (idx >= 0 && idx < 8)
- term->colors.regular[idx] = color;
- else if (idx >= 8 && idx < 16)
- term->colors.bright[idx - 8] = color;
- else
- term->colors.colors256[idx] = color;
-
+ term->colors.colors256[idx] = color;
render_refresh(term);
break;
}
@@ -373,11 +363,7 @@ osc_dispatch(struct terminal *term)
/* Reset Color Number 'c' (whole table if no parameter) */
if (strlen(string) == 0) {
- 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 = 16; i < 256; i++)
+ for (size_t i = 0; i < 256; i++)
term->colors.colors256[i] = term->colors.default_colors256[i];
} else {
unsigned idx = 0;
@@ -385,12 +371,7 @@ osc_dispatch(struct terminal *term)
for (; *string != '\0'; string++) {
char c = *string;
if (c == ';') {
- if (idx >= 0 && idx < 8)
- 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];
+ term->colors.colors256[idx] = term->colors.default_colors256[idx];
idx = 0;
continue;
}
@@ -399,12 +380,7 @@ osc_dispatch(struct terminal *term)
idx += c - '0';
}
- if (idx >= 0 && idx < 8)
- 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];
+ term->colors.colors256[idx] = term->colors.default_colors256[idx];
}
render_refresh(term);
diff --git a/terminal.c b/terminal.c
index 3101056d..593bf8ff 100644
--- a/terminal.c
+++ b/terminal.c
@@ -61,10 +61,6 @@ term_reset(struct terminal *term, bool hard)
term->blink.state = BLINK_ON;
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];
- }
for (size_t i = 0; i < 256; i++)
term->colors.colors256[i] = term->colors.default_colors256[i];
term->print_needs_wrap = false;
diff --git a/terminal.h b/terminal.h
index c866679d..a104b897 100644
--- a/terminal.h
+++ b/terminal.h
@@ -285,15 +285,11 @@ struct terminal {
struct {
uint32_t fg;
uint32_t bg;
- uint32_t regular[8];
- uint32_t bright[8];
uint32_t colors256[256];
double alpha;
uint32_t default_fg;
uint32_t default_bg;
- uint32_t default_regular[8];
- uint32_t default_bright[8];
uint32_t default_colors256[256];
} colors;