From 7ad3bb9d6b6def7127e4c6063dac85e2709b20eb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 25 Apr 2014 01:05:08 -0400 Subject: refactor --- src/display.c | 8 ++++---- src/screen.c | 21 +++++++++------------ src/screen.h | 29 ++++++++++++++++------------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/display.c b/src/display.c index b0d380a..a85fdaf 100644 --- a/src/display.c +++ b/src/display.c @@ -153,12 +153,12 @@ static void runes_display_draw_cell(RunesTerm *t, int row, int col) struct runes_cell *cell = &t->scr.rows[row].cells[col]; cairo_pattern_t *bg = NULL, *fg = NULL; - switch (cell->bgcolor.type) { + switch (cell->attrs.bgcolor.type) { case RUNES_COLOR_DEFAULT: bg = t->bgdefault; break; case RUNES_COLOR_IDX: - bg = t->colors[cell->bgcolor.idx]; + bg = t->colors[cell->attrs.bgcolor.idx]; break; case RUNES_COLOR_RGB: /* XXX */ @@ -166,12 +166,12 @@ static void runes_display_draw_cell(RunesTerm *t, int row, int col) break; } - switch (cell->fgcolor.type) { + switch (cell->attrs.fgcolor.type) { case RUNES_COLOR_DEFAULT: fg = t->fgdefault; break; case RUNES_COLOR_IDX: - fg = t->colors[cell->fgcolor.idx]; + fg = t->colors[cell->attrs.fgcolor.idx]; break; case RUNES_COLOR_RGB: /* XXX */ diff --git a/src/screen.c b/src/screen.c index 7f89916..8e0b333 100644 --- a/src/screen.c +++ b/src/screen.c @@ -64,8 +64,7 @@ void runes_screen_show_string_ascii(RunesTerm *t, char *buf, size_t len) cell->len = 1; cell->contents[0] = buf[i]; cell->contents[1] = '\0'; - cell->fgcolor = scr->fgcolor; - cell->bgcolor = scr->bgcolor; + cell->attrs = scr->attrs; scr->cur.col++; } @@ -89,8 +88,7 @@ void runes_screen_show_string_utf8(RunesTerm *t, char *buf, size_t len) cell->len = next - c; strncpy(cell->contents, c, cell->len); - cell->fgcolor = scr->fgcolor; - cell->bgcolor = scr->bgcolor; + cell->attrs = scr->attrs; scr->cur.col++; c = next; @@ -215,16 +213,15 @@ void runes_screen_set_scroll_region( void runes_screen_reset_text_attributes(RunesTerm *t) { - runes_screen_reset_fg_color(t); - runes_screen_reset_bg_color(t); + memset(&t->scr.attrs, 0, sizeof(struct runes_cell_attrs)); } void runes_screen_set_fg_color(RunesTerm *t, int idx) { RunesScreen *scr = &t->scr; - scr->fgcolor.type = RUNES_COLOR_IDX; - scr->fgcolor.idx = idx; + scr->attrs.fgcolor.type = RUNES_COLOR_IDX; + scr->attrs.fgcolor.idx = idx; } void runes_screen_set_fg_color_rgb(RunesTerm *t, int r, int g, int b) @@ -240,15 +237,15 @@ void runes_screen_reset_fg_color(RunesTerm *t) { RunesScreen *scr = &t->scr; - scr->fgcolor.type = RUNES_COLOR_DEFAULT; + scr->attrs.fgcolor.type = RUNES_COLOR_DEFAULT; } void runes_screen_set_bg_color(RunesTerm *t, int idx) { RunesScreen *scr = &t->scr; - scr->bgcolor.type = RUNES_COLOR_IDX; - scr->bgcolor.idx = idx; + scr->attrs.bgcolor.type = RUNES_COLOR_IDX; + scr->attrs.bgcolor.idx = idx; } void runes_screen_set_bg_color_rgb(RunesTerm *t, int r, int g, int b) @@ -264,7 +261,7 @@ void runes_screen_reset_bg_color(RunesTerm *t) { RunesScreen *scr = &t->scr; - scr->bgcolor.type = RUNES_COLOR_DEFAULT; + scr->attrs.bgcolor.type = RUNES_COLOR_DEFAULT; } void runes_screen_set_bold(RunesTerm *t) diff --git a/src/screen.h b/src/screen.h index 77f12f2..c0cab3a 100644 --- a/src/screen.h +++ b/src/screen.h @@ -24,15 +24,24 @@ struct runes_color { unsigned char type; }; +struct runes_cell_attrs { + struct runes_color fgcolor; + struct runes_color bgcolor; + union { + struct { + unsigned char bold: 1; + unsigned char italic: 1; + unsigned char underline: 1; + unsigned char inverse: 1; + }; + unsigned char attrs; + }; +}; + struct runes_cell { char contents[8]; size_t len; - struct runes_color fgcolor; - struct runes_color bgcolor; - unsigned char bold: 1; - unsigned char italic: 1; - unsigned char underline: 1; - unsigned char inverse: 1; + struct runes_cell_attrs attrs; }; struct runes_row { @@ -53,13 +62,7 @@ struct runes_screen { struct runes_row *rows; - struct runes_color fgcolor; - struct runes_color bgcolor; - - unsigned char bold: 1; - unsigned char italic: 1; - unsigned char underline: 1; - unsigned char inverse: 1; + struct runes_cell_attrs attrs; unsigned char hide_cursor: 1; unsigned char application_keypad: 1; -- cgit v1.2.3-54-g00ecf