diff options
-rw-r--r-- | l.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -56,14 +56,14 @@ int cpr(int *x, int *y) { prn(CSI "6n"); /* get CSI */ - read(1, &c, 1); + read(ttyfd, &c, 1); if (c != '\033') return -1; - read(1, &c, 1); + read(ttyfd, &c, 1); if (c != '[') return -1; /* get x */ i = 0; - while (read(1, &c, 1) && c != ';') { + while (read(ttyfd, &c, 1) && c != ';') { if (i > 3 || !isdigit(c)) return -1; ybuf[i++] = c; } @@ -72,7 +72,7 @@ int cpr(int *x, int *y) { /* get y */ i = 0; - while (read(1, &c, 1) && c != 'R') { + while (read(ttyfd, &c, 1) && c != 'R') { if (i > 3 || !isdigit(c)) return -1; xbuf[i++] = c; } @@ -118,7 +118,10 @@ int main() { /* save original cursor position */ r = cpr(&x, &y); - if (r == -1) goto quit; + if (r == -1) { + fprintf(stderr, "could not retrieve cursor position"); + goto quit; + } /* print output */ for (i = 0; i < height; i++) @@ -161,16 +164,19 @@ int main() { if (c == 'D') left(); break; case 13: /* enter */ - goto quit; phrase = lines[current - 1]; - break; + goto quit; } } - quit: - //prn("%s%d;%dH", CSI, y, x); - //prn(CSI "J"); /* delete from cursor to end of display (ED) */ + prn("%s%d;%dH", CSI, y, x); + prn(CSI "J"); /* delete from cursor to end of display (ED) */ raw(false); if (phrase != NULL) printf("%s\n", phrase); + return 0; +die: + raw(false); + puts("died"); + return 0; } |