fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

commit 9d1c8fb2f5547874cd9d2549b0c3a973ba402c0a
parent 114059e9549590d1b6633ebc503a4743ef735dcb
Author: John Hawthorn <john@hawthorn.email>
Date:   Sun,  9 Sep 2018 13:05:12 -0700

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.

Diffstat:
Msrc/tty_interface.c | 22++++++++--------------
Mtest/acceptance/acceptance_test.rb | 12++++++++++++
2 files changed, 20 insertions(+), 14 deletions(-)

diff --git 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); } diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb @@ -430,6 +430,18 @@ class FzyTest < Minitest::Test @tty.assert_cursor_position(y: 0, x: 8) end + def test_long_strings + ascii = "LongStringOfText" * 6 + unicode = "LongStringOfText" * 3 + + @tty = interactive_fzy(input: [ascii, unicode]) + @tty.assert_matches <<~TTY + > + LongStringOfTextLongStringOfTextLongStringOfTextLongStringOfTextLongStringOfText + LongStringOfTextLongStringOfTextLongStri + TTY + end + def test_help @tty = TTYtest.new_terminal(%{#{FZY_PATH} --help}) @tty.assert_matches <<TTY