Anonymous committed 2d61da7

do all the line editing on stderr, so we can redirect output, which means that the cw part of pcw is really not needed if we just do 'srw tail -f > in'. the only problems with that are that tail -f updates periodically (use inotail?) and ii doesn't create |in automagically. if that's fixed then i can get rid of cw

Comments (0)

Files changed (1)

 #define ESC         0x1b
 #define DEL         0x7f
-#define cursor_clr()  printf("\033[J")
-#define cursor_beg()  printf("\033[1G")
-#define cursor_fwd(n) printf("\033[%dC", MAX(1, (n)))
-#define cursor_bak(n) printf("\033[%dD", MAX(1, (n)))
+#define cursor_clr()  fprintf(stderr, "\033[J")
+#define cursor_beg()  fprintf(stderr, "\033[1G")
+#define cursor_fwd(n) fprintf(stderr, "\033[%dC", MAX(1, (n)))
+#define cursor_bak(n) fprintf(stderr, "\033[%dD", MAX(1, (n)))
 char  buf[4096], usrbuf[4096];
 char  scrl_prompt_left[]  = "<";
-	fflush(stdout);
+	fflush(stderr);
 int start_pos(int start, int cur, int len, int cols)
 	int cols, left_prompt_len, right_prompt_len = 0;
 	struct winsize ws;
-	if (ioctl(1, TIOCGWINSZ, &ws) < 0)
+	if (ioctl(STDOUT, TIOCGWINSZ, &ws) < 0)
 		err(1, "failed ioctl");
 	cols = ws.ws_col - 1;
 	if (start > 0) {
 		left_prompt_len = strlen(scrl_prompt_left);
-		my_write(STDOUT, scrl_prompt_left, left_prompt_len);
+		my_write(STDERR, scrl_prompt_left, left_prompt_len);
 		cols = ws.ws_col - 1 - left_prompt_len;
 		start = start_pos(start, cur, len, cols);
 	} else {
-		my_write(STDOUT, nrml_prompt, left_prompt_len);
+		my_write(STDERR, nrml_prompt, left_prompt_len);
 	if (start + cols < len) {
 		start = start_pos(start, cur, len, cols);
-	my_write(STDOUT, usrbuf + start, MIN(cols, len));
+	my_write(STDERR, usrbuf + start, MIN(cols, len));
 	if (start + cols < len)
-		my_write(STDOUT, scrl_prompt_right, right_prompt_len);
+		my_write(STDERR, scrl_prompt_right, right_prompt_len);
 	cursor_fwd(left_prompt_len + cur - start);
-	fflush(stdout);
+	fflush(stderr);
 void shift_buf(char *buf, int ind, int len, int delta)