changeset: 2466:0ab9741bbff2
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri May 22 23:58:56 2009 -0400
files: cmd/menu/fns.h cmd/menu/main.c cmd/menu/menu.c
description:
Allow for programmable completion in wimenu.
diff -r a1402b3de170 -r 0ab9741bbff2 cmd/menu/fns.h
--- a/cmd/menu/fns.h Fri May 22 23:33:25 2009 -0400
+++ b/cmd/menu/fns.h Fri May 22 23:58:56 2009 -0400
@@ -23,6 +23,7 @@
void update_filter(void);
/* menu.c */
+void menu_draw(void);
void menu_init(void);
void menu_show(void);
diff -r a1402b3de170 -r 0ab9741bbff2 cmd/menu/main.c
--- a/cmd/menu/main.c Fri May 22 23:33:25 2009 -0400
+++ b/cmd/menu/main.c Fri May 22 23:58:56 2009 -0400
@@ -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 @@
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;
@@ -84,6 +89,21 @@
link(i, &ret);
splice(&ret);
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*
@@ -271,8 +291,11 @@
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 @@
parse_keys(buffer);
}
- Bterm(inbuf);
histidx = &hist;
link(&hist, &hist);
if(histfile) {
diff -r a1402b3de170 -r 0ab9741bbff2 cmd/menu/menu.c
--- a/cmd/menu/menu.c Fri May 22 23:33:25 2009 -0400
+++ b/cmd/menu/menu.c Fri May 22 23:58:56 2009 -0400
@@ -7,8 +7,6 @@
static Handlers handlers;
static int ltwidth;
-
-static void menu_draw(void);
enum {
ACCEPT = CARET_LAST,
@@ -117,7 +115,7 @@
menu_draw();
}
-static void
+void
menu_draw(void) {
Rectangle r, rd, rp, r2;
CTuple *c;
Received on Sat May 23 2009 - 03:58:58 UTC
This archive was generated by hypermail 2.2.0 : Sat May 23 2009 - 04:00:08 UTC