diff options
| author | Sam Chudnick <sam@chudnick.com> | 2023-02-25 22:13:08 -0500 |
|---|---|---|
| committer | Sam Chudnick <sam@chudnick.com> | 2023-02-25 22:13:08 -0500 |
| commit | fff3a11874a0ea6c7e89ab5807a4e2673706c2c2 (patch) | |
| tree | faae7e2c69023c245ad11e007fc8b009588e3cf8 | |
| parent | 3cc0e23d37354724f897dfaf74411c58c2b3bdea (diff) | |
Apply rejectnomatch patch
| -rwxr-xr-x | dmenu | bin | 44544 -> 44616 bytes | |||
| -rw-r--r-- | dmenu.1 | 4 | ||||
| -rw-r--r-- | dmenu.c | 19 |
3 files changed, 21 insertions, 2 deletions
| Binary files differ | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | dmenu \- dynamic menu | 3 | dmenu \- 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 |
| 51 | dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. | 51 | dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. |
| 52 | .B \-r | ||
| 53 | dmenu will reject any input which would result in no matching option left. | ||
| 52 | .TP | 54 | .TP |
| 53 | .BI \-l " lines" | 55 | .BI \-l " lines" |
| 54 | dmenu lists items vertically, with the given number of lines. | 56 | dmenu lists items vertically, with the given number of lines. |
| @@ -43,6 +43,7 @@ static char *embed; | |||
| 43 | static int bh, mw, mh; | 43 | static int bh, mw, mh; |
| 44 | static int inputw = 0, promptw, passwd = 0; | 44 | static int inputw = 0, promptw, passwd = 0; |
| 45 | static int lrpad; /* sum of left and right padding */ | 45 | static int lrpad; /* sum of left and right padding */ |
| 46 | static int reject_no_match = 0; | ||
| 46 | static size_t cursor; | 47 | static size_t cursor; |
| 47 | static struct item *items = NULL; | 48 | static struct item *items = NULL; |
| 48 | static struct item *matches, *matchend; | 49 | static 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 | ||
| 437 | static size_t | 452 | static size_t |
| @@ -858,7 +873,7 @@ setup(void) | |||
| 858 | static void | 873 | static void |
| 859 | usage(void) | 874 | usage(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 */ |
