[wiki] [sites] [dmenu][patch] highlight: Add dmenu highlight patch || Miles Alan

From: <git_AT_suckless.org>
Date: Wed, 15 Jan 2020 05:39:17 +0100

commit f4218d68f4c9e328639c3a4cf634cf73104b30d9
Author: Miles Alan <m_AT_milesalan.com>
Date: Tue Jan 14 22:36:03 2020 -0600

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

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
new file mode 100644
index 00000000..9b01fae3
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/highlight/dmenu-highlight-4.9.diff
_AT_@ -0,0 +1,116 @@
+From 14e68d5d546830714e37e99667a455162dcd0e04 Mon Sep 17 00:00:00 2001
+From: Miles Alan <m_AT_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
+_AT_@ -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
+_AT_@ -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;
+_AT_@ -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] = '++ indentx = TEXTW(item->text);
++ item->text[highlightlen] = restorechar;
++
++ // Move highlight str end, draw highlight, & restore
++ restorechar = highlight[strlen(token)];
++ highlight[strlen(token)] = '++ 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)
+ {
+_AT_@ -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);
+_AT_@ -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;
+_AT_@ -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
new file mode 100644
index 00000000..20804b0d
Binary files /dev/null and b/tools.suckless.org/dmenu/patches/highlight/dmenu-highlight.png differ
diff --git a/tools.suckless.org/dmenu/patches/highlight/index.md b/tools.suckless.org/dmenu/patches/highlight/index.md
new file mode 100644
index 00000000..0c3fbfed
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/highlight/index.md
_AT_@ -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_AT_milesalan.com>
Received on Wed Jan 15 2020 - 05:39:17 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 15 2020 - 05:48:33 CET