Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,11 @@ size_t tty_getwidth(tty_t *tty) {
size_t tty_getheight(tty_t *tty) {
return tty->maxheight;
}

void tty_hide_cursor(tty_t *tty) {
fputs("\x1b[?25l", tty->fout);
}

void tty_unhide_cursor(tty_t *tty) {
fputs("\x1b[?25h", tty->fout);
}
3 changes: 3 additions & 0 deletions src/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void tty_flush(tty_t *tty);
size_t tty_getwidth(tty_t *tty);
size_t tty_getheight(tty_t *tty);

void tty_hide_cursor(tty_t *tty);
void tty_unhide_cursor(tty_t *tty);

#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 11 additions & 3 deletions src/tty_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void draw(tty_interface_t *state) {
}
}

tty_hide_cursor(tty);
tty_setcol(tty, 0);
tty_printf(tty, "%s%s", options->prompt, state->search);
tty_clearline(tty);
Expand All @@ -116,6 +117,8 @@ static void draw(tty_interface_t *state) {
fputs(options->prompt, tty->fout);
for (size_t i = 0; i < state->cursor; i++)
fputc(state->search[i], tty->fout);

tty_unhide_cursor(tty);
tty_flush(tty);
}

Expand Down Expand Up @@ -353,14 +356,16 @@ static void handle_input(tty_interface_t *state, const char *s, int handle_ambig

/* We could have a complete keybinding, or could be in the middle of one.
* We'll need to wait a few milliseconds to find out. */
if (found_keybinding != -1 && in_middle) {
/* if (found_keybinding != -1 && in_middle) {
state->ambiguous_key_pending = 1;
return;
}
} */

/* Wait for more if we are in the middle of a keybinding */
if (in_middle)
if (in_middle) {
state->ambiguous_key_pending = 1;
return;
}

/* No matching keybinding, add to search */
for (int i = 0; input[i]; i++)
Expand All @@ -384,6 +389,9 @@ int tty_interface_run(tty_interface_t *state) {
char s[2] = {tty_getchar(state->tty), '\0'};
handle_input(state, s, 0);

if (state->ambiguous_key_pending == 1)
continue;

if (state->exit >= 0)
return state->exit;

Expand Down