X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=gui.c;h=38addd9815cc5bf2775c80278679a1e9c64e872e;hp=42e7dd072ddbbad1ffdd04e8aeedab3884c51e53;hb=e4db7671a91a7552c642acc979f0eb278f8d467f;hpb=b3c78fae27ed5313c06aea24fcd5d8ea13a21fab diff --git a/gui.c b/gui.c index 42e7dd07..38addd98 100644 --- a/gui.c +++ b/gui.c @@ -400,11 +400,13 @@ static int draw_top_rbe(unsigned *lines) rbe = ringbuffer_get(bot_win_rb, fvr); if (!rbe) return -1; - /* first rbe might be only partially visible */ - offset = (*lines - bot.lines) * bot.cols; len = strlen(rbe->msg); - if (offset < 0 || len < offset) - return -1; + if (*lines > bot.lines) { + /* first rbe is only partially visible */ + offset = (*lines - bot.lines) * bot.cols; + assert(offset <= len); + } else + offset = 0; wattron(bot.win, COLOR_PAIR(rbe->color)); waddstr(bot.win, rbe->msg + offset); *lines = NUM_LINES(len - offset); @@ -655,14 +657,6 @@ static void init_wins(int top_lines) doupdate(); } -static void check_geometry(void) -{ - if (LINES < theme.lines_min || COLS < theme.cols_min) - msg_n_exit(EXIT_FAILURE, "Error: Terminal (%dx%d) too small" - " (need at least %dx%d)\n", COLS, LINES, - theme.cols_min, theme.lines_min); -} - /* * Print stat item #i to curses window */ @@ -767,53 +761,60 @@ static void clear_all_items(void) } } -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; - if (top.win && refresh() == ERR) { /* refesh is really needed */ + if (top.win && refresh() == ERR) /* refesh is really needed */ msg_n_exit(EXIT_FAILURE, "refresh() failed\n"); - } - check_geometry(); + if (LINES < theme.lines_min || COLS < theme.cols_min) + msg_n_exit(EXIT_FAILURE, "Error: Terminal (%dx%d) too small" + " (need at least %dx%d)\n", COLS, LINES, + theme.cols_min, theme.lines_min); curs_set(0); /* make cursor invisible, ignore errors */ -// if (noraw() == ERR); -// msg_n_exit(EXIT_FAILURE, "can not place terminal out of " -// "raw mode\n"); - 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 */ - //reset_prog_mode(); - 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) { int ret;