main: add --prompt-only
Before adoption: this commit came in with the history the project adopted, so no landing records it.
In dmenu mode, --prompt-only sets the prompt (like --prompt), but also ignores STDIN and sets --lines=0. In other words, it turns fuzzel into a one-line prompter, with no pre-existing choices. In application mode, it behaves exactly like --prompt. Closes #276
authored by Daniel Eklöf · committed by Daniel Eklöf · parent c6ae6c2 · Browse files · 4 files·+56 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+56 added−12 removed
- other:+56 added−12 removed
Provenance
- Commit
fd76db4- Tree
a08d217- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
c6ae6c2
4 files changed+56 added−12 removed
modified:doc/fuzzel.1.scd+8 added-2 removed
82 unmodified lines83 84 *-p*,*--prompt*=_PROMPT_85 Prompt to use. Default: _> _.86 87-*-i*88- Ignored; for compatibility with other, similar utilities (where87+*--prompt-only*=_PROMPT_88+ Same as *--prompt*, but in *--dmenu* mode it also:89+ - does not read anything from STDIN90+ - sets *--lines* to 091+ 92+ In non-dmenu mode it behaves exactly like *--prompt*.93+94+*-i* Ignored; for compatibility with other, similar utilities (where95 *-i* means "case insensitive search").96 97 *--icon-theme*=_NAME_98 Icon theme to use. Note that this option is case sensitive; the297 unmodified linesmodified:CHANGELOG.md+3 added
55 unmodified lines56 * Much improved performance with large amounts of input ([#305][305]).57 * Improved rendering performance, by using threads. See the new58 `--workers` command line option, and the new `workers` option in59 `fuzzel.ini`.60+* dmenu mode: `--prompt-only=PROMPT` command line option61+ ([#276][276]).62 63 [344]: https://codeberg.org/dnkl/fuzzel/issues/34464 [131]: https://codeberg.org/dnkl/fuzzel/issues/13165 [189]: https://codeberg.org/dnkl/fuzzel/issues/18966 [219]: https://codeberg.org/dnkl/fuzzel/issues/21967 [365]: https://codeberg.org/dnkl/fuzzel/issues/36568 [305]: https://codeberg.org/dnkl/fuzzel/issues/30569+[276]: https://codeberg.org/dnkl/fuzzel/issues/27670 71 72 ### Changed73 692 unmodified linesmodified:config.h+1 added
98 unmodified lines99 100 struct config {101 char *output;102 char32_t *prompt;103+ bool prompt_only;104 enum match_fields match_fields;105 106 struct {107 char32_t character;87 unmodified linesmodified:main.c+44 added-10 removed
309 unmodified lines310 {311 printf("Usage: %s [OPTION]...\n", prog_name);312 printf("\n");313 printf("Options:\n");314- printf(" --config=PATH load configuration from PATH (XDG_CONFIG_HOME/fuzzel/fuzzel.ini)\n"315- " --check-config verify configuration, exit with 0 if ok, otherwise exit with 1\n"316- " --cache=PATH load most recently launched applications from PATH (XDG_CACHE_HOME/fuzzel)\n"314+ printf(" --config=PATH load configuration from PATH\n"315+ " (XDG_CONFIG_HOME/fuzzel/fuzzel.ini)\n"316+ " --check-config verify configuration, exit with 0 if ok,\n"317+ " otherwise exit with 1\n"318+ " --cache=PATH load most recently launched applications from\n"319+ " PATH (XDG_CACHE_HOME/fuzzel)\n"320 " -o,--output=OUTPUT output (monitor) to display on (none)\n"321 " -f,--font=FONT font name and style, in FontConfig format\n"322 " (monospace)\n"323 " -D,--dpi-aware=no|yes|auto enable or disable DPI aware rendering (auto)\n"1 unmodified line325 " -I,--no-icons do not render any icons\n"326 " -F,--fields=FIELDS comma separated list of XDG Desktop entry\n"327 " fields to match\n"328 " -p,--prompt=PROMPT string to use as input prompt (\"> \")\n"329+ " --prompt-only=PROMPT same as --prompt, but in dmenu mode it does not\n"330+ " wait for STDIN, and implies --lines=0\n"331 " --password=[CHARACTER] render all input as CHARACTER ('*' by default)\n"332 " -T,--terminal terminal command to use when launching\n"333 " 'terminal' programs, e.g. \"xterm -e\".\n"334 " Not used in dmenu mode (not set)\n"335 " -a,--anchor window anchor (center)\n"336 " --x-margin=MARGIN horizontal margin, in pixels (0)\n"337 " --y-margin=MARGIN vertical margin, in pixels (0)\n"333- " --select=STRING select first entry that matches the given string\n"338+ " --select=STRING select first entry that matches the given\n"339+ " string\n"340 " -l,--lines number of matches to show\n"341 " -w,--width window width, in characters (margins and\n"342 " borders not included)\n"343 " --tabs=INT number of spaces a tab is expanded to (8)\n"7 unmodified lines351 " --input-color=HEX text color of the input string (657b83ff)\n"352 " -m,--match-color=HEX color of matched substring (cb4b16ff)\n"353 " -s,--selection-color=HEX background color of selected item (eee8d5dd)\n"354 " -S,--selection-text-color=HEX text color of selected item (657b83ff)\n"349- " -M,--selection-match-color=HEX color of matched substring in selection (cb4b16ff)\n"355+ " -M,--selection-match-color=HEX color of matched substring in selection\n"356+ " (cb4b16ff)\n"357 " -B,--border-width=INT width of border, in pixels (1)\n"358 " -r,--border-radius=INT amount of corner \"roundness\" (10)\n"359 " -C,--border-color=HEX border color (002b36ff)\n"360 " --show-actions include desktop actions in the list\n"3 unmodified lines364 " --fuzzy-max-length-discrepancy=VALUE maximum allowed length discrepancy\n"365 " between a fuzzy match and the search\n"366 " criteria. Larger values mean more\n"367 " fuzzy matches (2)\n"361- " --fuzzy-max-distance=VALUE maximum levenshtein distance between a fuzzy (1)\n"368+ " --fuzzy-max-distance=VALUE maximum levenshtein distance between a fuzzy\n"369 " match and the search criteria. Larger values\n"370 " mean more fuzzy matches\n"371 " --line-height=HEIGHT override line height from font metrics\n"372 " --letter-spacing=AMOUNT additional letter spacing\n"366- " --layer=top|overlay which layer to render the fuzzel window on (top)\n"373+ " --layer=top|overlay which layer to render the fuzzel window on\n"374+ " (top)\n"375 " --no-exit-on-keyboard-focus-loss do not exit when losing keyboard focus\n"376 " --launch-prefix=COMMAND prefix to add before argv of executed program\n"377+ " --list-executables-in-path include executables from PATH in the list\n"378 " --workers=N number of threads to use for rendering\n"379 " -d,--dmenu dmenu compatibility mode\n"380 " --dmenu0 like --dmenu, but input is NUL separated\n"381 " instead of newline separated\n"382 " --index print selected entry's index instead of of the \n"383 " entry's text (dmenu mode only)\n"375- " --list-executables-in-path include executables from PATH in the list\n"384 " -R,--no-run-if-empty exit immediately without showing UI if stdin\n"385 " is empty (dmenu mode only)\n"386 " --log-level={info|warning|error|none}\n"387 " log level (warning)\n"149 unmodified lines537 }538 }539 540 if (dmenu_enabled) {541+ if (!conf->prompt_only) {533- dmenu_load_entries(apps, dmenu_delim, ctx->dmenu_abort_fd);534- read_cache(cache_path, apps, true);542+ dmenu_load_entries(apps, dmenu_delim, ctx->dmenu_abort_fd);543+ read_cache(cache_path, apps, true);544+ }545 } else {546 xdg_find_programs(terminal, actions_enabled, filter_desktop, &desktops, apps);547 if (list_exec_in_path)548 path_find_programs(apps);108 unmodified lines657 #define OPT_CACHE 280658 #define OPT_WORKERS 281659 #define OPT_PROMPT_COLOR 282660 #define OPT_INPUT_COLOR 283661+ #define OPT_PROMPT_ONLY 284662 663 static const struct option longopts[] = {664 {"config", required_argument, 0, OPT_CONFIG},665 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},26 unmodified lines692 {"border-width", required_argument, 0, 'B'},693 {"border-radius", required_argument, 0, 'r'},694 {"border-color", required_argument, 0, 'C'},695 {"prompt", required_argument, 0, 'p'},696+ {"prompt-only", required_argument, 0, OPT_PROMPT_ONLY},697 {"terminal", required_argument, 0, 'T'},698 {"show-actions", no_argument, 0, OPT_SHOW_ACTIONS},699 {"filter-desktop", optional_argument, 0, OPT_FILTER_DESKTOP},700 {"match-mode", required_argument, 0, OPT_MATCH_MODE},71 unmodified lines772 bool dmenu_delim_set:1;773 bool layer_set:1;774 bool no_exit_on_keyboard_focus_loss_set:1;775 bool workers_set:1;776+ bool prompt_only_set:1;777 } cmdline_overrides = {{0}};778 779 setlocale(LC_CTYPE, "");780 setlocale(LC_MESSAGES, "");254 unmodified lines1035 }1036 1037 break;1038 1039+ case OPT_PROMPT_ONLY:1040+ free(cmdline_overrides.conf.prompt);1041+ cmdline_overrides.conf.prompt = ambstoc32(optarg);1042+1043+ if (cmdline_overrides.conf.prompt == NULL) {1044+ fprintf(stderr, "%s: invalid prompt\n", optarg);1045+ return EXIT_FAILURE;1046+ }1047+1048+ cmdline_overrides.prompt_only_set = true;1049+ cmdline_overrides.conf.prompt_only = true;1050+ break;1051+1052 case 'b': {1053 const char *clr_start = optarg;1054 if (clr_start[0] == '#')1055 clr_start++;388 unmodified lines1444 }1445 if (cmdline_overrides.conf.prompt != NULL) {1446 free(conf.prompt);1447 conf.prompt = cmdline_overrides.conf.prompt;1448+ if (cmdline_overrides.prompt_only_set)1449+ conf.prompt_only = cmdline_overrides.conf.prompt_only;1450 }1451 if (cmdline_overrides.conf.password_mode.enabled) {1452 conf.password_mode.enabled = true;1453 conf.password_mode.character =100 unmodified lines1554 1555 if (conf.dmenu.enabled) {1556 /* We don't have any meta data in dmenu mode */1557 conf.match_fields = MATCH_NAME;1558+1559+ if (conf.prompt_only) {1560+ conf.lines = 0;1561+ conf.dmenu.exit_immediately_if_empty = false;1562+ close(STDIN_FILENO); /* To catch reads */1563+ }1564 }1565 1566 _Static_assert((int)LOG_CLASS_ERROR == (int)FCFT_LOG_CLASS_ERROR,1567 "fcft log level enum offset");210 unmodified lines