[hackers] [dmenu][PATCH] this patch allows dmenu to grab the the keyboard output (raw user input text) and then displays/prints , this is useful in case of adding new field to a list of major bookmarks fields for example. This behaviour exists in rofi using the command (rofi -dmenu ).

From: <mohrizq895_AT_gmail.com>
Date: Sat, 25 Feb 2023 19:45:05 +0200

From: Mohamed Rezk <mohrizq895_AT_gmail.com>

---
 dmenu.1 | 3 +++
 dmenu.c | 9 ++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/dmenu.1 b/dmenu.1
index 323f93c..5cea477 100644
--- a/dmenu.1
+++ b/dmenu.1
_AT_@ -44,6 +44,9 @@ dmenu appears at the bottom of the screen.
 dmenu grabs the keyboard before reading stdin if not reading from a tty. This
 is faster, but will lock up X until stdin reaches end\-of\-file.
 .TP
+.B \-t
+dmenu grabs the keyboard output and prints it.
+.TP
 .B \-i
 dmenu matches menu items case insensitively.
 .TP
diff --git a/dmenu.c b/dmenu.c
index 27b7a30..ccd32ab 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -37,7 +37,7 @@ struct item {
 static char text[BUFSIZ] = "";
 static char *embed;
 static int bh, mw, mh;
-static int inputw = 0, promptw;
+static int inputw = 0, user_input = 0 ,promptw;
 static int lrpad; /* sum of left and right padding */
 static size_t cursor;
 static struct item *items = NULL;
_AT_@ -553,6 +553,11 @@ readstdin(void)
 	size_t i, junk, itemsiz = 0;
 	ssize_t len;
 
+	if(user_input){
+    	inputw = lines = 0;
+    	return;
+  	}
+
 	/* read each line from stdin and add it to the item list */
 	for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++) {
 		if (i + 1 >= itemsiz) {
_AT_@ -733,6 +738,8 @@ main(int argc, char *argv[])
 			topbar = 0;
 		else if (!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */
 			fast = 1;
+		else if (!strcmp(argv[i], "-t"))   /* grabs keyboard output */
+			user_input = 1;
 		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
-- 
2.39.2
Received on Sat Feb 25 2023 - 18:45:05 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 25 2023 - 19:00:45 CET