changeset: 2465:a1402b3de170
user: Kris Maglione <jg_AT_suckless.org>
date: Fri May 22 23:33:25 2009 -0400
files: alternative_wmiircs/python/pygmi/fs.py cmd/menu/caret.c cmd/menu/dat.h cmd/menu/fns.h cmd/menu/main.c cmd/menu/menu.c cmd/util.c include/util.h
description:
Fill in wimenu selections on <Tab>
diff -r a4b6e2f30117 -r a1402b3de170 alternative_wmiircs/python/pygmi/fs.py
--- a/alternative_wmiircs/python/pygmi/fs.py Fri May 22 16:56:01 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/fs.py Fri May 22 23:33:25 2009 -0400
@@ -111,7 +111,8 @@
def __set__(self, dir, val):
if not self.writable:
raise NotImplementedError('File %s is not writable' % self.name)
- return client.awrite('%s/%s' % (dir.path, self.name), val)
+ return client.awrite('%s/%s' % (dir.path, self.name),
+ str(val))
@property
def ctl_path(self):
@@ -524,6 +525,7 @@
NEXT = []
def __init__(self, normcol=None, focuscol=None):
+ self.ignore = set()
self.tags = {}
self.sel = None
self.normcol = normcol or wmii['normcolors']
@@ -555,7 +557,7 @@
self.tags[tag].button.label = urgent and '*' + tag or tag
def next(self, reverse=False):
- tags = list(wmii.tags)
+ tags = [t for t in wmii.tags if t.id not in self.ignore]
tags.append(tags[0])
if reverse:
tags.reverse()
@@ -566,7 +568,8 @@
def select(self, tag):
if tag is self.PREV:
- self.idx -= 1
+ if self.sel.id not in self.ignore:
+ self.idx -= 1
elif tag is self.NEXT:
self.idx += 1
else:
@@ -574,7 +577,7 @@
tag = tag.id
wmii['view'] = tag
- if tag != self.mru[-1]:
+ if tag != self.mru[-1] and tag not in self.ignore:
self.mru.append(tag)
self.mru = self.mru[-10:]
return
diff -r a4b6e2f30117 -r a1402b3de170 cmd/menu/caret.c
--- a/cmd/menu/caret.c Fri May 22 16:56:01 2009 -0400
+++ b/cmd/menu/caret.c Fri May 22 23:33:25 2009 -0400
@@ -31,6 +31,20 @@
return p;
i = chartorune(r, p);
return p + i;
+}
+
+void
+caret_set(int start, int end) {
+ int len;
+
+ len = input.end - input.string;
+ start = max(0, min(len, start));
+
+ input.pos = input.string + start;
+ if(end < 0)
+ input.pos_end = nil;
+ else
+ input.pos_end = input.string + max(start, end);
}
char*
@@ -79,12 +93,14 @@
return end;
}
}
+ input.pos_end = nil;
return input.pos;
}
void
caret_move(int dir, int type) {
input.pos = caret_find(dir, type);
+ input.pos_end = nil;
}
void
@@ -92,7 +108,10 @@
char *pos, *p;
int n;
- p = caret_find(dir, type);
+ if(input.pos_end)
+ p = input.pos_end;
+ else
+ p = caret_find(dir, type);
pos = input.pos;
if(p == input.end)
input.end = pos;
@@ -107,6 +126,7 @@
input.end = pos + n;
}
*input.end = '\0';
+ input.pos_end = nil;
}
void
@@ -118,7 +138,9 @@
if(clear) {
input.pos = input.string;
input.end = input.string;
- }
+ }else if(input.pos_end)
+ caret_delete(0, 0);
+
len = strlen(s);
pos = input.pos - input.string;
end = input.end - input.string;
@@ -137,5 +159,6 @@
memmove(input.pos + len, input.pos, end - pos);
memmove(input.pos, s, len);
input.pos += len;
+ input.pos_end = nil;
}
diff -r a4b6e2f30117 -r a1402b3de170 cmd/menu/dat.h
--- a/cmd/menu/dat.h Fri May 22 16:56:01 2009 -0400
+++ b/cmd/menu/dat.h Fri May 22 23:33:25 2009 -0400
@@ -62,8 +62,11 @@
char* string;
char* end;
char* pos;
- int len;
+ char* pos_end;
int size;
+
+ char* filter;
+ int filter_start;
} input;
extern char binding_spec[];
diff -r a4b6e2f30117 -r a1402b3de170 cmd/menu/fns.h
--- a/cmd/menu/fns.h Fri May 22 16:56:01 2009 -0400
+++ b/cmd/menu/fns.h Fri May 22 23:33:25 2009 -0400
@@ -1,22 +1,30 @@
+void check_x_event(IxpConn*);
+void dispatch_event(XEvent*);
+uint flushenterevents(void);
+uint flushevents(long, bool);
+void xtime_kludge(void);
+
+/* caret.c */
void caret_delete(int, int);
char* caret_find(int, int);
void caret_insert(char*, bool);
void caret_move(int, int);
-void check_x_event(IxpConn*);
-void debug(int, const char*, ...);
-void dispatch_event(XEvent*);
-Item* filter_list(Item*, char*);
-uint flushenterevents(void);
-uint flushevents(long, bool);
+void caret_set(int, int);
+
+/* history.c */
void history_dump(const char*, int);
char* history_search(int, char*, int);
-char* histtext(Item*);
+
+/* main.c */
+void debug(int, const char*, ...);
+Item* filter_list(Item*, char*);
void init_screens(int);
+void update_filter(void);
+
+/* menu.c */
void menu_init(void);
void menu_show(void);
-void xtime_kludge(void);
-void update_filter(void);
/* keys.c */
void parse_keys(char*);
diff -r a4b6e2f30117 -r a1402b3de170 cmd/menu/main.c
--- a/cmd/menu/main.c Fri May 22 16:56:01 2009 -0400
+++ b/cmd/menu/main.c Fri May 22 23:33:25 2009 -0400
@@ -122,10 +122,14 @@
void
update_filter(void) {
- /* TODO: Perhaps filter only previous matches unless filter
- * has been truncated.
- */
- matchfirst = matchstart = matchidx = filter_list(items, input.string);
+ char *filter;
+
+ filter = input.string + min(input.filter_start, input.pos - input.string);
+ if(input.pos < input.end)
+ filter = freelater(estrndup(filter, input.pos - filter));
+
+ matchidx = nil;
+ matchfirst = matchstart = filter_list(items, filter);
if(alwaysprint) {
write(1, input.string, input.pos - input.string);
write(1, "", 1);
diff -r a4b6e2f30117 -r a1402b3de170 cmd/menu/menu.c
--- a/cmd/menu/menu.c Fri May 22 16:56:01 2009 -0400
+++ b/cmd/menu/menu.c Fri May 22 23:33:25 2009 -0400
@@ -74,11 +74,9 @@
switch(op) {
case ACCEPT:
srv.running = false;
- if(matchidx->retstring && !motion)
- print("%s", matchidx->retstring);
- else
- print("%s", input.string);
-
+ if(!matchidx && matchfirst->retstring && !motion)
+ menu_cmd(CMPL_FIRST, 0);
+ print("%s", input.string);
break;
case REJECT:
srv.running = false;
@@ -89,14 +87,16 @@
caret_move(op, motion);
break;
case CMPL_NEXT:
- matchidx = matchidx->next;
+ matchidx = matchidx ? matchidx->next : matchfirst;
break;
case CMPL_PREV:
+ if(!matchidx)
+ matchidx = matchfirst;
matchidx = matchidx->prev;
break;
case CMPL_FIRST:
matchstart = matchfirst;
- matchidx = nil;
+ matchidx = matchstart;
matchend = nil;
break;
case CMPL_LAST:
@@ -109,6 +109,10 @@
matchend = matchstart->prev;
matchidx = nil;
break;
+ }
+ if(matchidx) {
+ caret_set(input.filter_start, input.pos - input.string);
+ caret_insert(matchidx->retstring, 0);
}
menu_draw();
}
@@ -160,9 +164,6 @@
}
}
- if(matchidx == nil)
- matchidx = matchstart;
-
r2 = rd;
for(i=matchstart; i->string; i=i->next) {
r2.min.x = promptw + itemoff;
@@ -185,6 +186,7 @@
drawstring(ibuf, font, r2, West, "<", cnorm.fg);
if(matchend->next != matchfirst)
drawstring(ibuf, font, r2, East, ">", cnorm.fg);
+
r2 = rd;
r2.max.x = promptw + inputw;
drawstring(ibuf, font, r2, West, input.string, cnorm.fg);
diff -r a4b6e2f30117 -r a1402b3de170 cmd/util.c
--- a/cmd/util.c Fri May 22 16:56:01 2009 -0400
+++ b/cmd/util.c Fri May 22 23:33:25 2009 -0400
@@ -151,13 +151,25 @@
return ret;
}
-char *
+char*
estrdup(const char *str) {
void *ret = strdup(str);
if(!ret)
mfatal("strdup", strlen(str));
return ret;
}
+
+char*
+estrndup(const char *str, uint len) {
+ char *ret;
+
+ len = min(len, strlen(str));
+ ret = emalloc(len + 1);
+ memcpy(ret, str, len);
+ ret[len] = '\0';
+ return ret;
+}
+
uint
tokenize(char *res[], uint reslen, char *str, char delim) {
diff -r a4b6e2f30117 -r a1402b3de170 include/util.h
--- a/include/util.h Fri May 22 16:56:01 2009 -0400
+++ b/include/util.h Fri May 22 23:33:25 2009 -0400
@@ -39,6 +39,7 @@
void* emallocz(uint);
void* erealloc(void*, uint);
char* estrdup(const char*);
+char* estrndup(const char*, uint);
void fatal(const char*, ...);
void* freelater(void*);
int max(int, int);
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:07 UTC