From c56fb7d6300b718a0634ec91eee86fba8a6a2f73 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Mon, 25 Dec 2006 11:25:06 +0200 Subject: [PATCH] Bug 871: Fall back to 16 colors if color_mode is unsupported. There may currently be no way to select an unsupported mode, but the next commit will change that. --- src/terminal/color.c | 6 ++++++ src/terminal/screen.c | 14 ++++++++++++-- src/viewer/dump/dump.c | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/terminal/color.c b/src/terminal/color.c index 6e8ff94ed..6f54d951a 100644 --- a/src/terminal/color.c +++ b/src/terminal/color.c @@ -301,6 +301,9 @@ set_term_color(struct screen_char *schar, struct color_pair *pair, } break; + default: + /* If the desired color mode was not compiled in, + * use 16 colors. */ case COLOR_MODE_16: /* Decrease the range of the 16 palette to not include * bright colors. */ @@ -386,6 +389,9 @@ set_term_color(struct screen_char *schar, struct color_pair *pair, case COLOR_MODE_TRUE_COLOR: return; #endif + default: + /* If the desired color mode was not compiled in, + * use 16 colors. */ case COLOR_MODE_MONO: case COLOR_MODE_16: set_term_color16(schar, flags, fg, bg); diff --git a/src/terminal/screen.c b/src/terminal/screen.c index f4e2d56aa..77b8fad5b 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -612,7 +612,15 @@ add_char16(struct string *screen, struct screen_driver *driver, add_bytes_to_string(screen, "\033[0", 3); - if (driver->color_mode == COLOR_MODE_16) { + /* @update_screen_driver has set @driver->color_mode + * according to terminal-type-specific options. + * The caller of @add_char16 has already partially + * checked it, but there are still these possibilities: + * - COLOR_MODE_MONO. Then don't show colors, but + * perhaps use the standout attribute. + * - COLOR_MODE_16. Use 16 colors. + * - An unsupported color mode. Use 16 colors. */ + if (driver->color_mode != COLOR_MODE_MONO) { unsigned char code[6] = ";30;40"; unsigned char bgcolor = TERM_COLOR_BACKGROUND_16(ch->color); @@ -956,6 +964,9 @@ redraw_screen(struct terminal *term) if (!init_string(&image)) return; switch (driver->color_mode) { + default: + /* If the desired color mode was not compiled in, + * use 16 colors. */ case COLOR_MODE_MONO: case COLOR_MODE_16: add_chars(&image, term, driver, &state, add_char16, compare_bg_color_16, compare_fg_color_16); @@ -977,7 +988,6 @@ redraw_screen(struct terminal *term) #endif case COLOR_MODES: case COLOR_MODE_DUMP: - default: INTERNAL("Invalid color mode (%d).", driver->color_mode); return; } diff --git a/src/viewer/dump/dump.c b/src/viewer/dump/dump.c index 506b5e631..f042df6e4 100644 --- a/src/viewer/dump/dump.c +++ b/src/viewer/dump/dump.c @@ -132,6 +132,9 @@ dump_formatted(int fd, struct download *download, struct cache_entry *cached) case COLOR_MODE_MONO: /* FIXME: inversion */ dump_to_file(formatted.document, fd); break; + default: + /* If the desired color mode was not compiled in, + * use 16 colors. */ case COLOR_MODE_16: dump_to_file_16(formatted.document, fd); break; @@ -150,8 +153,6 @@ dump_formatted(int fd, struct download *download, struct cache_entry *cached) dump_to_file_true_color(formatted.document, fd); break; #endif - default: - break; } detach_formatted(&formatted);