diff options
-rw-r--r-- | fzy.c | 6 | ||||
-rw-r--r-- | tty.c | 6 | ||||
-rw-r--r-- | tty.h | 2 |
3 files changed, 14 insertions, 0 deletions
@@ -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); } @@ -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; +} @@ -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 |