[hackers] [dmenu][PATCH] Add incremental output.

From: koniu <koniu_AT_riseup.net>
Date: Tue, 17 May 2016 00:02:38 +0100

http://tools.suckless.org/dmenu/patches/incremental

This patch causes dmenu to print out the current text each time a key is pressed.

Updated for current master branch.
---
 config.def.h |  1 +
 dmenu.1      |  4 ++++
 dmenu.c      | 11 +++++++++--
 3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index dcffd38..b879e9f 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -2,6 +2,7 @@
 /* Default settings; can be overriden by command line. */
 
 static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
+static int incremental = 0;                 /* -r  option; if 1, dmenu outputs during input */
 /* -fn option overrides fonts[0]; default X11 font or font set */
 static const char *fonts[] = {
 	"monospace:size=10"
diff --git a/dmenu.1 b/dmenu.1
index d3ab805..0f7486e 100644
--- a/dmenu.1
+++ b/dmenu.1
_AT_@ -6,6 +6,7 @@ dmenu \- dynamic menu
 .RB [ \-b ]
 .RB [ \-f ]
 .RB [ \-i ]
+.RB [ \-r ]
 .RB [ \-l
 .RB [ \-m
 .IR monitor ]
_AT_@ -48,6 +49,9 @@ X until stdin reaches end\-of\-file.
 .B \-i
 dmenu matches menu items case insensitively.
 .TP
+.B \-i
+dmenu outputs text each time a key is pressed.
+.TP
 .BI \-l " lines"
 dmenu lists items vertically, with the given number of lines.
 .TP
diff --git a/dmenu.c b/dmenu.c
index e0c2f80..100ab10 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -447,6 +447,11 @@ keypress(XKeyEvent *ev)
 		match();
 		break;
 	}
+	if(incremental) {
+		fprintf(stdout, "%s\n", text);
+		fflush(stdout);
+	}
+
 	drawmenu();
 }
 
_AT_@ -610,7 +615,7 @@ setup(void)
 static void
 usage(void)
 {
-	fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+	fputs("usage: dmenu [-b] [-f] [-i] [-r] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
 	exit(1);
 }
_AT_@ -632,7 +637,9 @@ main(int argc, char *argv[])
 		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
-		} else if (i + 1 == argc)
+		} else if (!strcmp(argv[i], "-r")) /* outputs during input */
+			incremental = 1;
+		else if (i + 1 == argc)
 			usage();
 		/* these options take one argument */
 		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
-- 
2.8.1
Received on Tue May 17 2016 - 01:02:38 CEST

This archive was generated by hypermail 2.3.0 : Tue May 17 2016 - 01:12:19 CEST