Skip to content

Commit 7c4f127

Browse files
committed
Apply fuzzy highlight patch
1 parent 18da4f7 commit 7c4f127

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

dmenu.1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ dmenu \- dynamic menu
2121
.IR color ]
2222
.RB [ \-sf
2323
.IR color ]
24+
.RB [ \-nhb
25+
.IR color ]
26+
.RB [ \-nhf
27+
.IR color ]
28+
.RB [ \-shb
29+
.IR color ]
30+
.RB [ \-shf
31+
.IR color ]
2432
.RB [ \-w
2533
.IR windowid ]
2634
.P
@@ -82,6 +90,18 @@ defines the selected background color.
8290
.BI \-sf " color"
8391
defines the selected foreground color.
8492
.TP
93+
.BI \-nhb " color"
94+
defines the normal highlight background color.
95+
.TP
96+
.BI \-nhf " color"
97+
defines the normal highlight foreground color.
98+
.TP
99+
.BI \-shb " color"
100+
defines the selected highlight background color.
101+
.TP
102+
.BI \-shf " color"
103+
defines the selected highlight foreground color.
104+
.TP
85105
.B \-v
86106
prints version information to stdout, then exits.
87107
.TP

dmenu.c

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
3030

3131
/* enums */
32-
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
32+
enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight,
33+
SchemeOut, SchemeLast }; /* color schemes */
34+
3335

3436
struct item {
3537
char *text;
@@ -118,17 +120,59 @@ cistrstr(const char *s, const char *sub)
118120
return NULL;
119121
}
120122

123+
static void
124+
drawhighlights(struct item *item, int x, int y, int maxw)
125+
{
126+
int i, indent;
127+
char *highlight;
128+
char c;
129+
130+
if (!(strlen(item->text) && strlen(text)))
131+
return;
132+
133+
drw_setscheme(drw, scheme[item == sel
134+
? SchemeSelHighlight
135+
: SchemeNormHighlight]);
136+
for (i = 0, highlight = item->text; *highlight && text[i];) {
137+
if (*highlight == text[i]) {
138+
/* get indentation */
139+
c = *highlight;
140+
*highlight = '\0';
141+
indent = TEXTW(item->text);
142+
*highlight = c;
143+
144+
/* highlight character */
145+
c = highlight[1];
146+
highlight[1] = '\0';
147+
drw_text(
148+
drw,
149+
x + indent - (lrpad / 2),
150+
y,
151+
MIN(maxw - indent, TEXTW(highlight) - lrpad),
152+
bh, 0, highlight, 0
153+
);
154+
highlight[1] = c;
155+
i++;
156+
}
157+
highlight++;
158+
}
159+
}
160+
161+
121162
static int
122163
drawitem(struct item *item, int x, int y, int w)
123164
{
165+
int r;
124166
if (item == sel)
125167
drw_setscheme(drw, scheme[SchemeSel]);
126168
else if (item->out)
127169
drw_setscheme(drw, scheme[SchemeOut]);
128170
else
129171
drw_setscheme(drw, scheme[SchemeNorm]);
130172

131-
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
173+
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
174+
drawhighlights(item, x, y, w);
175+
return r;
132176
}
133177

134178
static void
@@ -816,7 +860,8 @@ static void
816860
usage(void)
817861
{
818862
fputs("usage: dmenu [-bfiv] [-n|P] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
819-
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
863+
" [-nb color] [-nf color] [-sb color] [-sf color]\n"
864+
" [-nhb color] [-nhf color] [-shb color] [-shf color] [-w windowid]\n", stderr);
820865
exit(1);
821866
}
822867

@@ -863,6 +908,14 @@ main(int argc, char *argv[])
863908
colors[SchemeSel][ColBg] = argv[++i];
864909
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
865910
colors[SchemeSel][ColFg] = argv[++i];
911+
else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
912+
colors[SchemeNormHighlight][ColBg] = argv[++i];
913+
else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
914+
colors[SchemeNormHighlight][ColFg] = argv[++i];
915+
else if (!strcmp(argv[i], "-shb")) /* selected hi background color */
916+
colors[SchemeSelHighlight][ColBg] = argv[++i];
917+
else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
918+
colors[SchemeSelHighlight][ColFg] = argv[++i];
866919
else if (!strcmp(argv[i], "-w")) /* embedding window id */
867920
embed = argv[++i];
868921
else

0 commit comments

Comments
 (0)