config: --nth-delimiter=CHR
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add support for a custom field/column delimiter. Only single ASCII characters are supported (and not e.g. strings). Tab is still the default.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 4929e73 · Browse files · 11 files·+75 added−36 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+75 added−36 removed
- other:+75 added−36 removed
Provenance
- Commit
2dd56d8- Tree
a42ed18- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
4929e73
11 files changed+75 added−36 removed
modified:completions/fish/fuzzel.fish+3 added-2 removed
78 unmodified lines79 complete -c fuzzel -x -l scaling-filter -a "none nearest bilinear box linear cubic lanczos2 lanczos3 lanczos3-stretched" -d "filter to use when down scaling PNGs"80 complete -c fuzzel -s d -l dmenu -d "dmenu compatibility mode; entries are read from stdin, newline separated"81 complete -c fuzzel -l dmenu0 -d "dmenu compatibility mode; entries are read from stdin, NUL separated"82 complete -c fuzzel -l index -d "print selected entry's index instead of its text (dmenu mode only)"83-complete -c fuzzel -x -l with-nth -d "display the N:th column (tab separated) of each input line (dmenu only)"84-complete -c fuzzel -x -l accept-nth -d "output the N:th column (tab separated) of each input line (dmenu only)"83+complete -c fuzzel -x -l with-nth -d "display the N:th column (tab separated by default) of each input line (dmenu only)"84+complete -c fuzzel -x -l accept-nth -d "output the N:th column (tab separated by default) of each input line (dmenu only)"85+complete -c fuzzel -x -l nth-delimiter -d "field delimiter for --with-nth and --accept-nth"86 complete -c fuzzel -s R -l no-run-if-empty -d "exit immediately without showing the UI if stdin is empty (dmenu mode only)"87 complete -c fuzzel -x -s d -l log-level -a "info warning error none" -d "log-level (warning)"88 complete -c fuzzel -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"89 complete -c fuzzel -s S -l log-no-syslog -d "disable syslog logging"4 unmodified linesmodified:completions/zsh/_fuzzel+3 added-2 removed
69 unmodified lines70 '--delayed-filter-limit[switch to delayed refiltering when there are more matches than this]:delayed-filter-limit:()' \71 '(-d --dmenu)'{-d,--dmenu}'[dmenu compatibility mode; entries are read from stdin, newline separated]' \72 '--dmenu0[dmenu compatibility mode; entries are read from stdin, NUL separated]' \73 '--index[print selected entry'\''s index instead of its text (dmenu mode only)]' \74- '--with-nth[display the N:th column (tab separated) of each input line (dmenu mode only)]:with-nth:()' \75- '--accept-nth[output the N:th column (tab separated) of each input line (dmenu mode only)]:with-nth:()' \74+ '--with-nth[display the N:th column (tab separated by default) of each input line (dmenu mode only)]:with-nth:()' \75+ '--accept-nth[output the N:th column (tab separated by default) of each input line (dmenu mode only)]:with-nth:()' \76+ '--nth-delimiter[field delimiter for --with-nth and --accept-nth]:nth-delim:()' \77 '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]' \78 '--log-level[log level (warning)]:loglevel:(info warning error none)' \79 '--log-colorize[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \80 '--log-no-syslog[disable syslog logging]' \23 unmodified linesmodified:doc/fuzzel.1.scd+11 added-5 removed
482 unmodified lines483 Index values start with zero for the first entry.484 dmenu mode only.485 486 *--with-nth*=_N_|_FMT_487- Display the N:th column (tab separated) of each input line. When488- selected, the full input line is printed on stdout. dmenu mode489- only.487+ Display the N:th column (tab separated by default, see488+ *--nth-delimiter*) of each input line. When selected, the full489+ input line is printed on stdout. dmenu mode only.490 491 The argument can also be a format string (i.e free-format text),492 where *{N}* expands to the N:th column. Ranges on the form493 *{N..M}* and *{N..}* (open-ended) are also supported.9 unmodified lines503 504 Setting it to *0* is the same as not specifying *--with-nth* at all.505 506 *--accept-nth*=_N_|_FMT_507- Output the N:th column (tab separated) of each input line to stdout.508- dmenu mode only.507+ Output the N:th column (tab separated by default, see508+ *--nth-delimiter*) of each input line to stdout. dmenu mode only.509 510 The argument can also be a format string (i.e free-format text),511 where *{N}* expands to the N:th column. Ranges on the form512 *{N..M}* and *{N..}* (open-ended) are also supported.7 unmodified lines520 on which one is selected, *First* or *Second* will be printed to stdout.521 522 Setting it to *0* is the same as not specifying *--accept-nth* at all.523 524+*--nth-delimiter*=_CHARACTER_525+ Field (column) delimiter for *--with-nth* and *--accept-nth*. Must526+ be a single ASCII character.527+ 528+ Default: _\\t_ (tab)529+530 *-R*,*--no-run-if-empty*531 Exit immediately, without showing the UI, if stdin is532 empty. dmenu mode only.533 91 unmodified linesmodified:column.c+3 added-4 removed
12 unmodified lines13 #include "debug.h"14 #include "xmalloc.h"15 16 char32_t *17-nth_column(const char32_t *string, const char *nth_format)17+nth_column(const char32_t *string, char32_t delim, const char *nth_format)18 {19- const char32_t delim = U'\t';19 const char32_t *string_end = string + c32len(string);20 xassert(*string_end == U'\0');21 22 /* Count number of columns */102 unmodified lines125 } else126 idx_start = 0;127 }128 130- xassert(idx_end >= idx_start);131-129 if (idx_start == 0 || idx_start > col_count || idx_end > col_count) {130 /* Invalid index */131 p++;132 continue;133 }134 135+ xassert(idx_end >= idx_start);136+137 /* Non-template prefix length */138 const size_t copy_len = arg_start - copy_start;139 const size_t copy_len_wide_chars = mbsntoc32(NULL, copy_start, copy_len, 0);140 44 unmodified linesmodified:column.h+3 added-1 removed
1 #pragma once2 3 #include <uchar.h>4-char32_t *nth_column(const char32_t *string, const char *nth_format);4+5+char32_t *nth_column(6+ const char32_t *string, char32_t delim, const char *nth_format);modified:config.c+1 added
1659 unmodified lines1660 .enabled = false,1661 .mode = DMENU_MODE_TEXT,1662 .exit_immediately_if_empty = false,1663 .delim = '\n',1664+ .nth_delim = '\t',1665 .with_nth_format = NULL,1666 .accept_nth_format = NULL,1667 },1668 .anchor = ANCHOR_CENTER,129 unmodified linesmodified:config.h+1 added
164 unmodified lines165 bool enabled;166 enum dmenu_mode mode;167 bool exit_immediately_if_empty;168 char delim;169+ char nth_delim;170 char *with_nth_format;171 char *accept_nth_format;172 } dmenu;173 65 unmodified linesmodified:dmenu.c+13 added-13 removed
23 unmodified lines24 #include "xmalloc.h"25 26 void27 dmenu_load_entries(struct application_list *applications, char delim,28- const char *with_nth_format,28+ const char *with_nth_format, char nth_delim,29 int event_fd, int abort_fd)30 {31 tll(struct application *) entries = tll_init();32 136 unmodified lines169 }170 171 char32_t *title = with_nth_format == 0172 ? xc32dup(wline)173- : nth_column(wline, with_nth_format);173+ : nth_column(wline, nth_delim, with_nth_format);174 175 char32_t *lowercase = xc32dup(title);176 for (size_t i = 0; i < c32len(lowercase); i++)177 lowercase[i] = toc32lower(lowercase[i]);62 unmodified lines240 241 bool242 dmenu_execute(const struct application *app, ssize_t index,243 const struct prompt *prompt, enum dmenu_mode format,244- const char *columns)244+ const char *nth_format, char nth_delim)245 {246 switch (format) {247 case DMENU_MODE_TEXT: {248 const char32_t *output = app != NULL249 ? app->dmenu_input250 : prompt_text(prompt);251 252 char32_t *column_output = NULL;253- if (columns != NULL) {254- column_output = nth_column(output, columns);253+ if (nth_format != NULL) {254+ column_output = nth_column(output, nth_delim, nth_format);255 output = column_output;256 }257 258 char *text = ac32tombs(output);17 unmodified lines276 try_icon_list(struct application *app, icon_theme_list_t themes, int icon_size)277 {278 if (app->icon.name == NULL || strchr(app->icon.name, ',') == NULL)279 return;280- 280+281 if (app->icon.type != ICON_NONE) {282 return;283 }284- 284+285 char *icon_list = xstrdup(app->icon.name);286 char *saveptr = NULL;287- 287+288 for (char *icon_name = strtok_r(icon_list, ",", &saveptr);289 icon_name != NULL;290 icon_name = strtok_r(NULL, ",", &saveptr))291 {292 free(app->icon.name);293 app->icon.name = xstrdup(icon_name);294- 294+295 app->icon.type = ICON_NONE;296 app->icon.path = NULL;297 app->icon.svg = NULL;298 app->icon.png = NULL;299- 299+300 struct application_list temp_list = {301 .v = &app,302 .count = 1,303 .visible_count = 1304 };305- 305+306 icon_lookup_application_icons(themes, icon_size, &temp_list);307- 307+308 if (app->icon.type != ICON_NONE)309 break;310 }311- 311+312 free(icon_list);313 }314 315 void7 unmodified linesmodified:dmenu.h+4 added-2 removed
7 unmodified lines8 #include "prompt.h"9 10 void dmenu_load_entries(11 struct application_list *applications, char delim,12- const char *with_nth_format, int event_fd, int abort_fd);12+ const char *with_nth_format, char nth_delim,13+ int event_fd, int abort_fd);14 15 bool dmenu_execute(16 const struct application *app, ssize_t index,16- const struct prompt *prompt, enum dmenu_mode format, const char *columns);17+ const struct prompt *prompt, enum dmenu_mode format,18+ const char *nth_format, char nth_delim);19 20 void dmenu_try_icon_list(21 struct application_list *applications,22 icon_theme_list_t themes, int icon_size);modified:main.c+30 added-6 removed
434 unmodified lines435 " --dmenu0 like --dmenu, but input is NUL separated\n"436 " instead of newline separated\n"437 " --index print selected entry's index instead of of the \n"438 " entry's text (dmenu mode only)\n"439- " --with-nth=N display the N:th column (tab separated) of each\n"440- " input line (dmenu only)\n"441- " --accept-nth=N output the N:th column (tab separated) of each\n"442- " input line (dmenu only)\n"439+ " --with-nth=N|FMT display the N:th column (tab separated by\n"440+ " default) of each input line (dmenu only)\n"441+ " --accept-nth=N|FMT output the N:th column (tab separated by\n"442+ " default) of each input line (dmenu only)\n"443+ " --nth-delimiter=CHARACTER field (column) character, for --with-nth and\n"444+ " --accept-nth\n"445 " -R,--no-run-if-empty exit immediately without showing UI if stdin\n"446 " is empty (dmenu mode only)\n"447 " --log-level={info|warning|error|none}\n"448 " log level (warning)\n"116 unmodified lines565 bool actions_enabled = conf->actions_enabled;566 bool dmenu_enabled = conf->dmenu.enabled;567 bool icons_enabled = conf->icons_enabled;568 char dmenu_delim = conf->dmenu.delim;569+ char dmenu_nth_delim = conf->dmenu.nth_delim;570+ const char *dmenu_with_nth_format = conf->dmenu.with_nth_format;571 bool filter_desktop = conf->filter_desktop;572 bool list_exec_in_path = conf->list_executables_in_path;573 char_list_t desktops = tll_init();574 char *saveptr = NULL;13 unmodified lines588 }589 590 if (dmenu_enabled) {591 if (!conf->prompt_only) {588- dmenu_load_entries(apps, dmenu_delim, conf->dmenu.with_nth_format,589- ctx->event_fd, ctx->dmenu_abort_fd);592+ dmenu_load_entries(593+ apps, dmenu_delim, dmenu_with_nth_format, dmenu_nth_delim,594+ ctx->event_fd, ctx->dmenu_abort_fd);595 read_cache(cache_path, apps, true);596 }597 } else {598 gettimeofday(&ctx->timing.apps.start, NULL);254 unmodified lines853 #define OPT_HIDE_PROMPT 304854 #define OPT_AUTO_SELECT 305855 #define OPT_SELECTION_RADIUS 306856 #define OPT_NO_MOUSE 307857+ #define OPT_DMENU_NTH_DELIM 308858 859 static const struct option longopts[] = {860 {"config", required_argument, 0, OPT_CONFIG},861 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},68 unmodified lines930 {"dmenu", no_argument, 0, 'd'},931 {"dmenu0", no_argument, 0, OPT_DMENU_NULL},932 {"no-run-if-empty", no_argument, 0, 'R'},933 {"index", no_argument, 0, OPT_DMENU_INDEX},934+ {"nth-delimiter", required_argument, 0, OPT_DMENU_NTH_DELIM},935 {"with-nth", required_argument, 0, OPT_DMENU_WITH_NTH},936 {"accept-nth", required_argument, 0, OPT_DMENU_ACCEPT_NTH},937 938 /* Misc */57 unmodified lines996 bool dmenu_enabled_set:1;997 bool dmenu_mode_set:1;998 bool dmenu_exit_immediately_if_empty_set:1;999 bool dmenu_delim_set:1;1000+ bool dmenu_nth_delim_set:1;1001 bool dmenu_with_nth_set:1;1002 bool dmenu_accept_nth_set:1;1003 bool layer_set:1;1004 bool keyboard_focus_set:1;715 unmodified lines1720 cmdline_overrides.conf.dmenu.mode = DMENU_MODE_INDEX;1721 cmdline_overrides.dmenu_mode_set = true;1722 break;1723 1724+ case OPT_DMENU_NTH_DELIM:1725+ if (strlen(optarg) != 1) {1726+ fprintf(1727+ stderr,1728+ "%s: invalid nth-delimiter. Must be a single ASCII character",1729+ optarg);1730+ return EXIT_FAILURE;1731+ }1732+1733+ cmdline_overrides.conf.dmenu.nth_delim = optarg[0];1734+ cmdline_overrides.dmenu_nth_delim_set = true;1735+ printf("LKDJFLKDJF: delim: %c (%x)\n", cmdline_overrides.conf.dmenu.nth_delim, cmdline_overrides.conf.dmenu.nth_delim);1736+ break;1737+1738 case OPT_DMENU_WITH_NTH: {1739 unsigned int with_nth_idx;1740 if (sscanf(optarg, "%u", &with_nth_idx) == 1)1741 cmdline_overrides.conf.dmenu.with_nth_format = xasprintf("{%u}", with_nth_idx);322 unmodified lines2064 if (cmdline_overrides.dmenu_mode_set)2065 conf.dmenu.mode = cmdline_overrides.conf.dmenu.mode;2066 if (cmdline_overrides.dmenu_exit_immediately_if_empty_set)2067 conf.dmenu.exit_immediately_if_empty = cmdline_overrides.conf.dmenu.exit_immediately_if_empty;2068+ if (cmdline_overrides.dmenu_nth_delim_set)2069+ conf.dmenu.nth_delim = cmdline_overrides.conf.dmenu.nth_delim;2070 if (cmdline_overrides.dmenu_with_nth_set) {2071 free(conf.dmenu.with_nth_format);2072 conf.dmenu.with_nth_format = cmdline_overrides.conf.dmenu.with_nth_format;2073 }247 unmodified linesmodified:wayland.c+3 added-1 removed
632 unmodified lines633 struct application *app = match != NULL ? match->application : NULL;634 ssize_t index = app != NULL ? app->index : -1;635 636 if (wayl->conf->dmenu.enabled) {637- dmenu_execute(app, index, wayl->prompt, wayl->conf->dmenu.mode, wayl->conf->dmenu.accept_nth_format);637+ dmenu_execute(app, index, wayl->prompt, wayl->conf->dmenu.mode,638+ wayl->conf->dmenu.accept_nth_format,639+ wayl->conf->dmenu.nth_delim);640 wayl->exit_code = custom_success_exit_code >= 0641 ? custom_success_exit_code642 : EXIT_SUCCESS;643 wayl->status = EXIT_UPDATE_CACHE;2425 unmodified lines