fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

commit 547a68b8216cb39726772c480a51afa32188b72b
parent 0cda7af7bbfc245288df4d1a392aae8fc4b885d0
Author: John Hawthorn <john.hawthorn@gmail.com>
Date:   Sat, 16 Aug 2014 20:31:11 -0700

Refactor into tty_newline and tty_setcol

Diffstat:
Mfzy.c | 8++++----
Mtty.c | 8++++++++
Mtty.h | 8++++++++
3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/fzy.c b/fzy.c @@ -89,13 +89,13 @@ int search_size; char search[SEARCH_SIZE_MAX + 1] = {0}; void clear(tty_t *tty){ - fprintf(tty->fout, "%c%c0G", 0x1b, '['); + tty_setcol(tty, 0); int line = 0; while(line++ < NUMLINES + 1){ - fprintf(tty->fout, "%c%cK\n", 0x1b, '['); + tty_newline(tty); } fprintf(tty->fout, "%c%c%iA", 0x1b, '[', line-1); - fprintf(tty->fout, "%c%c0G", 0x1b, '['); + tty_setcol(tty, 0); } #define TTY_COLOR_HIGHLIGHT TTY_COLOR_YELLOW @@ -138,7 +138,7 @@ void draw(tty_t *tty){ line++; } fprintf(tty->fout, "%c%c%iA", 0x1b, '[', line + 1); - fprintf(tty->fout, "%c%c%ziG", 0x1b, '[', strlen(prompt) + strlen(search) + 1); + tty_setcol(tty, strlen(prompt) + strlen(search) + 1); fflush(tty->fout); } diff --git a/tty.c b/tty.c @@ -59,6 +59,14 @@ void tty_setnormal(tty_t *tty){ tty->fgcolor = 9; } +void tty_newline(tty_t *tty){ + tty_printf(tty, "%c%cK\n", 0x1b, '['); +} + +void tty_setcol(tty_t *tty, int col){ + tty_printf(tty, "%c%c%iG", 0x1b, '[', col); +} + void tty_printf(tty_t *tty, const char *fmt, ...){ va_list args; va_start(args, fmt); diff --git a/tty.h b/tty.h @@ -28,6 +28,14 @@ void tty_setnormal(tty_t *tty); #define TTY_COLOR_WHITE 7 #define TTY_COLOR_NORMAL 9 +/* tty_newline + * Move cursor to the beginning of the next line, clearing to the end of the + * current line + */ +void tty_newline(tty_t *tty); + +void tty_setcol(tty_t *tty, int col); + void tty_printf(tty_t *tty, const char *fmt, ...); #endif