diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-07-21 09:32:35 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-07-21 09:32:35 +0000 |
| commit | 16979927bacb617ef6c8cccb013ee6ff9eb93f78 (patch) | |
| tree | b2636e6e5ee897a1e6821141577475f9f0f6512d | |
| parent | csi: use colors from terminal struct (diff) | |
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.
| -rw-r--r-- | csi.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -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; } |
