Re: [wmii] [PATCH] add wimenu prompt support

From: Bart Trojanowski <bart_AT_jukie.net>
Date: Sun, 29 Mar 2009 21:42:23 -0400

sorry, I forgot to include 1 file. I'll repost.

* Bart Trojanowski <bart_AT_jukie.net> [090329 21:38]:
> This patch adds wimenu -p option that prepends an optional prompt box at
> the left of the input area. Here is an example:
>
> seq 1 100 | wimenu -p 'What number am I thinking of?'
>
> -Bart
>
> ---
> cmd/menu/main.c | 7 ++++++-
> cmd/menu/menu.c | 38 ++++++++++++++++++++++++++------------
> 2 files changed, 32 insertions(+), 13 deletions(-)
>
> diff --git a/cmd/menu/main.c b/cmd/menu/main.c
> index 26d8bf0..0ff4271 100644
> --- a/cmd/menu/main.c
> +++ b/cmd/menu/main.c
> @@ -21,7 +21,7 @@ static char* ectl;
>
> static void
> usage(void) {
> - fatal("usage: wimenu -i [-h <history>] [-a <address>]\n");
> + fatal("usage: wimenu -i [-h <history>] [-a <address>] [-p <prompt>]\n");
> }
>
> static int
> @@ -214,6 +214,8 @@ main(int argc, char *argv[]) {
> fmtinstall('r', errfmt);
> address = getenv("WMII_ADDRESS");
> histfile = nil;
> + prompt = nil;
> + promptw = 0;
>
> find = strstr;
> compare = strncmp;
> @@ -230,6 +232,9 @@ main(int argc, char *argv[]) {
> case 'n':
> ndump = strtol(EARGF(usage()), nil, 10);
> break;
> + case 'p':
> + prompt = EARGF(usage());
> + break;
> case 'i':
> find = strcasestr;
> compare = strncasecmp;
> diff --git a/cmd/menu/menu.c b/cmd/menu/menu.c
> index 6f726c3..56ec004 100644
> --- a/cmd/menu/menu.c
> +++ b/cmd/menu/menu.c
> @@ -117,20 +117,30 @@ next:
>
> static void
> menu_draw(void) {
> - Rectangle r, r2;
> + Rectangle r, rd, rp, r2;
> CTuple *c;
> Item *i;
> int inputw, itemoff, end, pad, n;
>
> r = barwin->r;
> r = rectsetorigin(r, ZP);
> - r2 = r;
>
> pad = (font->height & ~1);
> - inputw = min(Dx(r) / 3, maxwidth);
> +
> + rd = r;
> + if (prompt) {
> + if (!promptw)
> + promptw = textwidth(font, prompt) + 2 * ltwidth;
> + rd.min.x += promptw;
> +
> + rp = r;
> + rp.max.x = promptw;
> + }
> +
> + inputw = min(Dx(rd) / 3, maxwidth);
> inputw = max(inputw, textwidth(font, input.string)) + pad;
> itemoff = inputw + 2 * ltwidth;
> - end = Dx(r) - ltwidth;
> + end = Dx(rd) - ltwidth;
>
> fill(ibuf, r, cnorm.bg);
>
> @@ -155,10 +165,11 @@ menu_draw(void) {
> if(matchidx == nil)
> matchidx = matchstart;
>
> + r2 = rd;
> for(i=matchstart; i->string; i=i->next) {
> - r2.min.x = itemoff;
> + r2.min.x = promptw + itemoff;
> itemoff = itemoff + i->width + pad;
> - r2.max.x = min(itemoff, end);
> + r2.max.x = promptw + min(itemoff, end);
> if(i != matchstart && itemoff > end)
> break;
>
> @@ -170,23 +181,26 @@ menu_draw(void) {
> break;
> }
>
> - r2 = r;
> - r2.min.x = inputw;
> + r2 = rd;
> + r2.min.x = promptw + inputw;
> if(matchstart != matchfirst)
> drawstring(ibuf, font, r2, West, "<", cnorm.fg);
> if(matchend->next != matchfirst)
> drawstring(ibuf, font, r2, East, ">", cnorm.fg);
> - r2 = r;
> - r2.max.x = inputw;
> + r2 = rd;
> + r2.max.x = promptw + inputw;
> drawstring(ibuf, font, r2, West, input.string, cnorm.fg);
>
> - r2.min.x = textwidth_l(font, input.string, input.pos - input.string) + pad/2 - 1;
> + r2.min.x = promptw + textwidth_l(font, input.string, input.pos - input.string) + pad/2 - 1;
> r2.max.x = r2.min.x + 2;
> r2.min.y++;
> r2.max.y--;
> border(ibuf, r2, 1, cnorm.border);
>
> - border(ibuf, r, 1, cnorm.border);
> + if (prompt)
> + drawstring(ibuf, font, rp, West, prompt, cnorm.fg);
> +
> + border(ibuf, rd, 1, cnorm.border);
> copyimage(barwin, r, ibuf, ZP);
> }
>
> --
> 1.6.2.rc2.17.gcdd2484
>

-- 
				WebSig: http://www.jukie.net/~bart/sig/
Received on Mon Mar 30 2009 - 01:42:23 UTC

This archive was generated by hypermail 2.2.0 : Mon Mar 30 2009 - 01:48:08 UTC