[PATCH 1/5] fbconsole: use symbolic names for ANSI colors
Ahmad Fatoum
a.fatoum at barebox.org
Sun Jun 1 13:59:58 PDT 2025
Instead of hardcoding color indices, let's define symbolic names and use
them throughout. This makes it clear that we are using different default
colors, which will be fixed in the follow-up commit.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
drivers/video/fbconsole.c | 51 +++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 401b36c4de73..55df524a96a3 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -32,6 +32,11 @@ static const char * const rotation_names[] = {
[FBCONSOLE_ROTATE_270] = "270",
};
+enum ansi_color {
+ BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE,
+ BRIGHT
+};
+
struct fbc_priv {
struct console_device cdev;
struct fb_info *fb;
@@ -111,22 +116,22 @@ struct rgb {
};
static struct rgb colors[] = {
- { 0, 0, 0 },
- { 205, 0, 0 },
- { 0, 205, 0 },
- { 205, 205, 0 },
- { 0, 0, 238 },
- { 205, 0, 205 },
- { 0, 205, 205 },
- { 229, 229, 229 },
- { 127, 127, 127 },
- { 255, 0, 0 },
- { 0, 255, 0 },
- { 255, 255, 0 },
- { 92, 92, 255 },
- { 255, 0, 255 },
- { 0, 255, 255 },
- { 255, 255, 255 },
+ [BLACK] = { 0, 0, 0 },
+ [RED] = { 205, 0, 0 },
+ [GREEN] = { 0, 205, 0 },
+ [YELLOW] = { 205, 205, 0 },
+ [BLUE] = { 0, 0, 238 },
+ [MAGENTA] = { 205, 0, 205 },
+ [CYAN] = { 0, 205, 205 },
+ [WHITE] = { 229, 229, 229 },
+ [BRIGHT + BLACK] = { 127, 127, 127 },
+ [BRIGHT + RED] = { 255, 0, 0 },
+ [BRIGHT + GREEN] = { 0, 255, 0 },
+ [BRIGHT + YELLOW] = { 255, 255, 0 },
+ [BRIGHT + BLUE] = { 92, 92, 255 },
+ [BRIGHT + MAGENTA] = { 255, 0, 255 },
+ [BRIGHT + CYAN] = { 0, 255, 255 },
+ [BRIGHT + WHITE] = { 255, 255, 255 },
};
static void drawchar(struct fbc_priv *priv, int x, int y, int c)
@@ -155,7 +160,7 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
bgcolor = priv->flags & ANSI_FLAG_INVERT ? priv->color : priv->bgcolor;
if (priv->flags & ANSI_FLAG_BRIGHT)
- color += 8;
+ color += BRIGHT;
rgb = &colors[color];
color = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0xff);
@@ -490,8 +495,8 @@ static void fbc_parse_colors(struct fbc_priv *priv)
switch (code) {
case 0:
priv->flags = 0;
- priv->color = 8;
- priv->bgcolor = 0;
+ priv->color = BRIGHT + BLACK;
+ priv->bgcolor = BLACK;
break;
case 1:
priv->flags |= ANSI_FLAG_BRIGHT;
@@ -503,13 +508,13 @@ static void fbc_parse_colors(struct fbc_priv *priv)
priv->color = code - 30;
break;
case 39:
- priv->color = 7;
+ priv->color = WHITE;
break;
case 40 ... 47:
priv->bgcolor = code - 40;
break;
case 49:
- priv->bgcolor = 0;
+ priv->bgcolor = BLACK;
break;
}
@@ -814,8 +819,8 @@ int register_fbconsole(struct fb_info *fb)
priv->fb = fb;
priv->x = 0;
priv->y = 0;
- priv->color = 7;
- priv->bgcolor = 0;
+ priv->color = WHITE;
+ priv->bgcolor = BLACK;
cdev = &priv->cdev;
cdev->dev = &fb->dev;
--
2.39.5
More information about the barebox
mailing list