From 01f154bae839e37bfb7090eb90fb660a2639f954 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 31 Aug 2006 21:52:34 -0700 Subject: [PATCH] ansicon support for SOH # color table handling --- com32/lib/sys/ansicon_write.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/com32/lib/sys/ansicon_write.c b/com32/lib/sys/ansicon_write.c index 29f9d83..31f3e1a 100644 --- a/com32/lib/sys/ansicon_write.c +++ b/com32/lib/sys/ansicon_write.c @@ -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 */ -- 2.7.4