[wiki] [sites] dmenu: add new patch reject-no-match || Michael Stummvoll

From: <git_AT_suckless.org>
Date: Mon, 24 Jul 2017 14:50:59 +0200

commit 9afcd97bab4b5339f7bbd4bafb332792b9683b90
Author: Michael Stummvoll <suckless_AT_stummi.org>
Date: Mon Jul 24 14:46:18 2017 +0200

    dmenu: add new patch reject-no-match

diff --git a/tools.suckless.org/dmenu/patches/dmenu-rejectnomatch-4.7.diff b/tools.suckless.org/dmenu/patches/dmenu-rejectnomatch-4.7.diff
new file mode 100644
index 00000000..329ab1d0
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/dmenu-rejectnomatch-4.7.diff
_AT_@ -0,0 +1,82 @@
+diff --git a/dmenu.1 b/dmenu.1
+index 9eab758..61084ab 100644
+--- a/dmenu.1
++++ b/dmenu.1
+_AT_@ -3,7 +3,7 @@
+ dmenu \- dynamic menu
+ .SH SYNOPSIS
+ .B dmenu
+-.RB [ \-bfiv ]
++.RB [ \-bfirv ]
+ .RB [ \-l
+ .IR lines ]
+ .RB [ \-m
+_AT_@ -47,6 +47,9 @@ X until stdin reaches end\-of\-file.
+ .B \-i
+ dmenu matches menu items case insensitively.
+ .TP
++.B \-r
++dmenu will reject any input which would result in no matching option left.
++.TP
+ .BI \-l " lines"
+ dmenu lists items vertically, with the given number of lines.
+ .TP
+diff --git a/dmenu.c b/dmenu.c
+index d605ab4..7505278 100644
+--- a/dmenu.c
++++ b/dmenu.c
+_AT_@ -38,6 +38,7 @@ static char *embed;
+ static int bh, mw, mh;
+ static int inputw = 0, promptw;
+ static int lrpad; /* sum of left and right padding */
++static int reject_no_match = 0;
+ static size_t cursor;
+ static struct item *items = NULL;
+ static struct item *matches, *matchend;
+_AT_@ -268,12 +269,26 @@ insert(const char *str, ssize_t n)
+ {
+ if (strlen(text) + n > sizeof text - 1)
+ return;
++
++ static char last[BUFSIZ] = "";
++ if(reject_no_match) {
++ /* store last text value in case we need to revert it */
++ memcpy(last, text, BUFSIZ);
++ }
++
+ /* move existing text out of the way, insert new text, and update cursor */
+ memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0));
+ if (n > 0)
+ memcpy(&text[cursor], str, n);
+ cursor += n;
+ match();
++
++ if(!matches && reject_no_match) {
++ /* revert to last text value if theres no match */
++ memcpy(text, last, BUFSIZ);
++ cursor -= n;
++ match();
++ }
+ }
+
+ static size_t
+_AT_@ -636,7 +651,7 @@ setup(void)
+ static void
+ usage(void)
+ {
+- fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]
"
++ fputs("usage: dmenu [-bfirv] [-l lines] [-p prompt] [-fn font] [-m monitor]
"
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]
", stderr);
+ exit(1);
+ }
+_AT_@ -659,7 +674,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")) /* reject input which results in no match */
++ reject_no_match = 1;
++ 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/reject-no-match.md b/tools.suckless.org/dmenu/patches/reject-no-match.md
new file mode 100644
index 00000000..ccd14abc
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/reject-no-match.md
_AT_@ -0,0 +1,13 @@
+Reject no match
+===============
+
+Adds a new flag to dmenu with which text input will be rejected if it would
+result in no matching item
+
+Download
+--------
+* [dmenu-rejectnomatch-4.7.diff](dmenu-rejectnomatch-4.7.diff)
+
+Author
+------
+* Michael Stummvoll (stummi)<suckless_AT_stummi.org>
Received on Mon Jul 24 2017 - 14:50:59 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 24 2017 - 15:01:01 CEST