/* wait: * -1: non-blocking, always draw screen * 0: blocking wait for input and always draw screen * 1: non-blocking, draw screen only if a configured delay has passed or after keypress */ int input_handle(int wait) { int ch; struct timeval tv; nodelay(stdscr, wait?1:0); if(wait != 1) screen_draw(); else { gettimeofday(&tv, (void *)NULL); tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / update_delay; if(lastupdate != tv.tv_usec) { screen_draw(); lastupdate = tv.tv_usec; } } while((ch = getch()) != ERR) { if(ch == KEY_RESIZE) { if(ncresize(min_rows, min_cols)) min_rows = min_cols = 0; screen_draw(); continue; } switch(pstate) { case ST_CALC: return calc_key(ch); case ST_BROWSE: return browse_key(ch); case ST_HELP: return help_key(ch); case ST_DEL: return delete_key(ch); } screen_draw(); } return 0; }
/* wait: * -1: non-blocking, always draw screen * 0: blocking wait for input and always draw screen * 1: non-blocking, draw screen only if a configured delay has passed or after keypress */ int input_handle(int wait) { int ch; struct timeval tv; if(wait != 1) screen_draw(); else { gettimeofday(&tv, (void *)NULL); tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / update_delay; if(lastupdate != tv.tv_usec) { screen_draw(); lastupdate = tv.tv_usec; } } /* No actual input handling is done if ncurses hasn't been initialized yet. */ if(!ncurses_init) return wait == 0 ? 1 : 0; nodelay(stdscr, wait?1:0); while((ch = getch()) != ERR) { if(ch == KEY_RESIZE) { if(ncresize(min_rows, min_cols)) min_rows = min_cols = 0; /* ncresize() may change nodelay state, make sure to revert it. */ nodelay(stdscr, wait?1:0); screen_draw(); continue; } switch(pstate) { case ST_CALC: return dir_key(ch); case ST_BROWSE: return browse_key(ch); case ST_HELP: return help_key(ch); case ST_DEL: return delete_key(ch); } screen_draw(); } return 0; }