Browse code

Use /dev/tty for output

John Hawthorn authored on 12/07/2014 04:18:40
Showing 1 changed files

... ...
@@ -66,7 +66,7 @@ void run_search(char *needle){
66 66
 }
67 67
 
68 68
 int ttyin;
69
-int ttyout;
69
+FILE *ttyout;
70 70
 struct termios original_termios;
71 71
 
72 72
 void reset_tty(){
... ...
@@ -75,7 +75,7 @@ void reset_tty(){
75 75
 
76 76
 void init_tty(){
77 77
 	ttyin = open("/dev/tty", O_RDONLY);
78
-	ttyout = open("/dev/tty", O_WRONLY);
78
+	ttyout = fopen("/dev/tty", "w");
79 79
 
80 80
 	tcgetattr(ttyin, &original_termios);
81 81
 
... ...
@@ -104,13 +104,13 @@ int search_size;
104 104
 char search[4096] = {0};
105 105
 
106 106
 void clear(){
107
-	fprintf(stdout, "%c%c0G", 0x1b, '[');
107
+	fprintf(ttyout, "%c%c0G", 0x1b, '[');
108 108
 	int line = 0;
109
-	while(line++ < 11 + 1){
110
-		fprintf(stdout, "%c%cK\n", 0x1b, '[');
109
+	while(line++ < 10 + 1){
110
+		fprintf(ttyout, "%c%cK\n", 0x1b, '[');
111 111
 	}
112
-	fprintf(stdout, "%c%c%iA", 0x1b, '[', line-1);
113
-	fprintf(stdout, "%c%c0G", 0x1b, '[');
112
+	fprintf(ttyout, "%c%c%iA", 0x1b, '[', line-1);
113
+	fprintf(ttyout, "%c%c0G", 0x1b, '[');
114 114
 }
115 115
 
116 116
 void draw(){
... ...
@@ -118,18 +118,17 @@ void draw(){
118 118
 	int i;
119 119
 	const char *prompt = "> ";
120 120
 	clear();
121
-	printf("%s%s\n", prompt, search);
121
+	fprintf(ttyout, "%s%s\n", prompt, search);
122 122
 	for(i = 0; line < 10 && i < choices_n; i++){
123 123
 		double rank = match(search, choices[i]);
124 124
 		if(rank > 0){
125
-			//fprintf(stdout, "%c%cK", 0x1b, '[');
126
-			printf("%s\n", choices[i]);
125
+			fprintf(ttyout, "%s\n", choices[i]);
127 126
 			line++;
128 127
 		}
129 128
 	}
130
-	fprintf(stdout, "%c%c%iA", 0x1b, '[', line + 1);
131
-	fprintf(stdout, "%c%c%iG", 0x1b, '[', strlen(prompt) + strlen(search) + 1);
132
-	fflush(stdout);
129
+	fprintf(ttyout, "%c%c%iA", 0x1b, '[', line + 1);
130
+	fprintf(ttyout, "%c%c%iG", 0x1b, '[', strlen(prompt) + strlen(search) + 1);
131
+	fflush(ttyout);
133 132
 }
134 133
 
135 134
 void run(){