mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/5] fbconsole: use symbolic names for ANSI colors
@ 2025-06-01 20:59 Ahmad Fatoum
  2025-06-01 20:59 ` [PATCH 2/5] fbconsole: darken shade of non-bright white Ahmad Fatoum
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-06-01 20:59 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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@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




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-06-02  7:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-01 20:59 [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Ahmad Fatoum
2025-06-01 20:59 ` [PATCH 2/5] fbconsole: darken shade of non-bright white Ahmad Fatoum
2025-06-01 21:00 ` [PATCH 3/5] fbconsole: add support for aixterm bright colors Ahmad Fatoum
2025-06-01 21:00 ` [PATCH 4/5] fbconsole: use only one default color Ahmad Fatoum
2025-06-01 21:00 ` [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts Ahmad Fatoum
2025-06-01 21:02   ` Ahmad Fatoum
2025-06-02  7:42   ` (subset) " Sascha Hauer
2025-06-02  7:42 ` (subset) [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox