summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2018-06-18 11:18:50 -0700
committerGitHub <noreply@github.com>2018-06-18 11:18:50 -0700
commit98edd5f5c0a8e9469ca46a6c327798babd07e6ab (patch)
tree3b253182f9583ed946786ca4dcde7175935f77eb
parent1b3306813c7afcb40cbe4da81e077151cae9ae91 (diff)
parent7ba0da7711b986b19945fecdb823c7b7239b87a7 (diff)
Merge pull request #85 from jhawthorn/fast_tty_init
Initialize tty before reading choices
-rw-r--r--src/fzy.c11
-rw-r--r--test/acceptance/acceptance_test.rb7
2 files changed, 17 insertions, 1 deletions
diff --git a/src/fzy.c b/src/fzy.c
index 461f022..6b9aa5a 100644
--- a/src/fzy.c
+++ b/src/fzy.c
@@ -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;
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