diff options
-rw-r--r-- | rin.c | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -4,11 +4,13 @@ #include <unistd.h> #include <sys/select.h> +#define MAXBUF 1024 + int main() { fd_set rfds; - int c, in, n, out, startx, y; + int bufin[MAXBUF], bufout[MAXBUF], c, in, nin, nout, out, startx, y; struct timeval tv; WINDOW *w; @@ -23,16 +25,18 @@ main() err(1, "/var/tmp/r.out"); tv.tv_sec = 0; - tv.tv_usec = 1; + tv.tv_usec = 0; FD_ZERO(&rfds); startx = 0; + nin = 0; for(;;){ FD_SET(out, &rfds); if(select(out+1, &rfds, NULL, NULL, &tv) > 0){ - read(out, &c, 1); - printw("%c", c); + nout = read(out, bufout, MAXBUF); + bufout[nout+1] = 0; + printw("%s", bufout); startx = -1; } @@ -42,15 +46,20 @@ main() if(c == 26) /* ^Z */ break; if(c == 21){ /* ^U */ -move: y = getcury(w); +reset: bufin[0] = nin = 0; + y = getcury(w); move(y, startx); continue; } - if(c == '\n') - goto move; - else + + bufin[nin++] = c; + + if(c == '\n'){ + bufin[nin] = 0; + dprintf(in, "%s", bufin); + goto reset; + }else printw("%c", c); - write(in, &c, 1); } } |