commit 3be9b01d1a11b564debfd55acc34ab32a6838a04
Author: NRK <[email protected]>
Date:   Sat Sep 4 01:54:52 2021 +0600

    [dmenu][patch][separator] initial commit

diff --git 
a/tools.suckless.org/dmenu/patches/separator/dmenu-separator-20210904-d78ff08.diff
 
b/tools.suckless.org/dmenu/patches/separator/dmenu-separator-20210904-d78ff08.diff
new file mode 100644
index 00000000..a72de548
--- /dev/null
+++ 
b/tools.suckless.org/dmenu/patches/separator/dmenu-separator-20210904-d78ff08.diff
@@ -0,0 +1,92 @@
+diff --git a/dmenu.1 b/dmenu.1
+index 323f93c..a07e0f4 100644
+--- a/dmenu.1
++++ b/dmenu.1
+@@ -80,6 +80,14 @@ prints version information to stdout, then exits.
+ .TP
+ .BI \-w " windowid"
+ embed into windowid.
++.TP
++.BI \-d " separator"
++separate the input into two halves on the first occurrence of the given 
charcter.
++Display only the first half in dmenu and print the second half to stdout upon 
selection.
++Appending '|' to the separator reverses the display/printing order.
++.TP
++.BI \-D " separator"
++same as \-d but separate based on the last occurrence.
+ .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 98507d9..2ac2c9a 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -30,12 +30,16 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* 
color schemes */
+ 
+ struct item {
+       char *text;
++      char *text_output;
+       struct item *left, *right;
+       int out;
+ };
+ 
+ static char text[BUFSIZ] = "";
+ static char *embed;
++static char separator;
++static int separator_greedy;
++static int separator_reverse;
+ static int bh, mw, mh;
+ static int inputw = 0, promptw;
+ static int lrpad; /* sum of left and right padding */
+@@ -473,7 +477,7 @@ insert:
+               break;
+       case XK_Return:
+       case XK_KP_Enter:
+-              puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
++              puts((sel && !(ev->state & ShiftMask)) ? sel->text_output : 
text);
+               if (!(ev->state & ControlMask)) {
+                       cleanup();
+                       exit(0);
+@@ -545,6 +549,18 @@ readstdin(void)
+                       *p = '+                 if (!(items[i].text = 
strdup(buf)))
+                       die("cannot strdup %u bytes:", strlen(buf) + 1);
++              if (separator && (p = (separator_greedy) ?
++                      strrchr(items[i].text, separator) : 
strchr(items[i].text, separator))) {
++                      *p = '++                        items[i].text_output = 
++p;
++              } else {
++                      items[i].text_output = items[i].text;
++              }
++              if (separator_reverse) {
++                      char *tmp = items[i].text;
++                      items[i].text = items[i].text_output;
++                      items[i].text_output = tmp;
++              }
+               items[i].out = 0;
+               drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL);
+               if (tmpmax > inputw) {
+@@ -700,8 +716,9 @@ setup(void)
+ static void
+ usage(void)
+ {
+-      fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m 
monitor]
"
+-            "             [-nb color] [-nf color] [-sb color] [-sf color] [-w 
windowid]
", stderr);
++      fputs("usage: dmenu [-bfinv] [-l lines] [-p prompt] [-fn font] [-m 
monitor]
"
++            "             [-nb color] [-nf color] [-sb color] [-sf color] [-w 
windowid]
"
++            "             [-d separator] [-D separator]
", stderr);
+       exit(1);
+ }
+ 
+@@ -744,6 +761,11 @@ main(int argc, char *argv[])
+                       colors[SchemeSel][ColFg] = argv[++i];
+               else if (!strcmp(argv[i], "-w"))   /* embedding window id */
+                       embed = argv[++i];
++              else if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "-D")) { /* 
field separator */
++                      separator_reverse = (*(argv[i+1]+1) == '|');
++                      separator_greedy = !strcmp(argv[i], "-D");
++                      separator = *argv[++i];
++              }
+               else
+                       usage();
+ 
diff --git a/tools.suckless.org/dmenu/patches/separator/index.md 
b/tools.suckless.org/dmenu/patches/separator/index.md
new file mode 100644
index 00000000..82f4bc56
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/separator/index.md
@@ -0,0 +1,27 @@
+separator
+===
+
+This patch adds `-d` and `-D` flags which separates the input into two halves.
+One half will be displayed into dmenu and the other half will be printed to 
stdout.
+
+The following example will split the input into two halves on the _first_
+occurrence of ' ' (space).  Meaning "alpha" will be displayed on dmenu, and
+"beta charlie" will be printed to stdout upon selection.
+
+```sh
+echo "alpha beta charlie" | dmenu -d ' '
+```
+
+`-D` is similar but it separates the input based on the _last_ occurrence 
instead.
+
+The display/print order can be reversed by appending '|' to the separator.
+Example: `dmenu -D "$(printf " |")"` will separate on the last tab character
+and display the latter half on dmenu while printing the first half upon 
selection.
+
+Download
+--------
+* 
[dmenu-separator-20210904-d78ff08.diff](dmenu-separator-20210904-d78ff08.diff)
+
+Author
+------
+* NRK <[email protected]>


Reply via email to