ansicon support for SOH # color table handling
authorH. Peter Anvin <hpa@zytor.com>
Fri, 1 Sep 2006 04:52:34 +0000 (21:52 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 1 Sep 2006 04:52:34 +0000 (21:52 -0700)
com32/lib/sys/ansicon_write.c

index 29f9d83..31f3e1a 100644 (file)
@@ -51,6 +51,9 @@ enum ansi_state {
   st_init,                     /* Normal (no ESC seen) */
   st_esc,                      /* ESC seen */
   st_csi,                      /* CSI seen */
+  st_soh,                      /* SOH seen */
+  st_sohc,                     /* SOH # seen */
+  st_sohc1,                    /* SOH # digit seen */
 };
 
 #define MAX_PARMS      16
@@ -181,6 +184,9 @@ static void ansicon_putchar(int ch)
   switch ( st.state ) {
   case st_init:
     switch ( ch ) {
+    case 1:
+      st.state = st_soh;
+      break;
     case '\b':
       if ( xy.x > 0 ) xy.x--;
       break;
@@ -501,6 +507,45 @@ static void ansicon_putchar(int ch)
       }
     }
     break;
+
+  case st_soh:
+    if ( ch == '#' )
+      state = st_sohc;
+    else
+      state = st_init;
+    break;
+
+  case st_sohc:
+    {
+      int n = (unsigned char)ch - '0';
+      if (n < 10) {
+       st.param[0] = n*10;
+       state = st_sohc1;
+      } else {
+       state = st_init;
+      }
+    }
+    break;
+
+  case st_sohc1:
+    {
+      int n = (unsigned char)ch - '0';
+      const char *p;
+
+      if (n < 10) {
+       st.param[0] += n;
+       /* Emulate the appropriate CSI m sequence */
+       if (st.param[0] < console_color_table_size) {
+         state = st_csi;
+         for (p = console_color_table[st.param[0]]; *p; p++)
+           ansicon_putchar(*p);
+         ansicon_putchar('m');
+       }
+      }
+
+      state = st_init;
+    }
+    break;
   }
 
   /* If we fell off the end of the screen, adjust */