}
}
-static void init_colors(void)
+static void init_pair_or_die(short pair, short f, short b)
+{
+ if (init_pair(pair, f, b) == ERR)
+ msg_n_exit(EXIT_FAILURE, "fatal: init_pair() failed\n");
+}
+
+static void init_colors_or_die(void)
{
int i;
if (!has_colors())
- msg_n_exit(EXIT_FAILURE, "Error: No color term\n");
- start_color();
+ msg_n_exit(EXIT_FAILURE, "fatal: No color term\n");
+ if (start_color() == ERR)
+ msg_n_exit(EXIT_FAILURE, "fatal: failed to start colors\n");
FOR_EACH_STATUS_ITEM(i)
if (theme.data[i].len)
- init_pair(i + 1, theme.data[i].fg, theme.data[i].bg);
- init_pair(COLOR_STATUSBAR, theme.sb_fg, theme.sb_bg);
- init_pair(COLOR_COMMAND, theme.cmd_fg, theme.cmd_bg);
- init_pair(COLOR_OUTPUT, theme.output_fg, theme.output_bg);
- init_pair(COLOR_MSG, theme.msg_fg, theme.msg_bg);
- init_pair(COLOR_ERRMSG, theme.err_msg_fg, theme.err_msg_bg);
- init_pair(COLOR_WELCOME, theme.welcome_fg, theme.welcome_bg);
- init_pair(COLOR_SEPARATOR, theme.sep_fg, theme.sep_bg);
- init_pair(COLOR_TOP, theme.default_fg, theme.default_bg);
- init_pair(COLOR_BOT, theme.default_fg, theme.default_bg);
+ init_pair_or_die(i + 1, theme.data[i].fg,
+ theme.data[i].bg);
+ init_pair_or_die(COLOR_STATUSBAR, theme.sb_fg, theme.sb_bg);
+ init_pair_or_die(COLOR_COMMAND, theme.cmd_fg, theme.cmd_bg);
+ init_pair_or_die(COLOR_OUTPUT, theme.output_fg, theme.output_bg);
+ init_pair_or_die(COLOR_MSG, theme.msg_fg, theme.msg_bg);
+ init_pair_or_die(COLOR_ERRMSG, theme.err_msg_fg, theme.err_msg_bg);
+ init_pair_or_die(COLOR_WELCOME, theme.welcome_fg, theme.welcome_bg);
+ init_pair_or_die(COLOR_SEPARATOR, theme.sep_fg, theme.sep_bg);
+ init_pair_or_die(COLOR_TOP, theme.default_fg, theme.default_bg);
+ init_pair_or_die(COLOR_BOT, theme.default_fg, theme.default_bg);
}
-/* (Re-)initialize the curses library. FIXME: Error checking. */
+/* (Re-)initialize the curses library. */
static void init_curses(void)
{
curses_active = 1;
" (need at least %dx%d)\n", COLS, LINES,
theme.cols_min, theme.lines_min);
curs_set(0); /* make cursor invisible, ignore errors */
- nonl(); /* tell curses not to do NL->CR/NL on output */
- noecho(); /* don't echo input */
- cbreak(); /* take input chars one at a time, no wait for \n */
- init_colors();
- clear();
+ nonl(); /* do not NL->CR/NL on output, always returns OK */
+ /* don't echo input */
+ if (noecho() == ERR)
+ msg_n_exit(EXIT_FAILURE, "fatal: noecho() failed\n");
+ /* take input chars one at a time, no wait for \n */
+ if (cbreak() == ERR)
+ msg_n_exit(EXIT_FAILURE, "fatal: cbreak() failed\n");
+ init_colors_or_die();
+ clear(); /* ignore non-fatal errors */
init_wins(theme.top_lines_default);
print_all_items();
- noecho(); /* don't echo input */
+ // noecho(); /* don't echo input */
}
static void check_sigchld(void)