dmenu-fuzzyhighlight-caseinsensitive-4.9.diff (4647B)
1 From 2de2780bef245ae44d677abd20c589160f0d984b Mon Sep 17 00:00:00 2001 2 From: Oleh Kopeykin <olehkopeykin@yandex.by> 3 Date: Sun, 5 Feb 2023 01:15:35 +0300 4 Subject: [PATCH] Adds the fuzzyhighlight patch 5 6 --- 7 config.def.h | 2 ++ 8 dmenu.1 | 20 ++++++++++++++++++ 9 dmenu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++--- 10 3 files changed, 76 insertions(+), 3 deletions(-) 11 12 diff --git a/config.def.h b/config.def.h 13 index 51612b9..0103bda 100644 14 --- a/config.def.h 15 +++ b/config.def.h 16 @@ -12,6 +12,8 @@ static const char *colors[SchemeLast][2] = { 17 /* fg bg */ 18 [SchemeNorm] = { "#bbbbbb", "#222222" }, 19 [SchemeSel] = { "#eeeeee", "#005577" }, 20 + [SchemeSelHighlight] = { "#ffc978", "#005577" }, 21 + [SchemeNormHighlight] = { "#ffc978", "#222222" }, 22 [SchemeOut] = { "#000000", "#00ffff" }, 23 }; 24 /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ 25 diff --git a/dmenu.1 b/dmenu.1 26 index 323f93c..472b179 100644 27 --- a/dmenu.1 28 +++ b/dmenu.1 29 @@ -20,6 +20,14 @@ dmenu \- dynamic menu 30 .IR color ] 31 .RB [ \-sf 32 .IR color ] 33 +.RB [ \-nhb 34 +.IR color ] 35 +.RB [ \-nhf 36 +.IR color ] 37 +.RB [ \-shb 38 +.IR color ] 39 +.RB [ \-shf 40 +.IR color ] 41 .RB [ \-w 42 .IR windowid ] 43 .P 44 @@ -75,6 +83,18 @@ defines the selected background color. 45 .BI \-sf " color" 46 defines the selected foreground color. 47 .TP 48 +.BI \-nhb " color" 49 +defines the normal highlight background color. 50 +.TP 51 +.BI \-nhf " color" 52 +defines the normal highlight foreground color. 53 +.TP 54 +.BI \-shb " color" 55 +defines the selected highlight background color. 56 +.TP 57 +.BI \-shf " color" 58 +defines the selected highlight foreground color. 59 +.TP 60 .B \-v 61 prints version information to stdout, then exits. 62 .TP 63 diff --git a/dmenu.c b/dmenu.c 64 index 96ddc98..442d707 100644 65 --- a/dmenu.c 66 +++ b/dmenu.c 67 @@ -27,7 +27,9 @@ 68 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) 69 70 /* enums */ 71 -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ 72 +enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight, 73 + SchemeOut, SchemeLast }; /* color schemes */ 74 + 75 76 struct item { 77 char *text; 78 @@ -115,9 +117,47 @@ cistrstr(const char *s, const char *sub) 79 return NULL; 80 } 81 82 +static void 83 +drawhighlights(struct item *item, int x, int y, int maxw) 84 +{ 85 + int i, indent; 86 + char *highlight; 87 + char c; 88 + 89 + if (!(strlen(item->text) && strlen(text))) 90 + return; 91 + 92 + drw_setscheme(drw, scheme[item == sel 93 + ? SchemeSelHighlight 94 + : SchemeNormHighlight]); 95 + for (i = 0, highlight = item->text; *highlight && text[i];) { 96 + if (!fstrncmp(&text[i], highlight, 1)) { 97 + c = highlight[1]; 98 + highlight[1] = '\0'; 99 + 100 + /* get indentation */ 101 + indent = TEXTW(item->text); 102 + 103 + /* highlight character */ 104 + drw_text( 105 + drw, 106 + x + indent - lrpad, 107 + y, 108 + MIN(maxw - indent, TEXTW(highlight) - lrpad), 109 + bh, 0, highlight, 0 110 + ); 111 + highlight[1] = c; 112 + i++; 113 + } 114 + highlight++; 115 + } 116 +} 117 + 118 + 119 static int 120 drawitem(struct item *item, int x, int y, int w) 121 { 122 + int r; 123 if (item == sel) 124 drw_setscheme(drw, scheme[SchemeSel]); 125 else if (item->out) 126 @@ -125,7 +165,9 @@ drawitem(struct item *item, int x, int y, int w) 127 else 128 drw_setscheme(drw, scheme[SchemeNorm]); 129 130 - return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); 131 + r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); 132 + drawhighlights(item, x, y, w); 133 + return r; 134 } 135 136 static void 137 @@ -770,7 +812,8 @@ static void 138 usage(void) 139 { 140 fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" 141 - " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); 142 + " [-nb color] [-nf color] [-sb color] [-sf color]\n" 143 + " [-nhb color] [-nhf color] [-shb color] [-shf color] [-w windowid]\n", stderr); 144 exit(1); 145 } 146 147 @@ -813,6 +856,14 @@ main(int argc, char *argv[]) 148 colors[SchemeSel][ColBg] = argv[++i]; 149 else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ 150 colors[SchemeSel][ColFg] = argv[++i]; 151 + else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */ 152 + colors[SchemeNormHighlight][ColBg] = argv[++i]; 153 + else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */ 154 + colors[SchemeNormHighlight][ColFg] = argv[++i]; 155 + else if (!strcmp(argv[i], "-shb")) /* selected hi background color */ 156 + colors[SchemeSelHighlight][ColBg] = argv[++i]; 157 + else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */ 158 + colors[SchemeSelHighlight][ColFg] = argv[++i]; 159 else if (!strcmp(argv[i], "-w")) /* embedding window id */ 160 embed = argv[++i]; 161 else 162 -- 163 2.39.1 164