summaryrefslogtreecommitdiff
path: root/src/tty_interface.c
diff options
context:
space:
mode:
authormomotaro <momotaro.n@gmail.com>2016-12-21 04:18:05 +0900
committermomotaro <momotaro.n@gmail.com>2016-12-21 04:18:05 +0900
commit0341d2fa077a148aa5779bf4e00dccc943c96289 (patch)
tree342085b02a102ff0108eb0890569e682a17a22e2 /src/tty_interface.c
parentd88d197c76fc53c1ff604e00cb0f421f379e2910 (diff)
Fix a problem that the cursor position shifted upward
Diffstat (limited to 'src/tty_interface.c')
-rw-r--r--src/tty_interface.c9
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);
}