Skip to contentSkip to conversation

commands: 2048: use 16-color ANSI palette

PATCH Applied Ahmad Fatoum 2 participants 2 messages May 2 – May 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commands: 2048: use 16-color ANSI palette

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.

---
 commands/2048.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
commands/2048.c +7 -2
index c8b35bdb7d0a..6d35e03d4889 100644
@@ -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])
Signature · 1 line
2.47.3
Applied
#1 lore raw
Quoted 6 lines · Ahmad Fatoum

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.

Applied, thanks!

[1/1] commands: 2048: use 16-color ANSI palette
https://git.pengutronix.de/cgit/barebox/commit/?id=447d7bf2590d (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>