diff options
author | John Ankarström <john@ankarstrom.se> | 2020-11-06 23:30:07 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-11-06 23:30:07 +0100 |
commit | 545fcfb1ee7b4004707da7183399ad822365c7a8 (patch) | |
tree | e96790cc990809f911af705a3b32e9592032a5c9 | |
parent | 9e1088749bee6c101143a17ca853b01c8163ac91 (diff) | |
download | lst-545fcfb1ee7b4004707da7183399ad822365c7a8.tar.gz |
make it work with pipes
-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; } |