commit 41dc478e3b277b1427f0a526b8c7adb0c46aad6d
parent 085a9846031c78c6c11d4f36870b7a8a25768784
Author: Kris Maglione <jg@suckless.org>
Date: Fri, 22 May 2009 23:58:56 -0400
Allow for programmable completion in wimenu.
Diffstat:
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/cmd/menu/fns.h b/cmd/menu/fns.h
@@ -23,6 +23,7 @@ void init_screens(int);
void update_filter(void);
/* menu.c */
+void menu_draw(void);
void menu_init(void);
void menu_show(void);
diff --git a/cmd/menu/main.c b/cmd/menu/main.c
@@ -15,6 +15,7 @@
#define link _link
static const char version[] = "wimenu-"VERSION", ©2009 Kris Maglione\n";
+static Biobuf* cmplbuf;
static Biobuf* inbuf;
static bool alwaysprint;
@@ -65,9 +66,13 @@ populate_list(Biobuf *buf, bool hist) {
Item ret;
Item *i;
char *p;
+ bool stop;
+ stop = !hist && !isatty(buf->fid);
i = &ret;
while((p = Brdstr(buf, '\n', true))) {
+ if(stop && p[0] == '\0')
+ break;
link(i, emallocz(sizeof *i));
i->next_link = i->next;
i = i->next;
@@ -86,6 +91,21 @@ populate_list(Biobuf *buf, bool hist) {
return ret.next != &ret ? ret.next : nil;
}
+static void
+check_competions(IxpConn *c) {
+ char *s;
+
+ s = Brdstr(cmplbuf, '\n', true);
+ if(!s) {
+ ixp_hangup(c);
+ return;
+ }
+ input.filter_start = strtol(s, nil, 10);
+ items = populate_list(cmplbuf, false);
+ update_filter();
+ menu_draw();
+}
+
Item*
filter_list(Item *i, char *filter) {
static Item exact;
@@ -271,8 +291,11 @@ main(int argc, char *argv[]) {
if(!font)
fatal("Can't load font %q", readctl("font "));
- inbuf = Bfdopen(0, OREAD);
- items = populate_list(inbuf, false);
+ cmplbuf = Bfdopen(0, OREAD);
+ items = populate_list(cmplbuf, false);
+ if(!isatty(cmplbuf->fid))
+ ixp_listen(&srv, cmplbuf->fid, inbuf, check_competions, nil);
+
caret_insert("", true);
update_filter();
@@ -284,7 +307,6 @@ main(int argc, char *argv[]) {
parse_keys(buffer);
}
- Bterm(inbuf);
histidx = &hist;
link(&hist, &hist);
if(histfile) {
diff --git a/cmd/menu/menu.c b/cmd/menu/menu.c
@@ -8,8 +8,6 @@ static Handlers handlers;
static int ltwidth;
-static void menu_draw(void);
-
enum {
ACCEPT = CARET_LAST,
REJECT,
@@ -117,7 +115,7 @@ next:
menu_draw();
}
-static void
+void
menu_draw(void) {
Rectangle r, rd, rp, r2;
CTuple *c;