fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 1817977e2163cebea0d140f45f551569c56e8518 parent c0cb51cd47f3a3ea0e03adf1ceac4fbda7b9acdf Author: John Hawthorn <john.hawthorn@gmail.com> Date: Sat, 30 Aug 2014 19:11:18 -0700 Use last line of terminal Diffstat:
| M | fzy.c | | | 11 | +++++------ |
| M | tty.c | | | 4 | ++++ |
| M | tty.h | | | 5 | +++++ |
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/fzy.c b/fzy.c @@ -95,7 +95,7 @@ char search[SEARCH_SIZE_MAX + 1] = {0}; void clear(tty_t *tty){ tty_setcol(tty, 0); int line = 0; - while(line++ < NUMLINES + 1){ + while(line++ < NUMLINES){ tty_newline(tty); } tty_moveup(tty, line-1); @@ -132,24 +132,23 @@ void draw(tty_t *tty){ if(current_selection + SCROLLOFF >= NUMLINES){ start = current_selection + SCROLLOFF - NUMLINES + 1; if(start + NUMLINES >= choices_available){ - start = choices_available - NUMLINES + 1; + start = choices_available - NUMLINES; } } const char *prompt = "> "; tty_setcol(tty, 0); tty_printf(tty, "%s%s", prompt, search); - tty_newline(tty); for(size_t i = start; i < start + NUMLINES; i++){ + tty_newline(tty); if(i < choices_available){ size_t choice_idx = choices_sorted[i]; if(flag_show_scores) tty_printf(tty, "(%5.2f) ", choices_score[choice_idx]); draw_match(tty, choices[choice_idx], i == current_selection); - }else{ - tty_newline(tty); } } - tty_moveup(tty, NUMLINES + 1); + tty_clearline(tty); + tty_moveup(tty, NUMLINES); tty_setcol(tty, strlen(prompt) + strlen(search)); tty_flush(tty); } diff --git a/tty.c b/tty.c @@ -64,6 +64,10 @@ void tty_newline(tty_t *tty){ tty_printf(tty, "%c%cK\n", 0x1b, '['); } +void tty_clearline(tty_t *tty){ + tty_printf(tty, "%c%cK", 0x1b, '['); +} + void tty_setcol(tty_t *tty, int col){ tty_printf(tty, "%c%c%iG", 0x1b, '[', col + 1); } diff --git a/tty.h b/tty.h @@ -34,6 +34,11 @@ void tty_setnormal(tty_t *tty); */ void tty_newline(tty_t *tty); +/* tty_clearline + * Clear to the end of the current line without advancing the cursor. + */ +void tty_clearline(tty_t *tty); + void tty_moveup(tty_t *tty, int i); void tty_setcol(tty_t *tty, int col);