Tweak was incorrectly handling the terminal default colour scheme.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 7 Dec 2004 12:05:50 +0000 (12:05 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 7 Dec 2004 12:05:50 +0000 (12:05 +0000)
I've fixed this using use_default_colors(), which I believe are
ncurses extensions (but I think I was ncurses-specific already owing
to KEY_RESIZE).

git-svn-id: svn://svn.tartarus.org/sgt/tweak@4949 cda61777-01e9-0310-a592-d414129be87e

curses.c
main.c
slang.c

index f11d777..ea8b5ac 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -28,8 +28,10 @@ void display_setup(void)
     move(0,0);
     refresh();
     get_screen_size();
-    if (has_colors())
+    if (has_colors()) {
        start_color();
+        use_default_colors();
+    }
 }
 
 void display_cleanup(void)
@@ -73,11 +75,14 @@ void display_define_colour(int colour, int fg, int bg)
         COLOR_WHITE,
     };
 
-    assert(colour >= 0 && colour < MAXCOLOURS && colour < COLOR_PAIRS-2);
-
-    assert(!(bg & ~7));                       /* bold backgrounds are nonportable */
-    init_pair(colour+1, colours[fg & 7], colours[bg]);
-    attrs[colour] = (fg & 8 ? A_BOLD : 0) | COLOR_PAIR(colour+1);
+    if (fg < 0 && bg < 0) {
+        attrs[colour] = 0;
+    } else {
+        assert(colour >= 0 && colour < MAXCOLOURS && colour < COLOR_PAIRS-2);
+        assert(!(bg & ~7));            /* bold backgrounds are nonportable */
+        init_pair(colour+1, colours[fg & 7], colours[bg]);
+        attrs[colour] = (fg & 8 ? A_BOLD : 0) | COLOR_PAIR(colour+1);
+    }
 }
 
 void display_set_colour(int colour)
diff --git a/main.c b/main.c
index 2e7d179..adb3254 100644 (file)
--- a/main.c
+++ b/main.c
@@ -251,7 +251,7 @@ static void init(void) {
 
     display_setup();
 
-    display_define_colour(COL_BUFFER, 7, 0);
+    display_define_colour(COL_BUFFER, -1, -1);
     display_define_colour(COL_SELECT, 0, 7);
     display_define_colour(COL_STATUS, 11, 4);
     display_define_colour(COL_ESCAPE, 9, 0);
@@ -499,9 +499,11 @@ void draw_scr (void) {
                    display_write_chars(linebuf+10+3*localstop,
                                       2+3*width-3*localstop);
                }
-           } else
+           } else {
+                display_set_colour(COL_BUFFER);
                display_write_chars(linebuf,
                                   ascii_enabled ? 13+4*width : 10+3*width);
+            }
        }
        currpos += (currpos ? width : offset);
        display_clear_to_eol();
diff --git a/slang.c b/slang.c
index 0dca727..a6e0b37 100644 (file)
--- a/slang.c
+++ b/slang.c
@@ -119,6 +119,12 @@ void display_define_colour(int colour, int fg, int bg)
     };
     char cname[40];
 
+    if (fg < 0 && bg < 0) {
+        /* FIXME: not sure how to support terminal default fg+bg */
+        fg = 7;
+        bg = 0;
+    }
+
     sprintf(cname, "colour%d", colour);
 
     SLtt_set_color(colour, cname, colours[fg], colours[bg]);