✨ Add --auto-select opt. When one entry is left, automatically select it.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fixes #411
authored by Mark Stosberg · committed by Daniel Eklöf · parent 544c59a · Browse files · 11 files·+127 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+127 added−1 removed
- tests:+57 added−0 removed
- other:+70 added−1 removed
Provenance
- Commit
5751a65- Tree
7dacfcb- Author
Mark Stosberg <mark@stosberg.com>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
544c59a
11 files changed+127 added−1 removed
modified:completions/fish/fuzzel.fish+1 added
34 unmodified lines35 complete -c fuzzel -x -s a -l anchor -a "top-left top top-right left center right bottom-left bottom bottom-right" -d "set window anchor (center)"36 complete -c fuzzel -x -l x-margin -d "horizontal margin away from the anchor point in pixels (0)"37 complete -c fuzzel -x -l y-margin -d "vertical margin away from the anchor point in pixels (0)"38 complete -c fuzzel -x -l select -d "select the first entry that matches the given string"39+complete -c fuzzel -l auto-select -d "automatically select when only one match remains"40 complete -c fuzzel -x -l select-index -d "select the entry at index"41 complete -c fuzzel -x -s l -l lines -d "maximum number of matches to displayh (15)"42 complete -c fuzzel -l minimal-lines -d "adjust lines to minimum of --lines and input lines (dmenu mode only)"43 complete -c fuzzel -x -s w -l width -d "window width, in characters (30)"47 unmodified linesmodified:completions/zsh/_fuzzel+1 added
26 unmodified lines27 '(-a --anchor)'{-a,--anchor}'[set window anchor (center)]:anchors:(top-left top top-right left center right bottom-left bottom bottom-right)' \28 '--x-margin[horizontal margin away from the anchor point in pixels (0)]:()' \29 '--y-margin[vertical margin away from the anchor point in pixels (0)]:()' \30 '--select[select the first entry that matches the given string]:()' \31+ '--auto-select[automatically select when only one match remains]' \32 '--select-index[select the entry with index]:()' \33 '(-l --lines)'{-l,--lines}'[maximum number of matches to display (15)]:()' \34 '--minimal-lines[adjust lines to minimum of --lines and input lines (dmenu mode only)]' \35 '(-w --width)'{-w,--width}'[window width, in characters (30)]:()' \65 unmodified linesmodified:doc/fuzzel.1.scd+4 added-1 removed
228 unmodified lines229 *--select*=_STRING_230 Select the first entry that matches the given string (case231 insensitive).232 233+*--auto-select*234+ Automatically select when only one match remains.235+236 *--select-index*=INDEX237 Select the entry with index, not compatible with --select.238 239 *-l*,*--lines*=COUNT282 unmodified lines522 *--log-no-syslog*523 Disables syslog logging. Logging is only done on stderr.524 525 *--print-timing-info*523- Print timing information, to help debug performance issues.526+ Print timing information to help debug performance issues.527 528 *-v*,*--version*529 Show the version number and quit530 58 unmodified linesmodified:doc/fuzzel.ini.5.scd+4 added
415 unmodified lines416 Specify the default cache location. If unset,417 *$XDG_CACHE_HOME/fuzzel* will be used. Set to */dev/null* to418 disable caching. Default: _not set_.419 420+*auto-select*421+ Boolean. When one entry is left, automatically select it.422+ Default: _no_.423+424 # SECTION: colors425 426 All color values are in RGBA.427 277 unmodified linesadded:test/auto-select.fish+57 added
1+#!/usr/bin/fish2+3+set got4+5+# Given lines of input as $input and a search string as $search,6+# run Fuzzel with auto-select enabled and set the returned string in $got7+function test_auto_select --argument-names input search8+ rm -f out.txt9+10+ echo -e "$input" \11+ | ./build/fuzzel --dmenu --auto-select --search "$search" >out.txt &12+ # Wait for fuzzel to auto-select and exit13+ sleep .314+ set got (cat out.txt)15+end16+17+# Test that auto-select works when only one match remains18+test_auto_select "apple\nbanana\ncherry" app19+@test "auto-select should execute when only one match remains" "$got" = "apple"20+21+# Test that auto-select works with partial matches22+test_auto_select "application\napple\nbanana" applic23+@test "auto-select should work with partial matches" "$got" = "application"24+25+# Test that auto-select doesn't trigger with multiple matches26+function test_no_auto_select --argument-names input search27+ rm -f out.txt28+29+ echo -e "$input" \30+ | ./build/fuzzel --dmenu --auto-select --search "$search" >out.txt &31+ # Wait briefly to see if fuzzel auto-selects (it shouldn't)32+ sleep .133+ # Force exit with Escape34+ wtype -k Escape35+ sleep .136+ set got (cat out.txt)37+end38+39+test_no_auto_select "apple\napricot\nbanana" ap40+@test "auto-select should not trigger with multiple matches" "$got" = ""41+42+# Test without auto-select flag (should not auto-select)43+function test_normal_mode --argument-names input search44+ rm -f out.txt45+46+ echo -e "$input" \47+ | ./build/fuzzel --dmenu --search "$search" >out.txt &48+ # Wait briefly 49+ sleep .150+ # Force exit with Escape since it won't auto-select51+ wtype -k Escape52+ sleep .153+ set got (cat out.txt)54+end55+56+test_normal_mode unique uniqu57+@test "normal mode should not auto-select even with one match" "$got" = ""modified:CHANGELOG.md+2 added
53 unmodified lines54 for setting the title or app_id. ([#600][600])55 * `--hide-prompt` command line option to hide the prompt line, reducing56 window size while still accepting input. This cannot be used57 simultaneously with `--prompt-only`.i ([#597][597])58+* `--auto-select` option. When one entry is left, automatically select it. ([#411][411])59 60+[411]: https://codeberg.org/dnkl/fuzzel/issues/41161 [504]: https://codeberg.org/dnkl/fuzzel/pulls/50462 [512]: https://codeberg.org/dnkl/fuzzel/pulls/51263 [546]: https://codeberg.org/dnkl/fuzzel/issues/54664 [553]: https://codeberg.org/dnkl/fuzzel/issues/553968 unmodified linesmodified:config.c+4 added
1032 unmodified lines1033 1034 else if (strcmp(key, "cache") == 0)1035 return value_to_str(ctx, &conf->cache_path);1036 1037+ else if (strcmp(key, "auto-select") == 0)1038+ return value_to_bool(ctx, &conf->auto_select);1039+1040 else1041 LOG_CONTEXTUAL_ERR("not a valid option: %s", key);1042 1043 return false;652 unmodified lines1696 .keyboard_focus = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE,1697 .exit_on_kb_focus_loss = true,1698 .list_executables_in_path = false,1699 .cache_path = NULL,1700+ .auto_select = false,1701 .print_timing_info = false,1702 };1703 1704 add_default_key_bindings(conf);78 unmodified linesmodified:config.h+1 added
219 unmodified lines220 221 bool list_executables_in_path;222 char *cache_path;223 224+ bool auto_select;225 bool print_timing_info;226 };227 228 typedef tll(char *) config_override_t;7 unmodified linesmodified:main.c+10 added
369 unmodified lines370 " --x-margin=MARGIN horizontal margin, in pixels (0)\n"371 " --y-margin=MARGIN vertical margin, in pixels (0)\n"372 " --select=STRING select first entry that matches the given\n"373 " string\n"374+ " --auto-select automatically select when only one match\n"375+ " remains\n"376 " --select-index=INDEX select the entry with index, not compatible with --select\n"377 " -l,--lines number of matches to show\n"378 " --minimal-lines adjust the number of lines to the\n"379 " minimum of --lines and the number\n"459 unmodified lines839 #define OPT_PRINT_TIMINGS 301840 #define OPT_SCALING_FILTER 302841 #define OPT_MINIMAL_LINES 303842 #define OPT_HIDE_PROMPT 304843+ #define OPT_AUTO_SELECT 305844 845 static const struct option longopts[] = {846 {"config", required_argument, 0, OPT_CONFIG},847 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},59 unmodified lines907 {"counter", no_argument, 0, OPT_COUNTER},908 {"delayed-filter-ms", required_argument, 0, OPT_DELAYED_FILTER_MS},909 {"delayed-filter-limit", required_argument, 0, OPT_DELAYED_FILTER_LIMIT},910 {"scaling-filter", required_argument, 0, OPT_SCALING_FILTER},911+ {"auto-select", no_argument, 0, OPT_AUTO_SELECT},912 913 /* dmenu mode */914 {"dmenu", no_argument, 0, 'd'},915 {"dmenu0", no_argument, 0, OPT_DMENU_NULL},909 unmodified lines1825 cmdline_overrides.conf.print_timing_info = true;1826 cmdline_overrides.print_timing_info_set = true;1827 break;1828 1829+ case OPT_AUTO_SELECT:1830+ cmdline_overrides.conf.auto_select = true;1831+ break;1832+1833 case 'v':1834 printf("fuzzel %s\n", version_and_features());1835 return EXIT_SUCCESS;1836 204 unmodified lines2041 if (cmdline_overrides.print_timing_info_set)2042 conf.print_timing_info = cmdline_overrides.conf.print_timing_info;2043 if (cmdline_overrides.scaling_filter_set)2044 conf.png_scaling_filter = cmdline_overrides.conf.png_scaling_filter;2045+ if (cmdline_overrides.conf.auto_select)2046+ conf.auto_select = cmdline_overrides.conf.auto_select;2047 2048 if (conf.dmenu.enabled) {2049 /* We don't have any meta data in dmenu mode */2050 conf.match_fields = MATCH_NAME;213 unmodified linesmodified:match.c+1 added
1384 unmodified lines1385 1386 return -1;1387 }1388 1389+1390 static void1391 matches_update_internal(struct matches *matches, bool incremental)1392 {1393 if (matches->applications == NULL)272 unmodified linesmodified:wayland.c+42 added
569 unmodified lines570 wl_display_roundtrip(wayl->display);571 xdg_activation_token_v1_destroy(token);572 }573 574+static void execute_selected(struct seat *seat, bool as_is, int custom_success_exit_code);575+576+static bool577+check_auto_select(struct seat *seat, bool refresh)578+{579+ struct wayland *wayl = seat->wayl;580+581+ /* Check for auto-select after key binding execution */582+ if (refresh && wayl->conf->auto_select) {583+ if (matches_get_total_count(wayl->matches) == 1) {584+ execute_selected(seat, false, -1);585+ return true;586+ }587+ }588+ return false;589+}590+591 static void592 execute_selected(struct seat *seat, bool as_is, int custom_success_exit_code)593 {594 struct wayland *wayl = seat->wayl;325 unmodified lines920 execute_binding(seat, bind, &refresh))921 {922 if (refresh)923 wayl_refresh(wayl);924+925+ if (check_auto_select(seat, refresh))926+ goto maybe_repeat;927+928 goto maybe_repeat;929 }930 }931 }7 unmodified lines939 execute_binding(seat, bind, &refresh))940 {941 if (refresh)942 wayl_refresh(wayl);943+944+ if (check_auto_select(seat, refresh))945+ goto maybe_repeat;946+947 goto maybe_repeat;948 }949 }950 10 unmodified lines961 execute_binding(seat, bind, &refresh))962 {963 if (refresh)964 wayl_refresh(wayl);965+966+ /* Check for auto-select after key binding execution */967+ if (refresh && wayl->conf->auto_select) {968+ if (matches_get_total_count(wayl->matches) == 1) {969+ execute_selected(seat, false, -1);970+ goto maybe_repeat;971+ }972+ }973+974 goto maybe_repeat;975 }976 }977 }26 unmodified lines1004 1005 matches_update_incremental(wayl->matches);1006 wayl_refresh(wayl);1007 1008+ /* Check for auto-select after character insertion */1009+ if (wayl->conf->auto_select) {1010+ if (matches_get_total_count(wayl->matches) == 1) {1011+ execute_selected(seat, false, -1);1012+ return;1013+ }1014+ }1015+1016 maybe_repeat:1017 1018 if (should_repeat)1019 repeat_start(&seat->kbd.repeat, key - 8);2005 unmodified lines