summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fzy.c6
-rw-r--r--tty.c6
-rw-r--r--tty.h2
3 files changed, 14 insertions, 0 deletions
diff --git a/fzy.c b/fzy.c
index 86c4de7..c97829d 100644
--- 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
index cbf0a85..63ea698 100644
--- 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
index 0586977..1f3a4f7 100644
--- 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