summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/choices.c2
-rw-r--r--src/fzy.c11
-rw-r--r--src/tty.c4
-rw-r--r--src/tty.h1
-rw-r--r--src/tty_interface.c8
5 files changed, 22 insertions, 4 deletions
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) {
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/src/tty.c b/src/tty.c
index ed951b3..7271307 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -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;
diff --git a/src/tty.h b/src/tty.h
index 28c5cad..b949a46 100644
--- a/src/tty.h
+++ b/src/tty.h
@@ -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 */