aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2023-02-25 22:13:08 -0500
committerSam Chudnick <sam@chudnick.com>2023-02-25 22:13:08 -0500
commitfff3a11874a0ea6c7e89ab5807a4e2673706c2c2 (patch)
treefaae7e2c69023c245ad11e007fc8b009588e3cf8
parent3cc0e23d37354724f897dfaf74411c58c2b3bdea (diff)
Apply rejectnomatch patch
-rwxr-xr-xdmenubin44544 -> 44616 bytes
-rw-r--r--dmenu.14
-rw-r--r--dmenu.c19
3 files changed, 21 insertions, 2 deletions
diff --git a/dmenu b/dmenu
index 4a32929..9595929 100755
--- a/dmenu
+++ b/dmenu
Binary files differ
diff --git a/dmenu.1 b/dmenu.1
index 762f707..29d3c6f 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -3,7 +3,7 @@
3dmenu \- dynamic menu 3dmenu \- dynamic menu
4.SH SYNOPSIS 4.SH SYNOPSIS
5.B dmenu 5.B dmenu
6.RB [ \-bfivP ] 6.RB [ \-bfirvP ]
7.RB [ \-l 7.RB [ \-l
8.IR lines ] 8.IR lines ]
9.RB [ \-m 9.RB [ \-m
@@ -49,6 +49,8 @@ dmenu matches menu items case insensitively.
49.TP 49.TP
50.B \-P 50.B \-P
51dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. 51dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored.
52.B \-r
53dmenu will reject any input which would result in no matching option left.
52.TP 54.TP
53.BI \-l " lines" 55.BI \-l " lines"
54dmenu lists items vertically, with the given number of lines. 56dmenu lists items vertically, with the given number of lines.
diff --git a/dmenu.c b/dmenu.c
index b1f1d3d..c5cce46 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -43,6 +43,7 @@ static char *embed;
43static int bh, mw, mh; 43static int bh, mw, mh;
44static int inputw = 0, promptw, passwd = 0; 44static int inputw = 0, promptw, passwd = 0;
45static int lrpad; /* sum of left and right padding */ 45static int lrpad; /* sum of left and right padding */
46static int reject_no_match = 0;
46static size_t cursor; 47static size_t cursor;
47static struct item *items = NULL; 48static struct item *items = NULL;
48static struct item *matches, *matchend; 49static struct item *matches, *matchend;
@@ -426,12 +427,26 @@ insert(const char *str, ssize_t n)
426{ 427{
427 if (strlen(text) + n > sizeof text - 1) 428 if (strlen(text) + n > sizeof text - 1)
428 return; 429 return;
430
431 static char last[BUFSIZ] = "";
432 if(reject_no_match) {
433 /* store last text value in case we need to revert it */
434 memcpy(last, text, BUFSIZ);
435 }
436
429 /* move existing text out of the way, insert new text, and update cursor */ 437 /* move existing text out of the way, insert new text, and update cursor */
430 memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0)); 438 memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0));
431 if (n > 0) 439 if (n > 0)
432 memcpy(&text[cursor], str, n); 440 memcpy(&text[cursor], str, n);
433 cursor += n; 441 cursor += n;
434 match(); 442 match();
443
444 if(!matches && reject_no_match) {
445 /* revert to last text value if theres no match */
446 memcpy(text, last, BUFSIZ);
447 cursor -= n;
448 match();
449 }
435} 450}
436 451
437static size_t 452static size_t
@@ -858,7 +873,7 @@ setup(void)
858static void 873static void
859usage(void) 874usage(void)
860{ 875{
861 die("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" 876 die("usage: dmenu [-bfirvP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
862 " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); 877 " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
863} 878}
864 879
@@ -884,6 +899,8 @@ main(int argc, char *argv[])
884 fstrstr = cistrstr; 899 fstrstr = cistrstr;
885 } else if (!strcmp(argv[i], "-P")) /* is the input a password */ 900 } else if (!strcmp(argv[i], "-P")) /* is the input a password */
886 passwd = 1; 901 passwd = 1;
902 else if (!strcmp(argv[i], "-r")) /* reject input which results in no match */
903 reject_no_match = 1;
887 else if (i + 1 == argc) 904 else if (i + 1 == argc)
888 usage(); 905 usage();
889 /* these options take one argument */ 906 /* these options take one argument */