1 /* Just a simple example program that creates a terminal in a frame
2 * and lets the user interact with it.
5 * gcc -o boxshell boxshell.c $(pkg-config madtty --cflags --libs)
13 #include <sys/ioctl.h>
18 #include <madtty/madtty.h>
20 static unsigned char getout = 0;
21 static int screen_w, screen_h;
22 static WINDOW *term_win;
24 void handler(int signo)
40 signal(SIGCHLD, handler);
41 signal(SIGWINCH, handler);
44 getmaxyx(stdscr, screen_h, screen_w);
46 /* create a window with a frame */
47 term_win = newwin(screen_h - 2, screen_w - 2, 1, 1);
48 rt = madtty_create(screen_h - 2, screen_w - 2);
50 const char *path = getenv("SHELL") ?: "/bin/sh";
51 const char *args[] = { path, "--login", NULL};
53 madtty_forkpty(rt, path, args);
56 /* keep reading keypresses from the user and passing them to the terminal;
57 * also, redraw the terminal to the window at each iteration */
60 struct timeval tv = { 0, 1000 * 1000 / 50 };
65 FD_SET(rt->pty, &rfds);
67 if (select(rt->pty + 1, &rfds, NULL, NULL, &tv) > 0) {
68 if (FD_ISSET(rt->pty, &rfds)) {
74 while ((ch = getch()) != ERR) {
83 ioctl(rt->pty, TIOCSWINSZ, &ws);
84 wresize(term_win, rt->rows, rt->cols);
87 madtty_keypress(rt, ch); /* pass the keypress for handling */
92 madtty_draw(rt, term_win, 0, 0);