From: simon Date: Tue, 7 Dec 2004 12:05:50 +0000 (+0000) Subject: Tweak was incorrectly handling the terminal default colour scheme. X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/tweak/commitdiff_plain/1610a3c6b38c6d659e29d06550229fe1aae24372 Tweak was incorrectly handling the terminal default colour scheme. 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 --- diff --git a/curses.c b/curses.c index f11d777..ea8b5ac 100644 --- 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 --- 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 --- 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]);