summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-06 23:30:07 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-06 23:30:07 +0100
commit545fcfb1ee7b4004707da7183399ad822365c7a8 (patch)
treee96790cc990809f911af705a3b32e9592032a5c9
parent9e1088749bee6c101143a17ca853b01c8163ac91 (diff)
downloadlst-545fcfb1ee7b4004707da7183399ad822365c7a8.tar.gz
make it work with pipes
-rw-r--r--l.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/l.c b/l.c
index 2bcbfd9..46fac3e 100644
--- a/l.c
+++ b/l.c
@@ -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;
}