diff --git a/src/terminal/draw.c b/src/terminal/draw.c index ea5b0d0a..58923945 100644 --- a/src/terminal/draw.c +++ b/src/terminal/draw.c @@ -21,12 +21,13 @@ int_bounds(&(x), 0, (term)->width - 1); \ int_bounds(&(y), 0, (term)->height - 1); \ } while (0) -#if defined(CONFIG_TRUE_COLOR) -#define clear_screen_char_color(schar) do { memset((schar)->color, 0, 6); } while (0) -#elif defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS) -#define clear_screen_char_color(schar) do { memset((schar)->color, 0, 2); } while (0) + +#if SCREEN_COLOR_SIZE > 1 +#define clear_screen_char_color(schar) \ + do { memset((schar)->color, 0, SCREEN_COLOR_SIZE); } while (0) #else -#define clear_screen_char_color(schar) do { (schar)->color[0] = 0; } while (0) +#define clear_screen_char_color(schar) \ + do { (schar)->color[0] = 0; } while (0) #endif diff --git a/src/terminal/draw.h b/src/terminal/draw.h index 75f1bdae..965a0a01 100644 --- a/src/terminal/draw.h +++ b/src/terminal/draw.h @@ -7,6 +7,16 @@ struct color_pair; struct box; struct terminal; +#if defined(CONFIG_TRUE_COLOR) +/* 0, 1, 2 - rgb foreground; 3, 4, 5 - rgb background */ +#define SCREEN_COLOR_SIZE 6 +#elif defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS) +/* 0 is foreground; 1 is background */ +#define SCREEN_COLOR_SIZE 2 +#else +#define SCREEN_COLOR_SIZE 1 +#endif + /* All attributes should fit inside an unsigned char. */ /* XXX: The bold mask is used as part of the color encoding. */ enum screen_char_attr { @@ -30,16 +40,8 @@ struct screen_char { /* Attributes are screen_char_attr bits. */ unsigned char attr; -#if defined(CONFIG_TRUE_COLOR) - /* 0, 1, 2 - rgb foreground, - 3, 4, 5 - rgb background */ - unsigned char color[6]; - /* The encoded fore- and background color. */ -#elif defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS) - unsigned char color[2]; -#else - unsigned char color[1]; -#endif + /* The fore- and background color. */ + unsigned char color[SCREEN_COLOR_SIZE]; }; #define copy_screen_chars(to, from, amount) \ diff --git a/src/terminal/screen.c b/src/terminal/screen.c index 94d25b6f..4e302aad 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -422,13 +422,7 @@ struct screen_state { unsigned char bold; unsigned char attr; /* Following should match struct screen_char color field. */ -#if defined(CONFIG_TRUE_COLOR) - unsigned char color[6]; -#elif defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS) - unsigned char color[2]; -#else - unsigned char color[1]; -#endif + unsigned char color[SCREEN_COLOR_SIZE]; }; #if defined(CONFIG_TRUE_COLOR)