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] commands: 2048: use 16-color ANSI palette
Date: Sat,  2 May 2026 13:36:24 +0200	[thread overview]
Message-ID: <20260502113624.1832173-1-a.fatoum@barebox.org> (raw)

The 256-color xterm sequences (38;5;n / 48;5;n) require xterm-256color
terminal support. Switch to standard 16-color ANSI SGR codes, which work
on any VT100-compatible terminal and can also be displayed fine by the
barebox framebuffer console.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 commands/2048.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/commands/2048.c b/commands/2048.c
index c8b35bdb7d0a..6d35e03d4889 100644
--- a/commands/2048.c
+++ b/commands/2048.c
@@ -13,17 +13,22 @@ static uint32_t score;
 
 static void getColor(uint16_t value, char *color, size_t length)
 {
-	uint8_t original[] = {8,255,1,255,2,255,3,255,4,255,5,255,6,255,7,255,9,0,10,0,11,0,12,0,13,0,14,0,255,0,255,0};
+	uint8_t original[] = {
+		0,7, 1,7, 2,7, 3,0, 4,7, 5,7, 6,7, 7,0,
+		1,0, 2,0, 3,0, 4,0, 5,0, 6,0, 7,0, 0,7
+	};
 	uint8_t *scheme = original;
 	uint8_t *background = scheme+0;
 	uint8_t *foreground = scheme+1;
+
 	if (value > 0) while (value >>= 1) {
 		if (background+2<scheme+sizeof(original)) {
 			background+=2;
 			foreground+=2;
 		}
 	}
-	snprintf(color,length,"\033[38;5;%d;48;5;%dm",*foreground,*background);
+
+	snprintf(color, length, "\033[%d;%dm", 30 + *foreground, 40 + *background);
 }
 
 static void drawBoard(uint16_t board[SIZE][SIZE])
-- 
2.47.3




             reply	other threads:[~2026-05-02 11:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-02 11:36 Ahmad Fatoum [this message]
2026-05-07 10:38 ` 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=20260502113624.1832173-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