From 757b31309434d7adcd1361be26c1cd2a44d6ec9b Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 9 Sep 2018 13:05:12 -0700 Subject: Disable line wrap when printing candidates This solves the line wrapping issue with much simpler code, which also works better with Unicode characters and when the terminal is resized. --- src/tty_interface.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/tty_interface.c b/src/tty_interface.c index a76cfa9..746da4d 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -42,15 +42,12 @@ static void draw_match(tty_interface_t *state, const char *choice, int selected) score_t score = match_positions(search, choice, &positions[0]); - size_t maxwidth = tty_getwidth(tty); - - if (options->show_scores && maxwidth >= 9) { + if (options->show_scores) { if (score == SCORE_MIN) { tty_printf(tty, "( ) "); } else { tty_printf(tty, "(%5.2f) ", score); } - maxwidth -= 8; } if (selected) @@ -60,20 +57,17 @@ static void draw_match(tty_interface_t *state, const char *choice, int selected) tty_setinvert(tty); #endif + tty_setnowrap(tty); for (size_t i = 0, p = 0; choice[i] != '\0'; i++) { - if (i + 1 < maxwidth) { - if (positions[p] == i) { - tty_setfg(tty, TTY_COLOR_HIGHLIGHT); - p++; - } else { - tty_setfg(tty, TTY_COLOR_NORMAL); - } - tty_printf(tty, "%c", choice[i]); + if (positions[p] == i) { + tty_setfg(tty, TTY_COLOR_HIGHLIGHT); + p++; } else { - tty_printf(tty, "$"); - break; + tty_setfg(tty, TTY_COLOR_NORMAL); } + tty_printf(tty, "%c", choice[i]); } + tty_setwrap(tty); tty_setnormal(tty); } -- cgit v1.2.3