X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-ui%2Fmadtty.c;h=4cc53fbf38748040866880e6c52ed441b0e31d9e;hb=819c071fa7efc8dffb4dd92f36f0111227ff692f;hp=135e9a7765da88b799ca84bce6e35bb0359e5ff9;hpb=00f34116b32751764d42f81159c292d850c74bac;p=apps%2Fmadmutt.git diff --git a/lib-ui/madtty.c b/lib-ui/madtty.c index 135e9a7..4cc53fb 100644 --- a/lib-ui/madtty.c +++ b/lib-ui/madtty.c @@ -19,19 +19,12 @@ Copyright © 2006 Pierre Habouzit */ -#include -#include -#include +#include + #include #include -#include -#include -#include -#include #include -#include #include -#include #include "madtty.h" @@ -962,9 +955,8 @@ void madtty_keypress(madtty_t *t, int keycode) void madtty_init_colors(void) { - if (COLORS > 8) { + if (COLOR_PAIRS > 64) { use_default_colors(); - assume_default_colors(-1, -1); has_default = 1; for (int bg = -1; bg < 8; bg++) { @@ -973,9 +965,16 @@ void madtty_init_colors(void) } } } else { + int use_default = use_default_colors() == OK; for (int bg = 0; bg < 8; bg++) { for (int fg = 0; fg < 8; fg++) { - init_pair((7 - fg) * 8 + bg, fg, bg); + if (use_default) { + init_pair((7 - fg) * 8 + bg, + fg == COLOR_WHITE ? -1 : fg, + bg == COLOR_BLACK ? -1 : bg); + } else { + init_pair((7 - fg) * 8 + bg, fg, bg); + } } } } @@ -983,9 +982,16 @@ void madtty_init_colors(void) int madtty_color_pair(int fg, int bg) { - if (fg < -1) - fg = -1; - if (bg < -1) - bg = -1; - return COLOR_PAIR(has_default ? (fg + 1) * 16 + bg + 1 : (7 - fg) * 8 + bg); + if (has_default) { + if (fg < -1) + fg = -1; + if (bg < -1) + bg = -1; + return COLOR_PAIR((fg + 1) * 16 + bg + 1); + } + if (fg < 0) + fg = COLOR_WHITE; + if (bg < 0) + bg = COLOR_BLACK; + return COLOR_PAIR((7 - fg) * 8 + bg); }