ref: 1fd26030655c541e7c78d4e0db64ed6725d7cc73
parent: ffc34e1ca04664f0bc4dfe40522190b0d33cc2f0
author: glenda <[email protected]>
date: Mon Sep 27 12:46:40 EDT 2021
add a -p flag to choose the prompt
--- a/dmenu.c
+++ b/dmenu.c
@@ -6,7 +6,6 @@
#include <keyboard.h>
#define Ctl(c) ((c) - 64)
-#define PROMPT " > "
enum
{
@@ -19,8 +18,9 @@
Image *color[NCOLORS];
char **lines, **matches, *buffer;
+char prompt[64] = " > ";
usize nlines, nmatches, scroll;
-Rune kbinput[512];
+Rune kinput[512];
int selected;
static void
@@ -96,7 +96,7 @@
Point pt;
char buf[512];
- snprint(buf, sizeof buf, PROMPT"%S▏", kbinput);
+ snprint(buf, sizeof buf, "%s%S▏", prompt, kinput);
pt = Pt(screen->r.max.x, screen->r.min.y + font->height * 2);
draw(screen, Rpt(screen->r.min, pt), color[BACK], nil, ZP);
pt = Pt(screen->r.min.x, screen->r.min.y + font->height);
@@ -118,7 +118,7 @@
bgcolor = color[BACK];
txcolor = color[TEXT];
}
- pt.x += stringwidth(font, PROMPT);
+ pt.x += stringwidth(font, prompt);
drawbackground(pt, bgcolor);
if(ln < nmatches)
tabstring(screen, pt, txcolor, ZP, font, matches[ln]);
@@ -156,7 +156,7 @@
char *buf, *words[64], **l, **m;
int nwords, old;
- if((buf = smprint("%S", kbinput)) == nil)
+ if((buf = smprint("%S", kinput)) == nil)
sysfatal("malloc");
nwords = tokenize(buf, words, sizeof words / sizeof *words);
@@ -179,14 +179,14 @@
}
static void
-kbadd(Rune r)
+kadd(Rune r)
{
- int len = runestrlen(kbinput);
+ int len = runestrlen(kinput);
- if(len == sizeof kbinput / sizeof *kbinput)
+ if(len == sizeof kinput / sizeof *kinput)
return;
- kbinput[len++] = r;
- kbinput[len] = L'\0';
+ kinput[len++] = r;
+ kinput[len] = L'\0';
filter(matches, nmatches);
}
@@ -194,11 +194,11 @@
static void
kbbackspace(void)
{
- usize len = runestrlen(kbinput);
+ usize len = runestrlen(kinput);
if(len == 0)
return;
- kbinput[len - 1] = L'\0';
+ kinput[len - 1] = L'\0';
filter(lines, nlines);
}
@@ -206,15 +206,15 @@
static void
kbdelword(void)
{
- usize len = runestrlen(kbinput);
+ usize len = runestrlen(kinput);
if(len == 0)
return;
- while(len > 0 && isspacerune(kbinput[len-1]))
+ while(len > 0 && isspacerune(kinput[len-1]))
len--;
- while(len > 0 && !isspacerune(kbinput[len-1]))
+ while(len > 0 && !isspacerune(kinput[len-1]))
len--;
- kbinput[len] = L'\0';
+ kinput[len] = L'\0';
filter(lines, nlines);
}
@@ -222,7 +222,7 @@
static void
kbclear(void)
{
- kbinput[0] = L'\0';
+ kinput[0] = L'\0';
filter(lines, nlines);
}
@@ -278,7 +278,7 @@
static void
usage(void)
{
- print("usage: %s [-b] <choices\n", argv0);
+ print("usage: %s [-b] [-p prompt] <choices\n", argv0);
exits("usage");
}
@@ -288,13 +288,16 @@
Event e;
int bflag = 0;
- ARGBEGIN{
+ ARGBEGIN {
case 'b':
bflag = 1;
break;
+ case 'p':
+ snprint(prompt, sizeof prompt, " %s> ", EARGF(usage()));
+ break;
default:
usage();
- }ARGEND;
+ } ARGEND;
readbuffer();
@@ -350,7 +353,7 @@
kbscroll(-40);
break;
default:
- kbadd(e.kbdc);
+ kadd(e.kbdc);
break;
}
break;
@@ -372,3 +375,4 @@
print("%s\n", matches[selected]);
exits(nil);
}
+
--- a/dmenu.man
+++ b/dmenu.man
@@ -7,6 +7,8 @@
.B menu
[
.B -d
+] [
+.B -p prompt
]
.B <choices
.
@@ -19,6 +21,9 @@
Once selection is made, dmenu print the selected line to standard
output and exits.
.PP
+The prompt can be changed with the -p flag, and -b set a black
+background instead of white.
+.PP
Along with Ctl+U, Ctl+W, Backspace, Del, LeftClic, MouseWheel,
extra controls are provided:
.TF "Enter / RightClic"
@@ -62,6 +67,13 @@
.RS
.EX
auth/secstore -G pass | dmenu | sed 's/.* pass=//' >/dev/snarf
+.EE
+.RE
+.PP
+Prompt for a file to plumb to the text editor with B:
+.RS
+.EX
+B `{walk -f $1 | dmenu -b}
.EE
.RE
.