From b5642ac35e52fa9b5b5816a0fcec16ae30c2dced Mon Sep 17 00:00:00 2001 From: cancel Date: Tue, 11 Dec 2018 23:32:15 +0900 Subject: [PATCH] Add workaround for linux virtual console colors init error --- tui_main.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tui_main.c b/tui_main.c index 4c3b022..d5e2adc 100644 --- a/tui_main.c +++ b/tui_main.c @@ -1585,18 +1585,26 @@ int main(int argc, char** argv) { // hasn't typed anything. That way we can mix other timers in our code, // instead of being a slave only to terminal input. // nodelay(stdscr, TRUE); - // Enable color - start_color(); - use_default_colors(); - - for (int ifg = 0; ifg < Colors_count; ++ifg) { - for (int ibg = 0; ibg < Colors_count; ++ibg) { - int res = init_pair((short int)(1 + ifg * Colors_count + ibg), - (short int)(ifg - 1), (short int)(ibg - 1)); - if (res == ERR) { - endwin(); - fprintf(stderr, "Error initializing color\n"); - exit(1); + + if (has_colors()) { + // Enable color + start_color(); + use_default_colors(); + for (int ifg = 0; ifg < Colors_count; ++ifg) { + for (int ibg = 0; ibg < Colors_count; ++ibg) { + int res = init_pair((short int)(1 + ifg * Colors_count + ibg), + (short int)(ifg - 1), (short int)(ibg - 1)); + (void)res; + // Might fail on Linux virtual console/terminal for a couple of colors. + // Just ignore. +#if 0 + if (res == ERR) { + endwin(); + fprintf(stderr, "Error initializing color pair: %d %d\n", ifg - 1, + ibg - 1); + exit(1); + } +#endif } } }