commit bd07f20f6a98964b38cc6adfc92b3be2e61943a0
parent f1a5d8d56cbae1e78f759549c0ad740b24220ad9
Author: yosh <yosh-git@riseup.net>
Date: Mon, 19 Sep 2022 19:25:12 -0400
[dmenu][patch] Add patch for dmenu-fce06f4: tsv-alt
This commit adds a patch for dmenu to separate the displayed text and
output text based on the presence of a tab character. While being
similar to tsv, it is different enough to be considered a separate
patch.
Diffstat:
2 files changed, 135 insertions(+), 0 deletions(-)
diff --git a/tools.suckless.org/dmenu/patches/tsv-alt/dmenu-tsv-alt-20220919-fce06f4.diff b/tools.suckless.org/dmenu/patches/tsv-alt/dmenu-tsv-alt-20220919-fce06f4.diff
@@ -0,0 +1,105 @@
+diff --git a/config.def.h b/config.def.h
+index 1edb647..bd0fcef 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -21,3 +21,8 @@ static unsigned int lines = 0;
+ * for example: " /?\"&[]"
+ */
+ static const char worddelimiters[] = " ";
++
++/* tsv-alt: reverse the order of tab separation.
++ * 0 = display<TAB>output. 1 = output<TAB>display
++ * can be reversed with -r as well */
++static int revtab = 0;
+diff --git a/dmenu.1 b/dmenu.1
+index 323f93c..39c3492 100644
+--- a/dmenu.1
++++ b/dmenu.1
+@@ -3,7 +3,7 @@
+ dmenu \- dynamic menu
+ .SH SYNOPSIS
+ .B dmenu
+-.RB [ \-bfiv ]
++.RB [ \-bfivr ]
+ .RB [ \-l
+ .IR lines ]
+ .RB [ \-m
+@@ -80,6 +80,10 @@ prints version information to stdout, then exits.
+ .TP
+ .BI \-w " windowid"
+ embed into windowid.
++.TP
++.B \-r
++tsv-alt: reverse the behavior of tab separation.
++.TP
+ .SH USAGE
+ dmenu is completely controlled by the keyboard. Items are selected using the
+ arrow keys, page up, page down, home, and end.
+diff --git a/dmenu.c b/dmenu.c
+index 818313a..9783fc4 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -30,6 +30,7 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
+
+ struct item {
+ char *text;
++ char *otext;
+ struct item *left, *right;
+ int out;
+ };
+@@ -105,7 +106,7 @@ cleanup(void)
+ for (i = 0; i < SchemeLast; i++)
+ free(scheme[i]);
+ for (i = 0; items && items[i].text; ++i)
+- free(items[i].text);
++ free(revtab ? items[i].otext : items[i].text);
+ free(items);
+ drw_free(drw);
+ XSync(dpy, False);
+@@ -490,7 +491,7 @@ insert:
+ break;
+ case XK_Return:
+ case XK_KP_Enter:
+- puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
++ puts((sel && !(ev->state & ShiftMask)) ? sel->otext : text);
+ if (!(ev->state & ControlMask)) {
+ cleanup();
+ exit(0);
+@@ -560,11 +561,15 @@ readstdin(void)
+ die("cannot realloc %zu bytes:", size);
+ if (line[len - 1] == '\n')
+ line[len - 1] = '\0';
+- items[i].text = line;
++ items[i].text = items[i].otext = line;
++ if ((line = strchr(line, '\t'))) {
++ *line++ = '\0';
++ revtab ? (items[i].text = line) : (items[i].otext = line);
++ }
+ items[i].out = 0;
+ }
+ if (items)
+- items[i].text = NULL;
++ items[i].text = items[i].otext = NULL;
+ lines = MIN(lines, i);
+ }
+
+@@ -710,7 +715,7 @@ setup(void)
+ static void
+ usage(void)
+ {
+- fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
++ fputs("usage: dmenu [-bfivr] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
+ exit(1);
+ }
+@@ -733,7 +738,9 @@ main(int argc, char *argv[])
+ else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
+ fstrncmp = strncasecmp;
+ fstrstr = cistrstr;
+- } else if (i + 1 == argc)
++ } else if (!strcmp(argv[i], "-r")) /* reverse the tab separation */
++ revtab = (!revtab);
++ else if (i + 1 == argc)
+ usage();
+ /* these options take one argument */
+ else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
diff --git a/tools.suckless.org/dmenu/patches/tsv-alt/index.md b/tools.suckless.org/dmenu/patches/tsv-alt/index.md
@@ -0,0 +1,30 @@
+tsv alt
+=======
+
+Description
+-----------
+This patch is similar to [tsv](https://tools.suckless.org/dmenu/patches/tsv/), but differs in the following way:
+
+All text before the first tab character will be the text displayed by
+dmenu and the text that matching is performed on, while all text after
+it will be the text outputted by dmenu. Subsequent tab characters do
+not affect anything.
+
+Configuration
+-------------
+Both a config.def.h value and runtime flag (`-r`) are available to
+reverse the behavior of tab separation. Be sure to check with any other
+patches for conflicts.
+
+Notes
+-----
+This patch is incompatible with any commit before `32db2b1` (2022-09-02)
+due to said commit changing how stdin is read.
+
+Download
+--------
+* [dmenu-tsv-alt-20220919-fce06f4.diff](dmenu-tsv-alt-20220919-fce06f4.diff)
+
+Author
+------
+* yosh