X-Git-Url: http://git.madism.org/?p=apps%2Fmadtty.git;a=blobdiff_plain;f=demo%2Fboxshell.c;fp=demo%2Fboxshell.c;h=dbb47e4690644720f2e002173841a7bfa1108dd6;hp=44a9d9c243eac2bca45668b4b7ab4945f30e67a9;hb=f38bb36465858ae6af3776175010e8c09e70f980;hpb=7e9bf69df0c4b6cd9a94172e71d7c6a584341f52 diff --git a/demo/boxshell.c b/demo/boxshell.c index 44a9d9c..dbb47e4 100644 --- a/demo/boxshell.c +++ b/demo/boxshell.c @@ -23,40 +23,21 @@ void sigchld(int signo __attribute__((unused))) getout = 1; } -int main(int argc, char *argv[]) +int main(void) { struct timeval next = { 0, 0 }; madtty_t *rt; - int i, j, ch, w, h, pos; + int pos = 0; char buf[BUFSIZ]; signal(SIGCHLD, sigchld); - w = 80; - h = 40; - if (argc > 1) { - char *p = argv[1]; - w = strtol(p, &p, 10); - if (*p++ == 'x') - h = strtol(p, &p, 10); - } - madtty_initialize(); getmaxyx(stdscr, screen_h, screen_w); - /* paint the screen blue */ - attrset(COLOR_PAIR(004)); - for (i = 0; i < screen_h; i++) - for (j = 0; j < screen_w; j++) - addch(' '); - refresh(); - /* create a window with a frame */ - term_win = newwin(h, w, 2, 3); - mvwprintw(term_win, 0, 27, " Term In a Box "); - wrefresh(term_win); - - rt = madtty_create(h, w); + term_win = newwin(screen_h - 2, screen_w - 2, 1, 1); + rt = madtty_create(screen_h - 2, screen_w - 2); { const char *path = getenv("SHELL") ?: "/bin/sh"; const char *args[] = { path, "--login", NULL}; @@ -66,28 +47,18 @@ int main(int argc, char *argv[]) /* keep reading keypresses from the user and passing them to the terminal; * also, redraw the terminal to the window at each iteration */ - ch = '\0'; pos = 0; while (!getout) { fd_set rfds; struct timeval tv = { 0 , 1000 }, t; + int ch; FD_ZERO(&rfds); FD_SET(rt->pty, &rfds); if (select(rt->pty + 1, &rfds, NULL, NULL, &tv) > 0) { - int nb; - - nb = madtty_read(rt, buf + pos, sizeof(buf) - pos); - if (nb <= 0) - continue; - pos += nb; - - nb = madtty_inject(rt, buf, pos); - if (nb <= 0) - continue; - memmove(buf, buf + nb, pos - nb); - pos -= nb; + if (madtty_process(rt)) + break; } while ((ch = getch()) != ERR) {