#include #include #include #include #include int main() { fd_set rfds; int c, in, n, out, startx, y; struct timeval tv; WINDOW *w; w = initscr(); raw(); noecho(); timeout(1); if((in = open("/var/tmp/r.in", O_RDWR)) == -1) err(1, "/var/tmp/r.in"); if((out = open("/var/tmp/r.out", O_RDWR)) == -1) err(1, "/var/tmp/r.out"); tv.tv_sec = 0; tv.tv_usec = 1; FD_ZERO(&rfds); startx = 0; for(;;){ FD_SET(out, &rfds); if(select(out+1, &rfds, NULL, NULL, &tv) > 0){ read(out, &c, 1); printw("%c", c); startx = -1; } if((c = getch()) != ERR){ if(startx == -1) startx = getcurx(w); if(c == 26) /* ^Z */ break; if(c == 21){ /* ^U */ move: y = getcury(w); move(y, startx); continue; } if(c == '\n') goto move; else printw("%c", c); write(in, &c, 1); } } echo(); noraw(); endwin(); }