fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 0cda7af7bbfc245288df4d1a392aae8fc4b885d0 parent ae418ccd6d225d868373799c8aee093811a5ba6d Author: John Hawthorn <john.hawthorn@gmail.com> Date: Sat, 16 Aug 2014 20:20:09 -0700 Refactor into tty_printf Diffstat:
| M | fzy.c | | | 6 | +++--- |
| M | tty.c | | | 10 | +++++++++- |
| M | tty.h | | | 2 | ++ |
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/fzy.c b/fzy.c @@ -118,9 +118,9 @@ void draw_match(tty_t *tty, const char *choice, int selected){ }else{ tty_setfg(tty, TTY_COLOR_NORMAL); } - fprintf(tty->fout, "%c", choice[i]); + tty_printf(tty, "%c", choice[i]); } - fprintf(tty->fout, "\n"); + tty_printf(tty, "\n"); tty_setnormal(tty); } @@ -132,7 +132,7 @@ void draw(tty_t *tty){ int line = 0; const char *prompt = "> "; clear(tty); - fprintf(tty->fout, "%s%s\n", prompt, search); + tty_printf(tty, "%s%s\n", prompt, search); for(size_t i = start; line < NUMLINES && i < choices_available; i++){ draw_match(tty, choices[choices_sorted[i]], i == current_selection); line++; diff --git a/tty.c b/tty.c @@ -2,6 +2,7 @@ #include <unistd.h> #include <fcntl.h> #include <stdlib.h> +#include <stdarg.h> #include "tty.h" @@ -39,7 +40,7 @@ char tty_getchar(tty_t *tty){ } static void tty_sgr(tty_t *tty, int code){ - fprintf(tty->fout, "%c%c%im", 0x1b, '[', code); + tty_printf(tty, "%c%c%im", 0x1b, '[', code); } void tty_setfg(tty_t *tty, int fg){ @@ -58,3 +59,10 @@ void tty_setnormal(tty_t *tty){ tty->fgcolor = 9; } +void tty_printf(tty_t *tty, const char *fmt, ...){ + va_list args; + va_start(args, fmt); + vfprintf(tty->fout, fmt, args); + va_end(args); +} + diff --git a/tty.h b/tty.h @@ -28,4 +28,6 @@ void tty_setnormal(tty_t *tty); #define TTY_COLOR_WHITE 7 #define TTY_COLOR_NORMAL 9 +void tty_printf(tty_t *tty, const char *fmt, ...); + #endif