From dd72b1baf7541a0c9b04087ae8ca34b4cf9cfbf9 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 17 Oct 2009 03:10:37 -0400 Subject: [PATCH] Add -S flag to wimenu. --- cmd/menu/main.c | 12 ++++++++++-- cmd/menu/menu.c | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/menu/main.c b/cmd/menu/main.c index fcfc69e2..147585fc 100644 --- a/cmd/menu/main.c +++ b/cmd/menu/main.c @@ -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; diff --git a/cmd/menu/menu.c b/cmd/menu/menu.c index 05918e09..62500504 100644 --- a/cmd/menu/menu.c +++ b/cmd/menu/menu.c @@ -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;