iomenu

interactive text selection menu
Log | Files | Refs | README | LICENSE

commit 70864688887921021de8ce2b803fdd4206214cda
parent 62853eb76762d6adfac4bd5cbcc410e96ebc955f
Author: Josuah Demangeonā  ā µ <mail@josuah.net>
Date:   Sun, 19 Mar 2017 13:53:45 +0100

Fixed horizontal scrolling

Diffstat:
Miomenu.c | 29+++++------------------------
1 file changed, 5 insertions(+), 24 deletions(-)

diff --git a/iomenu.c b/iomenu.c @@ -137,11 +137,10 @@ print_lines(int count) static int prev_page(int pos, int cols) { - pos--; + pos -= pos > 0 ? 1 : 0; for (int col = 0; pos > 0; pos--) if ((col += strlen(matchv[pos]) + 2) > cols) return pos + 1; - return pos; } @@ -151,8 +150,7 @@ next_page(int pos, int cols) { for (int col = 0; pos < matchc; pos++) if ((col += strlen(matchv[pos]) + 2) > cols) - return pos - 1; - + return pos; return pos; } @@ -162,13 +160,11 @@ print_columns(void) { if (current < offset) { next = offset; - offset = prev; - prev = prev_page(offset, winsize.ws_col - 30 - 1); + offset = prev_page(offset, winsize.ws_col - 30 - 4); } else if (current >= next) { - prev = offset; offset = next; - next = next_page(offset, winsize.ws_col - 30 - 1); + next = next_page(offset, winsize.ws_col - 30 - 4); } fputs(offset > 0 ? "< " : " ", stderr); @@ -182,19 +178,6 @@ print_columns(void) static void -print_prompt(void) -{ - int limit = opt_lines ? winsize.ws_col : 30 - 2; - - fputc('\r', stderr); - for (int i = 0; i < limit; i++) - fputc(' ', stderr); - - fprintf(stderr, "\r%s %s", opt_prompt, input); -} - - -static void print_screen(int tty_fd) { int count; @@ -215,7 +198,7 @@ print_screen(int tty_fd) print_columns(); } - print_prompt(); + fprintf(stderr, "\r%s %s", opt_prompt, input); } @@ -256,8 +239,6 @@ filter_lines(void) matchv[matchc++] = linev[i]; free(tokv); - - next = next_page(0, winsize.ws_col - 30 - 1); }