Added fallback color scheme for 8 color terminals
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Sun, 2 Nov 2014 19:04:05 +0000 (20:04 +0100)
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Sun, 2 Nov 2014 19:04:05 +0000 (20:04 +0100)
2048.c

diff --git a/2048.c b/2048.c
index 820edbe..3e9a717 100644 (file)
--- a/2048.c
+++ b/2048.c
@@ -57,17 +57,25 @@ int oldhighscore=0;
 uint8_t blackwhite[] = {232,7,234,7,236,7,238,7,240,7,242,7,244,7,246,0,248,0,249,0,250,0,251,0,252,0,253,0,254,0,7,0};
 uint8_t original[] = {8,7,1,7,2,7,3,0,4,7,5,7,6,7,7,0,9,0,10,0,11,0,12,0,13,0,14,0,7,0,7,0};
 uint8_t bluered[] = {235,7,63,7,57,7,93,7,129,7,165,7,201,7,200,7,199,7,198,7,197,7,196,7,196,7,196,7,196,7,196,7};
+uint8_t fallback[] = {7, 0, 0, 1, 0, 2, 0, 3, 0, 4, 4, 5, 6, 1, 7, 3, 0, 7, 1, 3, 2, 5, 3, 6, 4, 1, 5, 5, 6, 1, 7, 3};
 uint8_t *scheme = NULL;
-void getColor(uint16_t value, char *color, size_t length) {
+void getColor(uint16_t value, char *color, size_t length) 
+{
   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,"\e[31m\033[38;5;%d;48;5;%dm",*foreground,*background);
+  uint8_t *fbg = fallback+1;
+  uint8_t *ffg = fallback;
+  if (value > 0) while (value >>= 1) 
+                  {
+                    if (background+2<scheme+sizeof(original)) 
+                      {
+                        background+=2;
+                        foreground+=2;
+                        fbg +=2;
+                        ffg +=2;
+                      }
+                  }
+  snprintf(color,length,"\e[3%d;4%dm\033[38;5;%d;48;5;%dm",*ffg,*fbg,*foreground,*background);
 }
 
 void drawBoard(uint16_t board[SIZE][SIZE]) {