cmenu: reset attributes instead of using ANSI sequence 22
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Mon, 31 Aug 2009 06:47:46 +0000 (23:47 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Tue, 1 Sep 2009 18:45:11 +0000 (11:45 -0700)
hpa advised not to use ANSI sequence 22, as it may not work everywhere.
Instead, let's reset attributes and set last_attr to unknown. The next
background/foreground tests are then guaranteed to fire. We take a small
hit in terms of performance though.

Misc.: change initialization of last_attr to 0x300 (unknown) to trigger
properly the tests the first time.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/cmenu/libmenu/com32io.c

index ca207ee..3c4f921 100644 (file)
@@ -29,7 +29,7 @@ com32sys_t inreg, outreg;     // Global register sets for use
 static void cprint_vga2ansi(const char chr, const char attr)
 {
        static const char ansi_char[8] = "04261537";
-       static uint8_t last_attr = 0x07;
+       static uint8_t last_attr = 0x300;
        char buf[16], *p;
 
        if (attr != last_attr) {
@@ -37,13 +37,12 @@ static void cprint_vga2ansi(const char chr, const char attr)
                *p++ = '\033';
                *p++ = '[';
 
-               /* Beware! Do not use '1': this will reset all attributes off,
-                * including the background color - as a result, the background
-                * would be black after the highlight area <X> */
                if (last_attr & ~attr & 0x88) {
-                       *p++ = '2';
-                       *p++ = '2';
+                       *p++ = '0';
                        *p++ = ';';
+                       /* Reset last_attr to unknown to handle
+                        * background/foreground attributes correctly */
+                       last_attr = 0x300;
                }
                if (attr & 0x08) {
                        *p++ = '1';