fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 422519b314fa7e806a00f9e9595ae3ef5c8ffbad parent 2100ed06b19189a928d250cecf273d310388411c Author: John Hawthorn <john.hawthorn@gmail.com> Date: Tue, 16 Sep 2014 19:13:41 -0700 Cap max lines at terminal height Diffstat:
| M | fzy.c | | | 6 | ++++++ |
| M | tty.c | | | 6 | ++++++ |
| M | tty.h | | | 2 | ++ |
3 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/fzy.c b/fzy.c @@ -246,6 +246,9 @@ int main(int argc, char *argv[]){ choices_init(&choices); read_choices(&choices); + if(num_lines > choices.size) + num_lines = choices.size; + if(benchmark){ if(!initial_query){ fprintf(stderr, "Must specify -e/--show-matches with --benchmark\n"); @@ -265,6 +268,9 @@ int main(int argc, char *argv[]){ tty_t tty; tty_init(&tty, tty_filename); + if(num_lines + 1 > tty_getheight(&tty)) + num_lines = tty_getheight(&tty) - 1; + run(&tty, &choices); } diff --git a/tty.c b/tty.c @@ -43,8 +43,10 @@ void tty_getwinsz(tty_t *tty){ struct winsize ws; if(ioctl(fileno(tty->fout), TIOCGWINSZ, &ws) == -1){ tty->maxwidth = 80; + tty->maxheight = 25; }else{ tty->maxwidth = ws.ws_col; + tty->maxheight = ws.ws_row; } } @@ -112,3 +114,7 @@ void tty_flush(tty_t *tty){ size_t tty_getwidth(tty_t *tty){ return tty->maxwidth; } + +size_t tty_getheight(tty_t *tty){ + return tty->maxheight; +} diff --git a/tty.h b/tty.h @@ -9,6 +9,7 @@ typedef struct{ struct termios original_termios; int fgcolor; size_t maxwidth; + size_t maxheight; } tty_t; void tty_reset(tty_t *tty); @@ -48,5 +49,6 @@ void tty_printf(tty_t *tty, const char *fmt, ...); void tty_flush(tty_t *tty); size_t tty_getwidth(tty_t *tty); +size_t tty_getheight(tty_t *tty); #endif