term: prepare for configurable colors; add color variables to terminal

This commit is contained in:
Daniel Eklöf 2019-07-21 10:58:09 +02:00
parent b18478f9b6
commit 29d855d7c6
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 19 additions and 10 deletions

4
csi.c
View file

@ -111,8 +111,8 @@ static void
sgr_reset(struct terminal *term) sgr_reset(struct terminal *term)
{ {
memset(&term->vt.attrs, 0, sizeof(term->vt.attrs)); memset(&term->vt.attrs, 0, sizeof(term->vt.attrs));
term->vt.attrs.foreground = term->foreground; term->vt.attrs.foreground = term->colors.fg;
term->vt.attrs.background = term->background; term->vt.attrs.background = term->colors.bg;
} }
static const char * static const char *

4
main.c
View file

@ -346,8 +346,8 @@ main(int argc, char *const *argv)
.cmd = REPEAT_STOP, .cmd = REPEAT_STOP,
}, },
}, },
.foreground = default_foreground, .colors.fg = default_foreground,
.background = default_background, .colors.bg = default_background,
.selection = { .selection = {
.start = {-1, -1}, .start = {-1, -1},
.end = {-1, -1}, .end = {-1, -1},

2
osc.c
View file

@ -18,7 +18,7 @@ osc_query(struct terminal *term, unsigned param)
switch (param) { switch (param) {
case 10: case 10:
case 11: { case 11: {
uint32_t color = param == 10 ? term->foreground : term->background; uint32_t color = param == 10 ? term->colors.fg : term->colors.bg;
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;

View file

@ -105,10 +105,10 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
uint32_t _fg = cell->attrs.foreground >> 31 uint32_t _fg = cell->attrs.foreground >> 31
? cell->attrs.foreground ? cell->attrs.foreground
: !term->reverse ? term->foreground : term->background; : !term->reverse ? term->colors.fg : term->colors.bg;
uint32_t _bg = cell->attrs.background >> 31 uint32_t _bg = cell->attrs.background >> 31
? cell->attrs.background ? cell->attrs.background
: !term->reverse ? term->background : term->foreground; : !term->reverse ? term->colors.bg : term->colors.fg;
/* If *one* is set, we reverse */ /* If *one* is set, we reverse */
if (has_cursor ^ cell->attrs.reverse ^ is_selected) { if (has_cursor ^ cell->attrs.reverse ^ is_selected) {
@ -307,7 +307,7 @@ grid_render(struct terminal *term)
int rmargin_width = term->width - rmargin; int rmargin_width = term->width - rmargin;
int bmargin_height = term->height - bmargin; int bmargin_height = term->height - bmargin;
uint32_t _bg = !term->reverse ? term->background : term->foreground; uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg;
struct rgb bg = color_hex_to_rgb(_bg); struct rgb bg = color_hex_to_rgb(_bg);
cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b); cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b);

View file

@ -259,8 +259,17 @@ struct terminal {
bool print_needs_wrap; bool print_needs_wrap;
struct scroll_region scroll_region; struct scroll_region scroll_region;
uint32_t foreground; struct {
uint32_t background; uint32_t fg;
uint32_t bg;
uint32_t regular[8];
uint32_t bright[8];
uint32_t default_fg;
uint32_t defualt_bg;
uint32_t default_regular[8];
uint32_t defualt_bright[8];
} colors;
struct { struct {
int col; int col;