Fill in wimenu selections on <Tab>

This commit is contained in:
Kris Maglione 2009-05-22 23:33:25 -04:00
parent 0c8af0739b
commit 085a984603
8 changed files with 87 additions and 31 deletions

View File

@ -111,7 +111,8 @@ class Dir(Ctl):
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 @@ class Tags(object):
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 @@ class Tags(object):
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 @@ class Tags(object):
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 @@ class Tags(object):
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

View File

@ -33,6 +33,20 @@ next_rune(char *p, Rune *r) {
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*
caret_find(int dir, int type) {
char *end;
@ -79,12 +93,14 @@ caret_find(int dir, int type) {
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 @@ caret_delete(int dir, int type) {
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 @@ caret_delete(int dir, int type) {
input.end = pos + n;
}
*input.end = '\0';
input.pos_end = nil;
}
void
@ -118,7 +138,9 @@ caret_insert(char *s, bool clear) {
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 @@ caret_insert(char *s, bool clear) {
memmove(input.pos + len, input.pos, end - pos);
memmove(input.pos, s, len);
input.pos += len;
input.pos_end = nil;
}

View File

@ -62,8 +62,11 @@ EXTERN struct {
char* string;
char* end;
char* pos;
int len;
char* pos_end;
int size;
char* filter;
int filter_start;
} input;
extern char binding_spec[];

View File

@ -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*);

View File

@ -122,10 +122,14 @@ filter_list(Item *i, char *filter) {
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);

View File

@ -74,11 +74,9 @@ next:
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 @@ next:
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:
@ -110,6 +110,10 @@ next:
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 @@ menu_draw(void) {
}
}
if(matchidx == nil)
matchidx = matchstart;
r2 = rd;
for(i=matchstart; i->string; i=i->next) {
r2.min.x = promptw + itemoff;
@ -185,6 +186,7 @@ menu_draw(void) {
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);

View File

@ -151,7 +151,7 @@ erealloc(void *ptr, uint size) {
return ret;
}
char *
char*
estrdup(const char *str) {
void *ret = strdup(str);
if(!ret)
@ -159,6 +159,18 @@ estrdup(const char *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) {
char *s;

View File

@ -39,6 +39,7 @@ void* emalloc(uint);
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);