8 #include <sys/select.h>
14 static int init(void);
15 static void cleanup(void);
17 static void display(void);
18 static void reshape(int x, int y);
19 static void keypress(unsigned char key, int x, int y);
20 static void keyrelease(unsigned char key, int x, int y);
21 static void sighandler(int s);
23 int win_width, win_height;
27 int main(int argc, char **argv)
34 if(!(shell = getenv("SHELL"))) {
37 if((pty = open("/dev/ptmx", O_RDWR)) == -1) {
38 fprintf(stderr, "failed to open pseudoterminal\n");
50 if(open(ptsname(pty), O_RDWR) == -1) {
59 execl(shell, shell, (void*)0);
63 glutInit(&argc, argv);
64 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
65 glutInitWindowSize(800, 600);
66 glutCreateWindow("termu");
68 glutDisplayFunc(display);
69 glutReshapeFunc(reshape);
70 glutKeyboardFunc(keypress);
71 glutKeyboardUpFunc(keyrelease);
79 signal(SIGCHLD, sighandler);
81 xfd = miniglut_x11_socket();
82 maxfd = xfd > pty ? xfd : pty;
89 XFlush(miniglut_x11_display());
90 while(select(maxfd + 1, &rdset, 0, 0, 0) == -1 && errno == EINTR);
92 if(FD_ISSET(pty, &rdset)) {
93 rdsz = read(pty, buf, sizeof buf);
94 if(term_proc(buf, rdsz)) {
98 if(FD_ISSET(xfd, &rdset)) {
106 static int init(void)
113 width = TERM_COLS * fontw * 2;
114 height = width / 1.333333333;
115 glutReshapeWindow(width, height);
121 static void cleanup(void)
126 static void display(void)
129 unsigned char *scrptr = scrbuf;
131 glClearColor(0.1, 0.1, 0.1, 1);
132 glClear(GL_COLOR_BUFFER_BIT);
134 glMatrixMode(GL_PROJECTION);
136 glOrtho(0, TERM_COLS, 0, TERM_ROWS, -1, 1);
138 glMatrixMode(GL_MODELVIEW);
142 for(i=0; i<TERM_ROWS; i++) {
143 for(j=0; j<TERM_COLS; j++) {
144 if(*scrptr && *scrptr != ' ') {
145 draw_glyph(j, i, *scrptr);
155 static void reshape(int x, int y)
161 glViewport(0, 0, x, y);
164 static unsigned char shifted[] = {
165 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
166 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
167 "\040\041\042\043\044\045\046\047\050\051\052\053<_>?"
172 "PQRSTUVWXYZ{|}~\077"
175 static void keypress(unsigned char key, int x, int y)
177 unsigned int mod = glutGetModifiers();
181 if(mod & GLUT_ACTIVE_CTRL) {
190 if(mod & GLUT_ACTIVE_SHIFT) {
199 static void keyrelease(unsigned char key, int x, int y)
203 static void sighandler(int s)
207 printf("shell exited, closing terminal\n");