Add -S flag to wimenu.

This commit is contained in:
Kris Maglione 2009-10-17 03:10:37 -04:00
parent 3fa8e4ec06
commit dd72b1baf7
2 changed files with 15 additions and 4 deletions

View File

@ -18,6 +18,7 @@ static const char version[] = "wimenu-"VERSION", "COPYRIGHT"\n";
static Biobuf* cmplbuf;
static Biobuf* inbuf;
static bool alwaysprint;
static char* cmdsep;
static void
usage(void) {
@ -78,9 +79,13 @@ populate_list(Biobuf *buf, bool hist) {
i = i->next;
i->string = p;
i->retstring = p;
if(cmdsep && (p = strstr(p, cmdsep))) {
*p = '\0';
i->retstring = p + strlen(cmdsep);
}
if(!hist) {
i->len = strlen(p);
i->width = textwidth_l(font, p, i->len);
i->len = strlen(i->string);
i->width = textwidth_l(font, i->string, i->len);
if(i->width > maxwidth)
maxwidth = i->width;
}
@ -257,6 +262,9 @@ main(int argc, char *argv[]) {
case 's':
screen = strtol(EARGF(usage()), nil, 10);
break;
case 'S':
cmdsep = EARGF(usage());
break;
case 'v':
print("%s", version);
return 0;

View File

@ -57,7 +57,7 @@ static void
selectitem(Item *i) {
if(i != matchidx) {
caret_set(input.filter_start, input.pos - input.string);
caret_insert(i->retstring, 0);
caret_insert(i->string, 0);
matchidx = i;
}
}
@ -86,7 +86,10 @@ next:
if(!matchidx && matchfirst->retstring && !motion)
if(input.filter_start == 0 && input.pos == input.end)
menu_cmd(CMPL_FIRST, 0);
print("%s", input.string);
if(!motion && matchidx && !strcmp(input.string, matchidx->string))
print("%s", matchidx->retstring);
else
print("%s", input.string);
break;
case REJECT:
srv.running = false;