* to avoid possible artifacts like syscalls returning EINTR because of our
* interrupting clock signal. An alternative would be using an auto-restart
* signal with SA_RESTART that takes care of all updates while taking care not
- * to execute syscalls that are not signal handler safe.
+ * to execute syscalls that are not signal handler safe. This now also uses
+ * erase() and doupdate() instead of clear() and refresh(), removing the
+ * requirement for clearok() to prevent double clears.
+ * This version can also preserve default terminal colors like the foreground,
+ * using an extension to X/Open that both ncurses and BSD curses support.
*
* TODO
* - Consider another test keeping the time to determine if to delay again,
* instead of relying on signal interruption by an interval timer. This
- * possibly could allow more reliable user input.
- * - See if calling termios directly can be avoided with OSX still restoring
- * the tty settings properly. Also look at
- * reset_shell_mode()/reset_prog_mode(), def_shell_mode()/def_prog_mode().
+ * possibly could allow more reliable user input. However, non-blocking
+ * getch() may potentially interfere with key arrow sequence interpretation.
*
* $ cc -Wall -O0 -g -o test7 test7.c -lcurses
*/
/* Exit cleanup hook to restore normal terminal */
(void)atexit(cleanup);
+ /*
+ * XXX Useful but relies on an ncurses extension, also supported by
+ * NetBSD curses. init_pair() cannot accept -1 according to X/Open.
+ * But this special value means to keep the default foreground or
+ * background color of the terminal configuration. This also permits
+ * enforced color pairs to really only define the foreground or
+ * background color.
+ */
+ (void)use_default_colors();
if (start_color() == ERR)
err(EXIT_FAILURE, "start_color()");
- (void)init_pair(0, COLOR_WHITE, COLOR_BLACK);
- (void)init_pair(1, COLOR_WHITE, COLOR_RED);
- (void)init_pair(2, COLOR_WHITE, COLOR_GREEN);
- (void)init_pair(3, COLOR_WHITE, COLOR_YELLOW);
- (void)init_pair(4, COLOR_WHITE, COLOR_BLUE);
- (void)init_pair(5, COLOR_WHITE, COLOR_MAGENTA);
- (void)init_pair(6, COLOR_WHITE, COLOR_CYAN);
- (void)init_pair(7, COLOR_WHITE, COLOR_WHITE);
+ (void)init_pair(0, -1, COLOR_BLACK);
+ (void)init_pair(1, -1, COLOR_RED);
+ (void)init_pair(2, -1, COLOR_GREEN);
+ (void)init_pair(3, -1, COLOR_YELLOW);
+ (void)init_pair(4, -1, COLOR_BLUE);
+ (void)init_pair(5, -1, COLOR_MAGENTA);
+ (void)init_pair(6, -1, COLOR_CYAN);
+ (void)init_pair(7, -1, COLOR_WHITE);
(void)cbreak(); /* Use raw() if not wanting SIGINT */
(void)noecho();
(void)keypad(w, TRUE);
+ (void)nonl();
+ (void)intrflush(stdscr, FALSE);
(void)timeout(-1);
/* Setup animation world */
anim_init();
/* Initialize screen */
- (void)clear();
- (void)clearok(w, FALSE);
+ (void)erase();
safe_refresh();
(void)curs_set(0);
set = block_mask;
(void)sigprocmask(SIG_BLOCK, &set, NULL);
- (void)wrefresh(w);
+ (void)doupdate();
set = block_mask;
(void)sigprocmask(SIG_UNBLOCK, &set, NULL);
int i;
(void)attrset(COLOR_PAIR(0));
- (void)clear();
- (void)clearok(w, FALSE);
+ (void)erase();
for (i = 0; i < NOBJECTS; i++) {
aobject_t *o = &objects[i];