diff options
author | momotaro <momotaro.n@gmail.com> | 2016-12-21 04:18:05 +0900 |
---|---|---|
committer | momotaro <momotaro.n@gmail.com> | 2016-12-21 04:18:05 +0900 |
commit | 0341d2fa077a148aa5779bf4e00dccc943c96289 (patch) | |
tree | 342085b02a102ff0108eb0890569e682a17a22e2 /src/tty_interface.c | |
parent | d88d197c76fc53c1ff604e00cb0f421f379e2910 (diff) |
Fix a problem that the cursor position shifted upward
Diffstat (limited to 'src/tty_interface.c')
-rw-r--r-- | src/tty_interface.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/tty_interface.c b/src/tty_interface.c index 875f6c3..0385719 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -72,8 +72,9 @@ static void draw(tty_interface_t *state) { size_t current_selection = choices->selection; if (current_selection + options->scrolloff >= num_lines) { start = current_selection + options->scrolloff - num_lines + 1; - if (start + num_lines >= choices_available(choices)) { - start = choices_available(choices) - num_lines; + size_t available = choices_available(choices); + if (start + num_lines >= available && available > 0) { + start = available - num_lines; } } tty_setcol(tty, 0); @@ -87,7 +88,9 @@ static void draw(tty_interface_t *state) { draw_match(state, choice, i == choices->selection); } } - tty_moveup(tty, num_lines); + if (num_lines > 0) { + tty_moveup(tty, num_lines); + } tty_setcol(tty, strlen(options->prompt) + strlen(state->search)); tty_flush(tty); } |