X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=demo%2Fboxshell.c;h=43c007a2a90ab95281e4c9d48f2f76b6fee2c38a;hb=880886ae6dca338d2d57e4b85cf984f4022ec520;hp=cdc980cf12bc0d78c06d80c55366f71d4ce38243;hpb=5618d7a42ce62103e5f29da3756b81f57198b22f;p=apps%2Fmadtty.git diff --git a/demo/boxshell.c b/demo/boxshell.c index cdc980c..43c007a 100644 --- a/demo/boxshell.c +++ b/demo/boxshell.c @@ -72,25 +72,45 @@ int main(int argc, char *argv[]) /* create a window with a frame */ term_win = newwin(h + 2, w + 2, 1, 2); wattrset(term_win, COLOR_PAIR(7*8+7-0)); /* black over white */ - wborder(term_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wborder(term_win, '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'); mvwprintw(term_win, 0, 27, " Term In a Box "); wrefresh(term_win); /* create the terminal and have it run bash */ rt = rote_vt_create(h, w); - rote_vt_forkpty(rt, "/bin/bash --login"); + { + const char *path = "/bin/bash"; + const char *args[] = {"/bin/bash", "--login", NULL}; + + rote_vt_forkpty(rt, path, args); + } /* keep reading keypresses from the user and passing them to the terminal; * also, redraw the terminal to the window at each iteration */ ch = '\0'; while (!getout) { - usleep(10000); - rote_vt_draw(rt, term_win, 1, 1, NULL); - wrefresh(term_win); + fd_set rfds; + struct timeval tv = { 0 , 1000 }; + + FD_ZERO(&rfds); + FD_SET(rt->pty, &rfds); + + if (select(rt->pty + 1, &rfds, NULL, NULL, &tv) > 0) { + char buf[512]; + int nbread; - ch = getch(); - if (ch != ERR) + nbread = rote_vt_read(rt, buf, sizeof(buf)); + if (nbread > 0) + rote_vt_inject(rt, buf, nbread); + } + + + while ((ch = getch()) != ERR) { rote_vt_keypress(rt, ch); /* pass the keypress for handling */ + } + + rote_vt_draw(rt, term_win, 1, 1, NULL); + wrefresh(term_win); } endwin();