| ... | ... |
@@ -118,9 +118,9 @@ void draw_match(tty_t *tty, const char *choice, int selected){
|
| 118 | 118 |
}else{
|
| 119 | 119 |
tty_setfg(tty, TTY_COLOR_NORMAL); |
| 120 | 120 |
} |
| 121 |
- fprintf(tty->fout, "%c", choice[i]); |
|
| 121 |
+ tty_printf(tty, "%c", choice[i]); |
|
| 122 | 122 |
} |
| 123 |
- fprintf(tty->fout, "\n"); |
|
| 123 |
+ tty_printf(tty, "\n"); |
|
| 124 | 124 |
tty_setnormal(tty); |
| 125 | 125 |
} |
| 126 | 126 |
|
| ... | ... |
@@ -132,7 +132,7 @@ void draw(tty_t *tty){
|
| 132 | 132 |
int line = 0; |
| 133 | 133 |
const char *prompt = "> "; |
| 134 | 134 |
clear(tty); |
| 135 |
- fprintf(tty->fout, "%s%s\n", prompt, search); |
|
| 135 |
+ tty_printf(tty, "%s%s\n", prompt, search); |
|
| 136 | 136 |
for(size_t i = start; line < NUMLINES && i < choices_available; i++){
|
| 137 | 137 |
draw_match(tty, choices[choices_sorted[i]], i == current_selection); |
| 138 | 138 |
line++; |
| ... | ... |
@@ -2,6 +2,7 @@ |
| 2 | 2 |
#include <unistd.h> |
| 3 | 3 |
#include <fcntl.h> |
| 4 | 4 |
#include <stdlib.h> |
| 5 |
+#include <stdarg.h> |
|
| 5 | 6 |
|
| 6 | 7 |
#include "tty.h" |
| 7 | 8 |
|
| ... | ... |
@@ -39,7 +40,7 @@ char tty_getchar(tty_t *tty){
|
| 39 | 40 |
} |
| 40 | 41 |
|
| 41 | 42 |
static void tty_sgr(tty_t *tty, int code){
|
| 42 |
- fprintf(tty->fout, "%c%c%im", 0x1b, '[', code); |
|
| 43 |
+ tty_printf(tty, "%c%c%im", 0x1b, '[', code); |
|
| 43 | 44 |
} |
| 44 | 45 |
|
| 45 | 46 |
void tty_setfg(tty_t *tty, int fg){
|
| ... | ... |
@@ -58,3 +59,10 @@ void tty_setnormal(tty_t *tty){
|
| 58 | 59 |
tty->fgcolor = 9; |
| 59 | 60 |
} |
| 60 | 61 |
|
| 62 |
+void tty_printf(tty_t *tty, const char *fmt, ...){
|
|
| 63 |
+ va_list args; |
|
| 64 |
+ va_start(args, fmt); |
|
| 65 |
+ vfprintf(tty->fout, fmt, args); |
|
| 66 |
+ va_end(args); |
|
| 67 |
+} |
|
| 68 |
+ |