#include #include #include #include #include #include #include FILE *f; static void resize_sig_handler(int signo) { struct winsize win; ioctl(STDIN_FILENO, TIOCGWINSZ, &win); /* Avoid bogus sizes. */ if (win.ws_col > 10 && win.ws_row > 5) { /* Setup the ncurses library internal data. */ resizeterm(win.ws_row, win.ws_col); fprintf(f, "resized to %d, %d\n", win.ws_row, win.ws_col); } refresh(); signal(SIGWINCH, resize_sig_handler); } int main() { struct sigaction resize_sig; int c; resize_sig.sa_handler = resize_sig_handler; sigemptyset(&resize_sig.sa_mask); resize_sig.sa_flags = SA_RESTART; sigaction(SIGWINCH, &resize_sig, NULL); initscr(); start_color(); noecho(); nonl(); raw(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); mvaddstr(0, 0, "enter keys, type q to quit."); refresh(); f = fopen("t.out", "a"); fprintf(f, "################\n"); do { // XXX with the following two lines uncommented, it works. // nodelay(stdscr, TRUE); c = getch(); // nodelay(stdscr, FALSE); if (c == KEY_RESIZE) fprintf(f, "got KEY_RESIZE\n"); else if (c != ERR) fprintf(f, "got %d '%c'\n", c, c); } while (c != 'q'); fclose(f); endwin(); }