fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 422543b71e7b8a63e543030b9a7a736f0fa14975 parent 563792b5f00ec12931c561b21c92156f41c465de Author: Jul <jul@9o.is> Date: Mon, 23 Feb 2026 22:30:01 +0800 bolden matches and provide --no-color flag Diffstat:
| M | src/options.c | | | 8 | +++++++- |
| M | src/options.h | | | 1 | + |
| M | src/tty.c | | | 8 | ++++++++ |
| M | src/tty.h | | | 2 | ++ |
| M | src/tty_interface.c | | | 10 | +++++++--- |
5 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/options.c b/src/options.c @@ -21,6 +21,7 @@ static const char *usage_str = " -j, --workers NUM Use NUM workers for searching. (default is # of CPUs)\n" " -i, --show-info Show selection info line\n" " -m, --multi Enable multi-selection\n" + " -n, --no-color Do not use colored highlighting\n" " -h, --help Display this help and exit\n" " -v, --version Output version information and exit\n"; @@ -40,6 +41,7 @@ static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e' {"workers", required_argument, NULL, 'j'}, {"show-info", no_argument, NULL, 'i'}, {"multi", no_argument, NULL, 'm'}, + {"no-color", no_argument, NULL, 'n'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; @@ -56,13 +58,14 @@ void options_init(options_t *options) { options->input_delimiter = '\n'; options->show_info = DEFAULT_SHOW_INFO; options->multi = 0; + options->no_color = 0; } void options_parse(options_t *options, int argc, char *argv[]) { options_init(options); int c; - while ((c = getopt_long(argc, argv, "vhs0me:q:l:t:p:j:i", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "vhs0mne:q:l:t:p:j:i", longopts, NULL)) != -1) { switch (c) { case 'v': printf("%s " VERSION " © 2014-2025 John Hawthorn\n", argv[0]); @@ -119,6 +122,9 @@ void options_parse(options_t *options, int argc, char *argv[]) { case 'm': options->multi = 1; break; + case 'n': + options->no_color = 1; + break; case 'h': default: usage(argv[0]); diff --git a/src/options.h b/src/options.h @@ -17,6 +17,7 @@ typedef struct { char input_delimiter; int show_info; int multi; + int no_color; } options_t; void options_init(options_t *options); diff --git a/src/tty.c b/src/tty.c @@ -139,6 +139,14 @@ void tty_setfg(tty_t *tty, int fg) { } } +void tty_setbold(tty_t *tty) { + tty_sgr(tty, 1); +} + +void tty_unsetbold(tty_t *tty) { + tty_sgr(tty, 22); +} + void tty_setinvert(tty_t *tty) { tty_sgr(tty, 7); } diff --git a/src/tty.h b/src/tty.h @@ -26,6 +26,8 @@ char tty_getchar(tty_t *tty); int tty_input_ready(tty_t *tty, long int timeout, int return_on_signal); void tty_setfg(tty_t *tty, int fg); +void tty_setbold(tty_t *tty); +void tty_unsetbold(tty_t *tty); void tty_setinvert(tty_t *tty); void tty_setunderline(tty_t *tty); void tty_setnormal(tty_t *tty); diff --git a/src/tty_interface.c b/src/tty_interface.c @@ -64,10 +64,14 @@ static void draw_match(tty_interface_t *state, const char *choice, int selected) break; } if (positions[p] == i) { - tty_setfg(tty, TTY_COLOR_HIGHLIGHT); + tty_setbold(tty); + if (!options->no_color) + tty_setfg(tty, TTY_COLOR_HIGHLIGHT); p++; - } else { - tty_setfg(tty, TTY_COLOR_NORMAL); + } else if (p > 0 && positions[p-1] == i-1) { + tty_unsetbold(tty); + if (!options->no_color) + tty_setfg(tty, TTY_COLOR_NORMAL); } if (choice[i] == '\n') { tty_putc(tty, ' ');