sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit f4218d68f4c9e328639c3a4cf634cf73104b30d9
parent 30ec7e6550d5826232b0a35fdf5e6cfe9aebfffa
Author: Miles Alan <m@milesalan.com>
Date:   Tue, 14 Jan 2020 22:36:03 -0600

[dmenu][patch] highlight: Add dmenu highlight patch

Diffstat:
Atools.suckless.org/dmenu/patches/highlight/dmenu-highlight-4.9.diff | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/highlight/dmenu-highlight.png | 0
Atools.suckless.org/dmenu/patches/highlight/index.md | 14++++++++++++++
3 files changed, 130 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/highlight/dmenu-highlight-4.9.diff b/tools.suckless.org/dmenu/patches/highlight/dmenu-highlight-4.9.diff @@ -0,0 +1,116 @@ +From 14e68d5d546830714e37e99667a455162dcd0e04 Mon Sep 17 00:00:00 2001 +From: Miles Alan <m@milesalan.com> +Date: Tue, 14 Jan 2020 21:50:04 -0600 +Subject: [PATCH] Highlight matched text in a different color scheme + +--- + config.def.h | 2 ++ + dmenu.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- + 2 files changed, 48 insertions(+), 4 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 1edb647..64eab2a 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -11,6 +11,8 @@ static const char *colors[SchemeLast][2] = { + /* fg bg */ + [SchemeNorm] = { "#bbbbbb", "#222222" }, + [SchemeSel] = { "#eeeeee", "#005577" }, ++ [SchemeSelHighlight] = { "#ffc978", "#005577" }, ++ [SchemeNormHighlight] = { "#ffc978", "#222222" }, + [SchemeOut] = { "#000000", "#00ffff" }, + }; + /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ +diff --git a/dmenu.c b/dmenu.c +index 6b8f51b..84c902b 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -26,7 +26,7 @@ + #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) + + /* enums */ +-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ ++enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeLast }; /* color schemes */ + + struct item { + char *text; +@@ -113,6 +113,42 @@ cistrstr(const char *s, const char *sub) + return NULL; + } + ++static void ++drawhighlights(struct item *item, int x, int y, int maxw) ++{ ++ char restorechar, tokens[sizeof text], *highlight, *token; ++ int indentx, highlightlen; ++ ++ drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]); ++ strcpy(tokens, text); ++ for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) { ++ highlight = fstrstr(item->text, token); ++ while (highlight) { ++ // Move item str end, calc width for highlight indent, & restore ++ highlightlen = highlight - item->text; ++ restorechar = *highlight; ++ item->text[highlightlen] = '\0'; ++ indentx = TEXTW(item->text); ++ item->text[highlightlen] = restorechar; ++ ++ // Move highlight str end, draw highlight, & restore ++ restorechar = highlight[strlen(token)]; ++ highlight[strlen(token)] = '\0'; ++ drw_text( ++ drw, ++ x + indentx - (lrpad / 2) - 1, ++ y, ++ MIN(maxw - indentx, TEXTW(highlight) - lrpad), ++ bh, 0, highlight, 0 ++ ); ++ highlight[strlen(token)] = restorechar; ++ ++ if (strlen(highlight) - strlen(token) < strlen(token)) break; ++ highlight = fstrstr(highlight + strlen(token), token); ++ } ++ } ++} ++ + static int + drawitem(struct item *item, int x, int y, int w) + { +@@ -132,6 +168,7 @@ drawmenu(void) + unsigned int curpos; + struct item *item; + int x = 0, y = 0, w; ++ int savedx; + + drw_setscheme(drw, scheme[SchemeNorm]); + drw_rect(drw, 0, 0, mw, mh, 1, 1); +@@ -153,8 +190,10 @@ drawmenu(void) + + if (lines > 0) { + /* draw vertical list */ +- for (item = curr; item != next; item = item->right) ++ for (item = curr; item != next; item = item->right) { + drawitem(item, x, y += bh, mw - x); ++ drawhighlights(item, x, y, mw - x); ++ } + } else if (matches) { + /* draw horizontal list */ + x += inputw; +@@ -164,8 +203,11 @@ drawmenu(void) + drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0); + } + x += w; +- for (item = curr; item != next; item = item->right) +- x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">"))); ++ for (item = curr; item != next; item = item->right) { ++ savedx = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">"))); ++ drawhighlights(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">"))); ++ x = savedx; ++ } + if (next) { + w = TEXTW(">"); + drw_setscheme(drw, scheme[SchemeNorm]); +-- +2.23.1 + diff --git a/tools.suckless.org/dmenu/patches/highlight/dmenu-highlight.png b/tools.suckless.org/dmenu/patches/highlight/dmenu-highlight.png Binary files differ. diff --git a/tools.suckless.org/dmenu/patches/highlight/index.md b/tools.suckless.org/dmenu/patches/highlight/index.md @@ -0,0 +1,14 @@ +highlight +========= +This patch highlights the individual characters of matched text for each +dmenu list entry. + +[![Screenshot dmenu with highlight patch](dmenu-highlight.png)](dmenu-highlight.png) + +Download +-------- +* [dmenu-highlight-4.9.diff](dmenu-highlight-4.9.diff) + +Author +------ +* Miles Alan <m@milesalan.com>