about summary refs log tree commit diff stats
path: root/dmenu.c
diff options
context:
space:
mode:
author2020-04-18 09:59:37 -0400
committer2020-04-18 09:59:37 -0400
commit96608c36b59b6fa1803d2e32cfbab73c8b73f46d (patch)
tree7a71e603a232e33f3036eb6c51fcf2b26d4cd775 /dmenu.c
parentef9e3d24391cd1f324aedb16ff5745051f3710f0 (diff)
downloaddmenu-96608c36b59b6fa1803d2e32cfbab73c8b73f46d.tar.gz
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/dmenu.c b/dmenu.c
index 07afc9f..bc4ebfc 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;
@@ -323,12 +324,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
@@ -860,7 +875,7 @@ setup(void)
 static void
 usage(void)
 {
-	fputs("usage: dmenu [-bfiPv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+	fputs("usage: dmenu [-bfiPrv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
 	exit(1);
 }
@@ -910,6 +925,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 */