commit e56bec5106f40a37080bb9d2aa75c17298461812
parent f8394ead0e20e16a37fcb0d427914b4a048f48d5
Author: Justinas Grigas <dev@jstnas.com>
Date: Mon, 17 Jun 2024 04:32:45 +0100
dmenu(fuzzyhighlight): update to 5.3
Diffstat:
3 files changed, 182 insertions(+), 23 deletions(-)
diff --git a/tools.suckless.org/dmenu/patches/fuzzyhighlight/dmenu-fuzzyhighlight-5.3.diff b/tools.suckless.org/dmenu/patches/fuzzyhighlight/dmenu-fuzzyhighlight-5.3.diff
@@ -0,0 +1,165 @@
+From dd0327d33a3c5269ed128e0903787365625bd507 Mon Sep 17 00:00:00 2001
+From: Justinas Grigas <dev@jstnas.com>
+Date: Sun, 16 Jun 2024 00:38:53 +0100
+Subject: [PATCH] fuzzyhighlight: highlight fuzzy matches
+
+This patch actually fixes the highlighted character offset
+---
+ config.def.h | 2 ++
+ dmenu.1 | 20 ++++++++++++++++++
+ dmenu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++---
+ 3 files changed, 76 insertions(+), 3 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.1 b/dmenu.1
+index 323f93c..472b179 100644
+--- a/dmenu.1
++++ b/dmenu.1
+@@ -20,6 +20,14 @@ dmenu \- dynamic menu
+ .IR color ]
+ .RB [ \-sf
+ .IR color ]
++.RB [ \-nhb
++.IR color ]
++.RB [ \-nhf
++.IR color ]
++.RB [ \-shb
++.IR color ]
++.RB [ \-shf
++.IR color ]
+ .RB [ \-w
+ .IR windowid ]
+ .P
+@@ -75,6 +83,18 @@ defines the selected background color.
+ .BI \-sf " color"
+ defines the selected foreground color.
+ .TP
++.BI \-nhb " color"
++defines the normal highlight background color.
++.TP
++.BI \-nhf " color"
++defines the normal highlight foreground color.
++.TP
++.BI \-shb " color"
++defines the selected highlight background color.
++.TP
++.BI \-shf " color"
++defines the selected highlight foreground color.
++.TP
+ .B \-v
+ prints version information to stdout, then exits.
+ .TP
+diff --git a/dmenu.c b/dmenu.c
+index 40f93e0..662131a 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -25,7 +25,9 @@
+ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+
+ /* enums */
+-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
++enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight,
++ SchemeOut, SchemeLast }; /* color schemes */
++
+
+ struct item {
+ char *text;
+@@ -129,9 +131,47 @@ cistrstr(const char *h, const char *n)
+ return NULL;
+ }
+
++static void
++drawhighlights(struct item *item, int x, int y, int maxw)
++{
++ int i, indent;
++ char c, *highlight;
++
++ if (!(strlen(item->text) && strlen(text)))
++ return;
++
++ drw_setscheme(drw, scheme[item == sel
++ ? SchemeSelHighlight
++ : SchemeNormHighlight]);
++ for (i = 0, highlight = item->text; *highlight && text[i];) {
++ if (!fstrncmp(highlight, &text[i], 1)) {
++ /* get indentation */
++ c = *highlight;
++ *highlight = '\0';
++ indent = TEXTW(item->text);
++ *highlight = c;
++
++ /* highlight character */
++ c = highlight[1];
++ highlight[1] = '\0';
++ drw_text(
++ drw,
++ x + indent - (lrpad / 2.),
++ y,
++ MIN(maxw - indent, TEXTW(highlight) - lrpad),
++ bh, 0, highlight, 0
++ );
++ highlight[1] = c;
++ ++i;
++ }
++ ++highlight;
++ }
++}
++
+ static int
+ drawitem(struct item *item, int x, int y, int w)
+ {
++ int r;
+ if (item == sel)
+ drw_setscheme(drw, scheme[SchemeSel]);
+ else if (item->out)
+@@ -139,7 +179,9 @@ drawitem(struct item *item, int x, int y, int w)
+ else
+ drw_setscheme(drw, scheme[SchemeNorm]);
+
+- return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
++ r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
++ drawhighlights(item, x, y, w);
++ return r;
+ }
+
+ static void
+@@ -716,7 +758,8 @@ static void
+ usage(void)
+ {
+ die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
++ " [-nb color] [-nf color] [-sb color] [-sf color]\n"
++ " [-nhb color] [-nhf color] [-shb color] [-shf color] [-w windowid]");
+ }
+
+ int
+@@ -756,6 +799,14 @@ main(int argc, char *argv[])
+ colors[SchemeSel][ColBg] = argv[++i];
+ else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
+ colors[SchemeSel][ColFg] = argv[++i];
++ else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
++ colors[SchemeNormHighlight][ColBg] = argv[++i];
++ else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
++ colors[SchemeNormHighlight][ColFg] = argv[++i];
++ else if (!strcmp(argv[i], "-shb")) /* selected hi background color */
++ colors[SchemeSelHighlight][ColBg] = argv[++i];
++ else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
++ colors[SchemeSelHighlight][ColFg] = argv[++i];
+ else if (!strcmp(argv[i], "-w")) /* embedding window id */
+ embed = argv[++i];
+ else
+--
+2.45.2
+
diff --git a/tools.suckless.org/dmenu/patches/fuzzyhighlight/fuzzyhighlight.png b/tools.suckless.org/dmenu/patches/fuzzyhighlight/fuzzyhighlight.png
Binary files differ.
diff --git a/tools.suckless.org/dmenu/patches/fuzzyhighlight/index.md b/tools.suckless.org/dmenu/patches/fuzzyhighlight/index.md
@@ -1,32 +1,26 @@
-fuzzyhighlight
-==============
+# fuzzyhighlight
-Description
------------
-This patch make it so that fuzzy matches gets highlighted and is therefore
-meant to be used together with the patch fuzzymatch.
+## Description
-To make this patch fully integrated with fuzzymatch and support 'case
-insensitive' features the following line must be changed:
+Make dmenu highlight the fuzzy matching characters of items. Best used alongside
+the [fuzzymatch](https://tools.suckless.org/dmenu/patches/fuzzymatch/) patch.
- if (*highlight == text[i]) {
+![Screenshot of fuzzyhighlight and fuzzymatch patches applied](fuzzyhighlight.png)
-into:
+## Notes
- if (!fstrncmp(&(*highlight), &text[i], 1)) {
+- Supports case insensitive mode.
+- Works without fuzzy matching (as a more flexible / expensive alternative to
+ the [highlight](https://tools.suckless.org/dmenu/patches/highlight/) patch).
-[![Screenshot dmenu with the patch](fuzzyhighlight.png)](fuzzyhighlight.png)
+## Download
-Download
---------
-* [dmenu-fuzzyhighlight-4.9.diff](dmenu-fuzzyhighlight-4.9.diff)
+- [dmenu-fuzzyhighlight-4.9.diff](dmenu-fuzzyhighlight-4.9.diff)
+- [dmenu-fuzzyhighlight-caseinsensitive-4.9.diff](dmenu-fuzzyhighlight-caseinsensitive-4.9.diff)
+- [dmenu-fuzzyhighlight-5.3.diff](./dmenu-fuzzyhighlight-5.3.diff)
-This patch fixes the shift of highlighted symbols, it also supports case-insensitive
-item matching behavior.
+## Authors
-* [dmenu-fuzzyhighlight-caseinsensitive-4.9.diff](dmenu-fuzzyhighlight-caseinsensitive-4.9.diff)
-
-Authors
--------
-* Chris Noxz - <chris@noxz.tech>
-* Oleh Kopeykin - <olehkopeykin@yandex.by> (case-insensitive)
+- Chris Noxz - <chris@noxz.tech>
+- Oleh Kopeykin - <olehkopeykin@yandex.by> (case-insensitive)
+- Justinas Grigas <dev@jstnas.com> (5.3)