X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=demo%2Fboxshell.c;h=44a9d9c243eac2bca45668b4b7ab4945f30e67a9;hb=7e9bf69df0c4b6cd9a94172e71d7c6a584341f52;hp=a1d746e2c0627c4d18ccb9615a076ca62a6e910c;hpb=1f877e6f07a48bc78f0b38d4fba4306d3a4688a2;p=apps%2Fmadtty.git diff --git a/demo/boxshell.c b/demo/boxshell.c index a1d746e..44a9d9c 100644 --- a/demo/boxshell.c +++ b/demo/boxshell.c @@ -6,7 +6,6 @@ */ #include -#include #include #include #include @@ -27,7 +26,7 @@ void sigchld(int signo __attribute__((unused))) int main(int argc, char *argv[]) { struct timeval next = { 0, 0 }; - RoteTerm *rt; + madtty_t *rt; int i, j, ch, w, h, pos; char buf[BUFSIZ]; @@ -42,51 +41,27 @@ int main(int argc, char *argv[]) h = strtol(p, &p, 10); } - setlocale(LC_ALL, ""); - initscr(); - noecho(); - start_color(); - raw(); - nodelay(stdscr, TRUE); /* prevents getch() from blocking; rather - * it will return ERR when there is no - * keypress available */ - - keypad(stdscr, TRUE); /* necessary to use rote_vt_keypress */ + madtty_initialize(); getmaxyx(stdscr, screen_h, screen_w); - /* initialize the color pairs the way rote_vt_draw expects it. You might - * initialize them differently, but in that case you would need - * to supply a custom conversion function for rote_vt_draw to - * call when setting attributes. The idea of this "default" mapping - * is to map (fg, bg) to the color pair bg * 8 + 7 - fg. This way, - * the pair (white, black) ends up mapped to 0, which means that - * it does not need a color pair (since it is the default). Since - * there are only 63 available color pairs (and 64 possible fg/bg - * combinations), we really have to save 1 pair by assigning no pair - * to the combination white/black. */ - for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) - if (i != 7 || j != 0) - init_pair(j*8+7-i, i, j); - /* paint the screen blue */ - attrset(COLOR_PAIR(32)); + 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 + 2, w + 2, 2, 3); - wborder(term_win, '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'); + term_win = newwin(h, w, 2, 3); mvwprintw(term_win, 0, 27, " Term In a Box "); wrefresh(term_win); - rt = rote_vt_create(h, w); + rt = madtty_create(h, w); { const char *path = getenv("SHELL") ?: "/bin/sh"; const char *args[] = { path, "--login", NULL}; - rote_vt_forkpty(rt, path, args); + madtty_forkpty(rt, path, args); } /* keep reading keypresses from the user and passing them to the terminal; @@ -103,12 +78,12 @@ int main(int argc, char *argv[]) if (select(rt->pty + 1, &rfds, NULL, NULL, &tv) > 0) { int nb; - nb = rote_vt_read(rt, buf + pos, sizeof(buf) - pos); + nb = madtty_read(rt, buf + pos, sizeof(buf) - pos); if (nb <= 0) continue; pos += nb; - nb = rote_vt_inject(rt, buf, pos); + nb = madtty_inject(rt, buf, pos); if (nb <= 0) continue; memmove(buf, buf + nb, pos - nb); @@ -116,15 +91,15 @@ int main(int argc, char *argv[]) } while ((ch = getch()) != ERR) { - rote_vt_keypress(rt, ch); /* pass the keypress for handling */ + madtty_keypress(rt, ch); /* pass the keypress for handling */ } gettimeofday(&t, NULL); if (timercmp(&t, &next, >=)) { - rote_vt_draw(rt, term_win, 1, 1); + madtty_draw(rt, term_win, 0, 0); wrefresh(term_win); gettimeofday(&next, NULL); - next.tv_usec += 1000 * 1000 / 100; + next.tv_usec += 1000 * 1000 / 50; if (next.tv_usec > 1000 * 1000) { next.tv_usec -= 1000 * 1000; next.tv_sec++;