diff options
-rw-r--r-- | README.md | 38 | ||||
-rw-r--r-- | src/choices.c | 2 | ||||
-rw-r--r-- | src/fzy.c | 11 | ||||
-rw-r--r-- | src/tty.c | 4 | ||||
-rw-r--r-- | src/tty.h | 1 | ||||
-rw-r--r-- | src/tty_interface.c | 8 | ||||
-rw-r--r-- | test/acceptance/acceptance_test.rb | 7 |
7 files changed, 50 insertions, 21 deletions
@@ -3,7 +3,7 @@ **fzy** is a fast, simple fuzzy text selector for the terminal with an advanced [scoring algorithm](#sorting). -![](http://i.hawth.ca/u/fzy2.gif) +![](http://i.hawth.ca/u/fzy_animated_demo.svg) <blockquote> It's been kind of life-changing. @@ -41,30 +41,19 @@ Rather than clearing the screen, fzy displays its interface directly below the c The `PREFIX` environment variable can be used to specify the install location, the default is `/usr/local`. -### MacOS - -Using Homebrew - - brew install fzy - -Using MacPorts - - sudo port install fzy +### Arch Linux/MSYS2 -### Ubuntu/Debian 64-bit +fzy is available in the `community` repo. - wget https://github.com/jhawthorn/fzy/releases/download/0.9/fzy_0.9-1_amd64.deb - sudo dpkg -i fzy_0.9-1_amd64.deb + sudo pacman -S fzy ### Fedora/Redhat/CentOS sudo yum install https://github.com/jhawthorn/fzy/releases/download/0.9/fzy-0.9-1.x86_64.rpm -### Arch Linux/MSYS2 - -fzy is available in the `community` repo. +### FreeBSD - sudo pacman -S fzy + pkg install fzy ### Gentoo Linux @@ -72,6 +61,21 @@ fzy is available in the main repo. emerge -av app-shells/fzy +### macOS + +Using Homebrew + + brew install fzy + +Using MacPorts + + sudo port install fzy + +### Ubuntu/Debian 64-bit + + wget https://github.com/jhawthorn/fzy/releases/download/0.9/fzy_0.9-1_amd64.deb + sudo dpkg -i fzy_0.9-1_amd64.deb + ### pkgsrc (NetBSD and others) sudo pkgin install fzy diff --git a/src/choices.c b/src/choices.c index 64f9a8b..a8c24b6 100644 --- a/src/choices.c +++ b/src/choices.c @@ -21,7 +21,7 @@ static int cmpchoice(const void *_idx1, const void *_idx2) { if (a->score == b->score) { /* To ensure a stable sort, we must also sort by the string - * pointers. We can do this since we know all the stings are + * pointers. We can do this since we know all the strings are * from a contiguous memory segment (buffer in choices_t). */ if (a->str < b->str) { @@ -3,6 +3,7 @@ #include <stdlib.h> #include <ctype.h> #include <limits.h> +#include <unistd.h> #include "match.h" #include "tty.h" @@ -20,16 +21,17 @@ int main(int argc, char *argv[]) { choices_t choices; choices_init(&choices, &options); - choices_fread(&choices, stdin); if (options.benchmark) { if (!options.filter) { fprintf(stderr, "Must specify -e/--show-matches with --benchmark\n"); exit(EXIT_FAILURE); } + choices_fread(&choices, stdin); for (int i = 0; i < options.benchmark; i++) choices_search(&choices, options.filter); } else if (options.filter) { + choices_fread(&choices, stdin); choices_search(&choices, options.filter); for (size_t i = 0; i < choices_available(&choices); i++) { if (options.show_scores) @@ -38,9 +40,16 @@ int main(int argc, char *argv[]) { } } else { /* interactive */ + + if (isatty(STDIN_FILENO)) + choices_fread(&choices, stdin); + tty_t tty; tty_init(&tty, options.tty_filename); + if (!isatty(STDIN_FILENO)) + choices_fread(&choices, stdin); + if (options.num_lines > choices.size) options.num_lines = choices.size; @@ -110,6 +110,10 @@ void tty_setinvert(tty_t *tty) { tty_sgr(tty, 7); } +void tty_setunderline(tty_t *tty) { + tty_sgr(tty, 4); +} + void tty_setnormal(tty_t *tty) { tty_sgr(tty, 0); tty->fgcolor = 9; @@ -21,6 +21,7 @@ int tty_input_ready(tty_t *tty); void tty_setfg(tty_t *tty, int fg); void tty_setinvert(tty_t *tty); +void tty_setunderline(tty_t *tty); void tty_setnormal(tty_t *tty); #define TTY_COLOR_BLACK 0 diff --git a/src/tty_interface.c b/src/tty_interface.c index 35f2919..a76cfa9 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -54,7 +54,11 @@ static void draw_match(tty_interface_t *state, const char *choice, int selected) } if (selected) +#ifdef TTY_SELECTION_UNDERLINE + tty_setunderline(tty); +#else tty_setinvert(tty); +#endif for (size_t i = 0, p = 0; choice[i] != '\0'; i++) { if (i + 1 < maxwidth) { @@ -291,8 +295,8 @@ static const keybinding_t keybindings[] = {{"\x7f", action_del_char}, /* DEL */ {KEY_CTRL('M'), action_emit}, /* CR */ {KEY_CTRL('P'), action_prev}, /* C-P */ {KEY_CTRL('N'), action_next}, /* C-N */ - {KEY_CTRL('K'), action_prev}, /* C-J */ - {KEY_CTRL('J'), action_next}, /* C-K */ + {KEY_CTRL('K'), action_prev}, /* C-K */ + {KEY_CTRL('J'), action_next}, /* C-J */ {KEY_CTRL('A'), action_beginning}, /* C-A */ {KEY_CTRL('E'), action_end}, /* C-E */ diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb index 4a11cac..cac4c26 100644 --- a/test/acceptance/acceptance_test.rb +++ b/test/acceptance/acceptance_test.rb @@ -320,6 +320,13 @@ class FzyTest < Minitest::Test @tty.assert_matches "> foo\nfoo" end + # https://github.com/jhawthorn/fzy/issues/81 + def test_slow_stdin_fast_user + @tty = TTYtest.new_terminal(%{(echo aa; echo bc; echo bd; sleep 0.5) | #{FZY_PATH}}) + @tty.send_keys("b\r") + @tty.assert_matches "bc" + end + def test_help @tty = TTYtest.new_terminal(%{#{FZY_PATH} --help}) @tty.assert_matches <<TTY |