aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-08-21 15:56:21 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-08-21 15:56:21 +0000
commitd7aaeaedee981371f1137c058b60322155e9ba00 (patch)
tree68e8768734ec877b09bed43f533111bf62ce9263
parentmain: fix debug logs (diff)
csi: move 256-color table into the terminal struct
-rw-r--r--csi.c29
-rw-r--r--main.c24
-rw-r--r--terminal.c2
-rw-r--r--terminal.h2
4 files changed, 30 insertions, 27 deletions
diff --git a/csi.c b/csi.c
index 5adb5001..52772e7d 100644
--- a/csi.c
+++ b/csi.c
@@ -18,34 +18,9 @@
#define min(x, y) ((x) < (y) ? (x) : (y))
-static uint32_t colors256[256];
-
#define UNHANDLED() LOG_ERR("unhandled: %s", csi_as_string(term, final))
#define UNHANDLED_SGR() LOG_ERR("unhandled: %s", csi_as_string(term, 'm'))
-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++) {
- for (size_t b = 0; b < 6; b++) {
- colors256[16 + r * 6 * 6 + g * 6 + b]
- = r * 51 << 16 | g * 51 << 8 | b * 51;
- }
- }
- }
-
- for (size_t i = 0; i < 24; i++)
- colors256[232 + i] = i * 11 << 16 | i * 11 << 8 | i * 11;
-}
-
static void
sgr_reset(struct terminal *term)
{
@@ -144,7 +119,7 @@ csi_sgr(struct terminal *term)
else if (idx < 16)
color = term->colors.bright[idx - 8];
else
- color = colors256[idx];
+ color = term->colors.colors256[idx];
term->vt.attrs.have_fg = 1;
term->vt.attrs.fg = color;
i += 2;
@@ -215,7 +190,7 @@ csi_sgr(struct terminal *term)
else if (idx < 16)
color = term->colors.bright[idx - 8];
else
- color = colors256[idx];
+ color = term->colors.colors256[idx];
term->vt.attrs.have_bg = 1;
term->vt.attrs.bg = color;
i += 2;
diff --git a/main.c b/main.c
index 2326356e..720729db 100644
--- a/main.c
+++ b/main.c
@@ -493,6 +493,30 @@ main(int argc, char *const *argv)
},
};
+ /* Initialize the 256 gray-scale color cube */
+ {
+#if 0 /* pick colors from term struct instead, since they can be changed runtime */
+ for (size_t i = 0; i < 8; i++)
+ term.colors.default_colors256[i] = term.colors.default_regular[i];
+ for (size_t i = 0; i < 8; i++)
+ term.colors.default_colors256[8 + i] = term.colors.default_bright[i];
+#endif
+
+ for (size_t r = 0; r < 6; r++) {
+ for (size_t g = 0; g < 6; g++) {
+ for (size_t b = 0; b < 6; b++) {
+ term.colors.default_colors256[16 + r * 6 * 6 + g * 6 + b]
+ = r * 51 << 16 | g * 51 << 8 | b * 51;
+ }
+ }
+ }
+
+ for (size_t i = 0; i < 24; i++)
+ term.colors.default_colors256[232 + i] = i * 11 << 16 | i * 11 << 8 | i * 11;
+
+ 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];
diff --git a/terminal.c b/terminal.c
index b7133186..3101056d 100644
--- a/terminal.c
+++ b/terminal.c
@@ -65,6 +65,8 @@ term_reset(struct terminal *term, bool hard)
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;
term->cursor = (struct coord){0, 0};
term->saved_cursor = (struct coord){0, 0};
diff --git a/terminal.h b/terminal.h
index 02caec6b..c866679d 100644
--- a/terminal.h
+++ b/terminal.h
@@ -287,12 +287,14 @@ struct terminal {
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;
struct {