From fff3a11874a0ea6c7e89ab5807a4e2673706c2c2 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sat, 25 Feb 2023 22:13:08 -0500 Subject: Apply rejectnomatch patch --- dmenu | Bin 44544 -> 44616 bytes dmenu.1 | 4 +++- dmenu.c | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dmenu b/dmenu index 4a32929..9595929 100755 Binary files a/dmenu and b/dmenu differ diff --git a/dmenu.1 b/dmenu.1 index 762f707..29d3c6f 100644 --- a/dmenu.1 +++ b/dmenu.1 @@ -3,7 +3,7 @@ dmenu \- dynamic menu .SH SYNOPSIS .B dmenu -.RB [ \-bfivP ] +.RB [ \-bfirvP ] .RB [ \-l .IR lines ] .RB [ \-m @@ -49,6 +49,8 @@ dmenu matches menu items case insensitively. .TP .B \-P dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. +.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. 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; static int bh, mw, mh; static int inputw = 0, promptw, passwd = 0; 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; @@ -426,12 +427,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 @@ -858,7 +873,7 @@ setup(void) static void usage(void) { - die("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + die("usage: dmenu [-bfirvP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); } @@ -884,6 +899,8 @@ main(int argc, char *argv[]) fstrstr = cistrstr; } else if (!strcmp(argv[i], "-P")) /* is the input a password */ passwd = 1; + 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 */ -- cgit v1.2.3