mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 1/5] fbconsole: use symbolic names for ANSI colors
Date: Sun,  1 Jun 2025 22:59:58 +0200	[thread overview]
Message-ID: <20250601210002.562733-1-a.fatoum@barebox.org> (raw)

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




             reply	other threads:[~2025-06-01 21:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-01 20:59 Ahmad Fatoum [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250601210002.562733-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox