sortof works
authorJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 2 Nov 2023 20:51:30 +0000 (22:51 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 2 Nov 2023 20:51:30 +0000 (22:51 +0200)
.gitignore
src/main.c
src/term.c
src/term.h

index 0fb09dd..f28238d 100644 (file)
@@ -7,3 +7,4 @@ data/
 core
 *.ppm
 *.png
+.cache/
index a4b7347..81c0f4d 100644 (file)
@@ -30,6 +30,7 @@ int main(int argc, char **argv)
        char *shell;
        fd_set rdset;
        char buf[1024];
+       struct timeval tv;
 
        if(!(shell = getenv("SHELL"))) {
                shell = "/bin/sh";
@@ -86,8 +87,13 @@ int main(int argc, char **argv)
                FD_SET(pty, &rdset);
                FD_SET(xfd, &rdset);
 
+               tv.tv_sec = 0;
+               tv.tv_usec = 250000;
+
                XFlush(miniglut_x11_display());
-               while(select(maxfd + 1, &rdset, 0, 0, 0) == -1 && errno == EINTR);
+               while(select(maxfd + 1, &rdset, 0, 0, &tv) == -1 && errno == EINTR);
+
+               glutPostRedisplay();
 
                if(FD_ISSET(pty, &rdset)) {
                        rdsz = read(pty, buf, sizeof buf);
@@ -95,9 +101,9 @@ int main(int argc, char **argv)
                                glutPostRedisplay();
                        }
                }
-               if(FD_ISSET(xfd, &rdset)) {
+               /*if(FD_ISSET(xfd, &rdset)) {*/
                        glutMainLoopEvent();
-               }
+               /*}*/
        }
 
        return 0;
@@ -127,6 +133,7 @@ static void display(void)
 {
        int i, j;
        unsigned char *scrptr = scrbuf;
+       unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
 
        glClearColor(0.1, 0.1, 0.1, 1);
        glClear(GL_COLOR_BUFFER_BIT);
@@ -149,12 +156,23 @@ static void display(void)
        }
        text_end();
 
+       if(cursor_vis && (!cursor_blink || ((msec >> 9) & 1))) {
+               int y = 23 - cursor_y;
+
+               glLogicOp(GL_XOR);
+               glEnable(GL_COLOR_LOGIC_OP);
+
+               glColor3f(1, 1, 1);
+               glRectf(cursor_x + 0.1f, y + 1.0 / 9.0, cursor_x + 1, y + 0.95f);
+
+               glDisable(GL_COLOR_LOGIC_OP);
+       }
+
        glutSwapBuffers();
 }
 
 static void reshape(int x, int y)
 {
-       printf("RESHAPE\n");
        win_width = x;
        win_height = y;
 
@@ -164,7 +182,7 @@ static void reshape(int x, int y)
 static unsigned char shifted[] = {
        "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
        "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
-       "\040\041\042\043\044\045\046\047\050\051\052\053<_>?"
+       "\040\041\042\043\044\045\046\"\050\051\052\053<_>?"
        ")!@#$%^&*(;:<+>?"
        "@ABCDEFGHIJKLMNO"
        "PQRSTUVWXYZ{|}^_"
index e7c55f4..406c8d3 100644 (file)
@@ -6,11 +6,13 @@
 static void clearscr(void);
 static void scroll(void);
 
-int cursor_x, cursor_y, cursor_vis;
+int cursor_x, cursor_y, cursor_vis, cursor_blink;
 unsigned char scrbuf[TERM_COLS * TERM_ROWS];
 
 void term_init(void)
 {
+       cursor_vis = 1;
+       cursor_blink = 0;
        clearscr();
 }
 
@@ -34,12 +36,14 @@ static int proc_char(int c)
 {
        static int cbuf[8], clen;
 
+       /*
        if(isprint(c)) {
                printf(" %c", c);
        } else {
                printf(" %x", (unsigned int)c);
        }
        fflush(stdout);
+       */
 
        if(clen) {
                if(cbuf[0] == 0x1b) {
@@ -66,6 +70,8 @@ static int proc_char(int c)
                                clen = 0;
                                return 1;
                        }
+                       cbuf[clen++] = c;
+                       return 0;
                }
        }
 
@@ -85,8 +91,9 @@ static int proc_char(int c)
                break;
 
        case '\n':
-               if(cursor_y >= TERM_ROWS) {
+               if(cursor_y >= TERM_ROWS - 1) {
                        scroll();
+                       cursor_y = TERM_ROWS - 1;
                } else {
                        cursor_y++;
                }
index 1a32981..1758f54 100644 (file)
@@ -4,7 +4,7 @@
 #define TERM_COLS      80
 #define TERM_ROWS      24
 
-extern int cursor_x, cursor_y, cursor_vis;
+extern int cursor_x, cursor_y, cursor_vis, cursor_blink;
 extern unsigned char scrbuf[TERM_COLS * TERM_ROWS];
 
 void term_init(void);