From: Mike Lowis Date: Thu, 18 May 2023 20:44:31 +0000 (-0400) Subject: cleaned up code a bit and changed to right-most match X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8ff76ee4d776f6d1603f96fb66b625869f6989c2;p=proto%2Faos.git cleaned up code a bit and changed to right-most match --- diff --git a/bin/pick.c b/bin/pick.c index eadb09e..f710170 100644 --- a/bin/pick.c +++ b/bin/pick.c @@ -6,62 +6,14 @@ #include #include -enum { /* Color Names */ - Red, Purple, Orange, - EditBg, EditFg, EditSel, - TagsBg, TagsFg, TagsSel, - ScrollBg, ScrollFg, - VerBdr, HorBdr, Point, - ClrCount -}; - -/* List of font patterns available to the editor */ -static char* Fonts[2] = { - "Verdana:size=12", - "Liberation Mono:size=12" -}; - -int ScrollWidth = 8; /* width in pixels of the scrollbar */ - -static int Palette[ClrCount] = { -#if 0 /* Original Acme Colors */ - [EditBg] = 0xFFFFEA, /* Edit region background */ - [EditFg] = 0x000000, /* Edit region text */ - [EditSel] = 0xEEEE9E, /* Edit region selection */ - [TagsBg] = 0xEAFFFF, /* Tags region background */ - [TagsFg] = 0x000000, /* Tags region text */ - [TagsSel] = 0x9EEEEE, /* Tags region selection */ - [ScrollBg] = 0x99994C, /* Scroll region background */ - [ScrollFg] = 0xFFFFEA, /* Scroll region foreground */ - [VerBdr] = 0x99994C, /* Vertical border */ - [HorBdr] = 0x000000, /* Horizontal border */ - [Point] = 0xEFEFDA, /* Point background */ - [Purple] = 0x6666CC, /* Purple */ - [Red] = 0xCC0000, /* Red */ - [Orange] = 0xFF7700, /* Orange */ -#else - [EditBg] = 0xF5F5F0, /* Edit region background */ - [EditFg] = 0x222222, /* Edit region text */ - [EditSel] = 0xAACCEE, /* Edit region selection */ - - [TagsBg] = 0xF5F5F0, /* Tags region background */ - [TagsFg] = 0x222222, /* Tags region text */ - [TagsSel] = 0xAACCEE, /* Tags region selection */ - - [ScrollBg] = 0x959590, /* Scroll region background */ - [ScrollFg] = 0xF5F5F0, /* Scroll region foreground */ - - [VerBdr] = 0x959590, /* Vertical border */ - [HorBdr] = 0x222222, /* Horizontal border */ - - [Point] = 0xD5D5D0, /* Point background */ - [Purple] = 0x6666CC, /* Purple */ - [Red] = 0xCC0000, /* Red */ - [Orange] = 0xFF7700, /* Orange */ -#endif -}; - -#pragma GCC diagnostic pop +#define WindowBg 0xF5F5F0 +#define ChoiceBg 0xAACCEE +#define ChoiceFg 0x222222 +#define ScrollBg 0x959590 +#define ScrollFg 0xF5F5F0 +#define HorBdr 0x222222 +#define ScrollWidth 8 +#define Font "Verdana:size=12" static void xkeypress(XConf* x, XEvent* e); static void xbtnpress(XConf* x, XEvent* e); @@ -187,8 +139,8 @@ static bool match(char *string, size_t offset, size_t *start, size_t *end) return false; s2 = s1, e2 = e1; // Init s2 and e2 before use below - /* next find the longest match. If multiple, take the left most one */ - while (find_match(string, Query, ++offset, &s1, &e1) && ((e1-s1) <= (e2-s2))) + /* next find the longest match. If multiple, take the right most one */ + while (find_match(string, Query, ++offset, &s1, &e1) && ((e1-s1) >= (e2-s2))) s1 = s2, e1 = e2; /* return the best match */ @@ -246,6 +198,7 @@ static void xkeypress(XConf* x, XEvent* e) Xutf8LookupString(x->xic, &(e->xkey), buf, sizeof(buf), &key, &status); else XLookupString(&(e->xkey), buf, sizeof(buf), &key, 0); + if (key == XK_Return) { x->state = QUITTING; @@ -325,11 +278,11 @@ static void redraw(XConf* x) size_t start = (size_t)((float)Offset / (float)vec_size(&Choices) * scroll_height); size_t size = (size_t)((float)nlines / (float)vec_size(&Choices) * scroll_height); - x11_draw_rect(x, Palette[EditBg], 0, 0, x->width, x->height); - x11_draw_rect(x, Palette[TagsBg], 0, 0, x->width, fheight + 4); - x11_draw_rect(x, Palette[HorBdr], 0, fheight + 4, x->width, 1); - x11_draw_rect(x, Palette[ScrollBg], 0, fheight + 5, ScrollWidth+1, scroll_height); - x11_draw_rect(x, Palette[ScrollFg], 0, fheight + 5 + start, ScrollWidth, (size ? size : 5)); + x11_draw_rect(x, WindowBg, 0, 0, x->width, x->height); + x11_draw_rect(x, WindowBg, 0, 0, x->width, fheight + 4); + x11_draw_rect(x, HorBdr, 0, fheight + 4, x->width, 1); + x11_draw_rect(x, ScrollBg, 0, fheight + 5, ScrollWidth+1, scroll_height); + x11_draw_rect(x, ScrollFg, 0, fheight + 5 + start, ScrollWidth, (size ? size : 5)); /* get size of the query when printed */ XGlyphInfo glyphinfo; @@ -340,10 +293,10 @@ static void redraw(XConf* x) /* draw the query and the cursor to the query region */ int posx = 2 + glyphinfo.width + offset; - x11_draw_rect(x, Palette[TagsFg], posx-1, 2, 3, 3); - x11_draw_rect(x, Palette[TagsFg], posx, 2, 1, fheight); - x11_draw_rect(x, Palette[TagsFg], posx-1, 2+fheight-3, 3, 3); - x11_draw_string(x, x->font, offset + 2, fheight, Palette[TagsFg], Query); + x11_draw_rect(x, ChoiceFg, posx-1, 2, 3, 3); + x11_draw_rect(x, ChoiceFg, posx, 2, 1, fheight); + x11_draw_rect(x, ChoiceFg, posx-1, 2+fheight-3, 3, 3); + x11_draw_string(x, x->font, offset + 2, fheight, ChoiceFg, Query); /* draw the scored and sorted results */ if (vec_size(&Choices)) @@ -351,13 +304,13 @@ static void redraw(XConf* x) for (int i = Offset, y = 2 * fheight + 4; ((size_t)i < vec_size(&Choices)) && ((size_t)i <= Offset+nlines); i++, y += fheight) { if ((size_t)i == ChoiceIdx) - x11_draw_rect(x, Palette[EditSel], ScrollWidth+3, y - x->font->ascent, x->width, fheight); - x11_draw_string(x, x->font, ScrollWidth+3, y, Palette[TagsFg], ((Choice*)vec_at(&Choices, i))->string); + x11_draw_rect(x, ChoiceBg, ScrollWidth+3, y - x->font->ascent, x->width, fheight); + x11_draw_string(x, x->font, ScrollWidth+3, y, ChoiceFg, ((Choice*)vec_at(&Choices, i))->string); } } else { - x11_draw_string(x, x->font, ScrollWidth+3, 2 * fheight + 4, Palette[TagsFg], "Loading..."); + x11_draw_string(x, x->font, ScrollWidth+3, 2 * fheight + 4, ChoiceFg, "Loading..."); } x11_flip(x); } @@ -373,7 +326,7 @@ static void xinit(XConf* x) ); x11_init_gc(x); x11_centerwin(x); - if (!(x->font = x11_font_load(x, Fonts[0]))) + if (!(x->font = x11_font_load(x, Font))) { perror("unable to load base font"); exit(EXIT_FAILURE);