commit 4d8bad93b21aefdb6108cf79aecb48e99bd182ea
Author: Timmy Keller <[email protected]>
Date:   Sat Jan 28 23:30:33 2023 -0600

    tmenu patch for dmenu which adds the ability to have the text displayed in 
dmenu be different from the text that is output

diff --git a/tools.suckless.org/dmenu/patches/tmenu/dmenu-tmenu-5.2.diff 
b/tools.suckless.org/dmenu/patches/tmenu/dmenu-tmenu-5.2.diff
new file mode 100644
index 00000000..41463407
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/tmenu/dmenu-tmenu-5.2.diff
@@ -0,0 +1,110 @@
+diff --git a/config.def.h b/config.def.h
+index 1edb647..805d8c4 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -21,3 +21,6 @@ static unsigned int lines      = 0;
+  * for example: " /?\"&[]"
+  */
+ static const char worddelimiters[] = " ";
++
++/* delimiter for tmenu */
++static char valuedelimiter = '        ';
+diff --git a/dmenu.1 b/dmenu.1
+index 323f93c..fb22ed3 100644
+--- a/dmenu.1
++++ b/dmenu.1
+@@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches 
end\-of\-file.
+ .B \-i
+ dmenu matches menu items case insensitively.
+ .TP
++.BI \-d " tmenu delimiter"
++when used in a line, the value after the delimiter will be displayed. When 
selected, the value before the delimiter will be output. Only uses a single 
char as the delimiter.
++.TP
+ .BI \-l " lines"
+ dmenu lists items vertically, with the given number of lines.
+ .TP
+diff --git a/dmenu.c b/dmenu.c
+index 27b7a30..b586a40 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -29,7 +29,7 @@
+ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
+ 
+ struct item {
+-      char *text;
++      char *text, *value;
+       struct item *left, *right;
+       int out;
+ };
+@@ -104,8 +104,8 @@ cleanup(void)
+       XUngrabKey(dpy, AnyKey, AnyModifier, root);
+       for (i = 0; i < SchemeLast; i++)
+               free(scheme[i]);
+-      for (i = 0; items && items[i].text; ++i)
+-              free(items[i].text);
++      for (i = 0; items && items[i].value; ++i)
++              free(items[i].value);
+       free(items);
+       drw_free(drw);
+       XSync(dpy, False);
+@@ -490,7 +490,7 @@ insert:
+               break;
+       case XK_Return:
+       case XK_KP_Enter:
+-              puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
++              puts((sel && !(ev->state & ShiftMask)) ? sel->value : text);
+               if (!(ev->state & ControlMask)) {
+                       cleanup();
+                       exit(0);
+@@ -549,7 +549,7 @@ paste(void)
+ static void
+ readstdin(void)
+ {
+-      char *line = NULL;
++      char *line = NULL, *text;
+       size_t i, junk, itemsiz = 0;
+       ssize_t len;
+ 
+@@ -562,13 +562,22 @@ readstdin(void)
+               }
+               if (line[len - 1] == '
')
+                       line[len - 1] = '+-             items[i].text = line;
++
++              if ((text = strchr(line, valuedelimiter)) != NULL) {
++                      items[i].text = text + 1;
++                      text[0] = '++           } else {
++                      items[i].text = line;
++              }
++              items[i].value = line;
+               items[i].out = 0;
+               line = NULL; /* next call of getline() allocates a new line */
+       }
+       free(line);
+-      if (items)
++      if (items) {
+               items[i].text = NULL;
++              items[i].value = NULL;
++      }
+       lines = MIN(lines, i);
+ }
+ 
+@@ -714,7 +723,7 @@ setup(void)
+ static void
+ usage(void)
+ {
+-      die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]
"
++      die("usage: dmenu [-bfiv] [-d tmenu-delim] [-l lines] [-p prompt] [-fn 
font] [-m monitor]
"
+           "             [-nb color] [-nf color] [-sb color] [-sf color] [-w 
windowid]");
+ }
+ 
+@@ -739,6 +748,8 @@ main(int argc, char *argv[])
+               } else if (i + 1 == argc)
+                       usage();
+               /* these options take one argument */
++              else if (!strcmp(argv[i], "-d"))   /* delimiter for tmenu */
++                      valuedelimiter = argv[++i][0];
+               else if (!strcmp(argv[i], "-l"))   /* number of lines in 
vertical list */
+                       lines = atoi(argv[++i]);
+               else if (!strcmp(argv[i], "-m"))
diff --git a/tools.suckless.org/dmenu/patches/tmenu/index.md 
b/tools.suckless.org/dmenu/patches/tmenu/index.md
new file mode 100644
index 00000000..c2bc11b4
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/tmenu/index.md
@@ -0,0 +1,18 @@
+tmenu
+====
+Text displayed != text output
+For each line, if the delimeter character (tab by default, selectable with -d 
option) is present, the text before that character will be the text output, and 
the text after that delimiter will be the text displayed on the menu.
+
+For example,
+$ echo "~/.local/bin" "        " "local binarys" | dmenu
+will display "local binarys" in dmenu. When this option is selected, 
"~/.local/bin" will be output to stdout
+
+When the delimiter character is not present, the behavior is the same as w/o 
this patch
+
+Download
+--------
+* [dmenu-tmenu-5.2.diff](dmenu-tmenu-5.2.diff)
+
+Author
+------
+* Tim Keller <[email protected]>


Reply via email to