Skip to content
Myr

✨ 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

11 files+127 added−1 removed

modified:completions/fish/fuzzel.fish+1 added
34 unmodified lines
35complete -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)"36complete -c fuzzel -x -l x-margin -d "horizontal margin away from the anchor point in pixels (0)"37complete -c fuzzel -x -l y-margin -d "vertical margin away from the anchor point in pixels (0)"38complete -c fuzzel -x -l select -d "select the first entry that matches the given string"39complete -c fuzzel -l auto-select -d "automatically select when only one match remains"40complete -c fuzzel -x -l select-index -d "select the entry at index"41complete -c fuzzel -x -s l -l lines -d "maximum number of matches to displayh (15)"42complete -c fuzzel -l minimal-lines -d "adjust lines to minimum of --lines and input lines (dmenu mode only)"43complete -c fuzzel -x -s w -l width -d "window width, in characters (30)"
47 unmodified lines
modified:completions/zsh/_fuzzel+1 added
26 unmodified lines
27 '(-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 lines
modified:doc/fuzzel.1.scd+4 added-1 removed
228 unmodified lines
229*--select*=_STRING_230 Select the first entry that matches the given string (case231 insensitive).232233*--auto-select*234 Automatically select when only one match remains.235236*--select-index*=INDEX237 Select the entry with index, not compatible with --select.238239*-l*,*--lines*=COUNT
282 unmodified lines
522*--log-no-syslog*523 Disables syslog logging. Logging is only done on stderr.524525*--print-timing-info*523 Print timing information, to help debug performance issues.526 Print timing information to help debug performance issues.527528*-v*,*--version*529 Show the version number and quit530
58 unmodified lines
modified:doc/fuzzel.ini.5.scd+4 added
415 unmodified lines
416 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_.419420*auto-select*421 Boolean. When one entry is left, automatically select it.422 Default: _no_.423424# SECTION: colors425426All color values are in RGBA.427
277 unmodified lines
added:test/auto-select.fish+57 added
1#!/usr/bin/fish23set got45# 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 $got7function test_auto_select --argument-names input search8 rm -f out.txt910 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)15end1617# Test that auto-select works when only one match remains18test_auto_select "apple\nbanana\ncherry" app19@test "auto-select should execute when only one match remains" "$got" = "apple"2021# Test that auto-select works with partial matches22test_auto_select "application\napple\nbanana" applic23@test "auto-select should work with partial matches" "$got" = "application"2425# Test that auto-select doesn't trigger with multiple matches26function test_no_auto_select --argument-names input search27 rm -f out.txt2829 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)37end3839test_no_auto_select "apple\napricot\nbanana" ap40@test "auto-select should not trigger with multiple matches" "$got" = ""4142# Test without auto-select flag (should not auto-select)43function test_normal_mode --argument-names input search44 rm -f out.txt4546 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)54end5556test_normal_mode unique uniqu57@test "normal mode should not auto-select even with one match" "$got" = ""
modified:CHANGELOG.md+2 added
53 unmodified lines
54 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])5960[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/553
968 unmodified lines
modified:config.c+4 added
1032 unmodified lines
10331034 else if (strcmp(key, "cache") == 0)1035 return value_to_str(ctx, &conf->cache_path);10361037 else if (strcmp(key, "auto-select") == 0)1038 return value_to_bool(ctx, &conf->auto_select);10391040 else1041 LOG_CONTEXTUAL_ERR("not a valid option: %s", key);10421043 return false;
652 unmodified lines
1696 .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 };17031704 add_default_key_bindings(conf);
78 unmodified lines
modified:config.h+1 added
219 unmodified lines
220221 bool list_executables_in_path;222 char *cache_path;223224 bool auto_select;225 bool print_timing_info;226};227228typedef tll(char *) config_override_t;
7 unmodified lines
modified:main.c+10 added
369 unmodified lines
370 " --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 lines
839 #define OPT_PRINT_TIMINGS 301840 #define OPT_SCALING_FILTER 302841 #define OPT_MINIMAL_LINES 303842 #define OPT_HIDE_PROMPT 304843 #define OPT_AUTO_SELECT 305844845 static const struct option longopts[] = {846 {"config", required_argument, 0, OPT_CONFIG},847 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},
59 unmodified lines
907 {"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},912913 /* dmenu mode */914 {"dmenu", no_argument, 0, 'd'},915 {"dmenu0", no_argument, 0, OPT_DMENU_NULL},
909 unmodified lines
1825 cmdline_overrides.conf.print_timing_info = true;1826 cmdline_overrides.print_timing_info_set = true;1827 break;18281829 case OPT_AUTO_SELECT:1830 cmdline_overrides.conf.auto_select = true;1831 break;18321833 case 'v':1834 printf("fuzzel %s\n", version_and_features());1835 return EXIT_SUCCESS;1836
204 unmodified lines
2041 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;20472048 if (conf.dmenu.enabled) {2049 /* We don't have any meta data in dmenu mode */2050 conf.match_fields = MATCH_NAME;
213 unmodified lines
modified:match.c+1 added
1384 unmodified lines
13851386 return -1;1387}138813891390static void1391matches_update_internal(struct matches *matches, bool incremental)1392{1393 if (matches->applications == NULL)
272 unmodified lines
modified:wayland.c+42 added
569 unmodified lines
570 wl_display_roundtrip(wayl->display);571 xdg_activation_token_v1_destroy(token);572}573574static void execute_selected(struct seat *seat, bool as_is, int custom_success_exit_code);575576static bool577check_auto_select(struct seat *seat, bool refresh)578{579 struct wayland *wayl = seat->wayl;580581 /* 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}590591static void592execute_selected(struct seat *seat, bool as_is, int custom_success_exit_code)593{594 struct wayland *wayl = seat->wayl;
325 unmodified lines
920 execute_binding(seat, bind, &refresh))921 {922 if (refresh)923 wayl_refresh(wayl);924925 if (check_auto_select(seat, refresh))926 goto maybe_repeat;927928 goto maybe_repeat;929 }930 }931 }
7 unmodified lines
939 execute_binding(seat, bind, &refresh))940 {941 if (refresh)942 wayl_refresh(wayl);943944 if (check_auto_select(seat, refresh))945 goto maybe_repeat;946947 goto maybe_repeat;948 }949 }950
10 unmodified lines
961 execute_binding(seat, bind, &refresh))962 {963 if (refresh)964 wayl_refresh(wayl);965966 /* 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 }973974 goto maybe_repeat;975 }976 }977 }
26 unmodified lines
10041005 matches_update_incremental(wayl->matches);1006 wayl_refresh(wayl);10071008 /* 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 }10151016maybe_repeat:10171018 if (should_repeat)1019 repeat_start(&seat->kbd.repeat, key - 8);
2005 unmodified lines