X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=demo%2Fboxshell.c;fp=demo%2Fboxshell.c;h=7c9512d423fc57c9e48a0fb14a37333c692ad1f2;hb=f5196e6e851c7d1dcf8c7e9c50f4da314c6ac238;hp=b3c8f2d9d033c20c1357f901962c1492e55ef7c3;hpb=5c99ba24e74e451d0c256b46134d38ee17054565;p=apps%2Fmadtty.git diff --git a/demo/boxshell.c b/demo/boxshell.c index b3c8f2d..7c9512d 100644 --- a/demo/boxshell.c +++ b/demo/boxshell.c @@ -6,10 +6,13 @@ */ #include -#include + #include +#include #include +#include #include +#include #include #include @@ -18,17 +21,24 @@ static unsigned char getout = 0; static int screen_w, screen_h; static WINDOW *term_win; -void sigchld(int signo __attribute__((unused))) +void handler(int signo) { - getout = 1; + switch (signo) { + case SIGCHLD: + getout = 1; + break; + case SIGWINCH: + break; + } } int main(void) { - struct timeval next = { 0, 0 }; madtty_t *rt; + int dirty = 0; - signal(SIGCHLD, sigchld); + signal(SIGCHLD, handler); + signal(SIGWINCH, handler); madtty_initialize(); getmaxyx(stdscr, screen_h, screen_w); @@ -47,31 +57,40 @@ int main(void) * also, redraw the terminal to the window at each iteration */ while (!getout) { fd_set rfds; - struct timeval tv = { 0 , 1000 }, t; + struct timeval tv = { 0, 1000 * 1000 / 50 }; int ch; FD_ZERO(&rfds); FD_SET(rt->pty, &rfds); if (select(rt->pty + 1, &rfds, NULL, NULL, &tv) > 0) { - if (madtty_process(rt)) - break; + if (FD_ISSET(rt->pty, &rfds)) { + madtty_process(rt); + dirty = 1; + } } while ((ch = getch()) != ERR) { +#if 0 + if (ch == KEY_F(3)) { + struct winsize ws = { + .ws_row = --rt->rows, + .ws_col = --rt->cols, + }; + + erase(); + ioctl(rt->pty, TIOCSWINSZ, &ws); + wresize(term_win, rt->rows, rt->cols); + } +#endif madtty_keypress(rt, ch); /* pass the keypress for handling */ + dirty = 1; } - gettimeofday(&t, NULL); - if (timercmp(&t, &next, >=)) { + if (dirty) { madtty_draw(rt, term_win, 0, 0); wrefresh(term_win); - gettimeofday(&next, NULL); - next.tv_usec += 1000 * 1000 / 50; - if (next.tv_usec > 1000 * 1000) { - next.tv_usec -= 1000 * 1000; - next.tv_sec++; - } + dirty = 0; } }