mirror of
https://github.com/mintycube/dmenu.git
synced 2024-10-22 12:05:48 +00:00
Adding fuzzyhighlight patch
This commit is contained in:
parent
415fa6ccad
commit
fcfde08faf
@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
|
||||
|
||||
### Changelog:
|
||||
|
||||
2020-04-05 - Added fuzzyhighlight patch
|
||||
|
||||
2020-02-09 - Added revised border patch (adding command line parameter for setting border width)
|
||||
|
||||
2019-12-29 - Added xresources patch
|
||||
@ -31,6 +33,9 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
|
||||
- [center](https://tools.suckless.org/dmenu/patches/center/)
|
||||
- this patch centers dmenu in the middle of the screen
|
||||
|
||||
- [fuzzyhighlight](https://tools.suckless.org/dmenu/patches/fuzzyhighlight/)
|
||||
- intended to be combined with the fuzzymatch patch, this makes it so that fuzzy matches are highlighted
|
||||
|
||||
- [fuzzymatch](https://tools.suckless.org/dmenu/patches/fuzzymatch/)
|
||||
- adds support for fuzzy-matching to dmenu, allowing users to type non-consecutive portions of the string to be matched
|
||||
|
||||
|
@ -35,6 +35,10 @@ static const char *colors[][2] =
|
||||
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
[SchemeSelHighlight] = { "#ffc978", "#005577" },
|
||||
[SchemeNormHighlight] = { "#ffc978", "#222222" },
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
};
|
||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
static unsigned int lines = 0;
|
||||
|
33
dmenu.c
33
dmenu.c
@ -27,7 +27,16 @@
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
|
||||
/* enums */
|
||||
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
|
||||
enum {
|
||||
SchemeNorm,
|
||||
SchemeSel,
|
||||
SchemeOut,
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
SchemeNormHighlight,
|
||||
SchemeSelHighlight,
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
SchemeLast,
|
||||
}; /* color schemes */
|
||||
|
||||
struct item {
|
||||
char *text;
|
||||
@ -165,6 +174,9 @@ cistrstr(const char *s, const char *sub)
|
||||
static int
|
||||
drawitem(struct item *item, int x, int y, int w)
|
||||
{
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
int r;
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
if (item == sel)
|
||||
drw_setscheme(drw, scheme[SchemeSel]);
|
||||
else if (item->out)
|
||||
@ -172,7 +184,13 @@ drawitem(struct item *item, int x, int y, int w)
|
||||
else
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
drawhighlights(item, x, y, w);
|
||||
return r;
|
||||
#else
|
||||
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1078,6 +1096,9 @@ usage(void)
|
||||
#if XYW_PATCH
|
||||
" [-X xoffset] [-Y yoffset] [-W width]" // (arguments made upper case due to conflicts)
|
||||
#endif // XYW_PATCH
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
"\n [-nhb color] [-nhf color] [-shb color] [-shf color]" // highlight colors
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
"\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
@ -1174,6 +1195,16 @@ main(int argc, char *argv[])
|
||||
colors[SchemeSel][ColBg] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
|
||||
colors[SchemeSel][ColFg] = argv[++i];
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
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];
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
||||
embed = argv[++i];
|
||||
#if BORDER_PATCH
|
||||
|
37
patch/fuzzyhighlight.c
Normal file
37
patch/fuzzyhighlight.c
Normal file
@ -0,0 +1,37 @@
|
||||
static void
|
||||
drawhighlights(struct item *item, int x, int y, int maxw)
|
||||
{
|
||||
int i, indent;
|
||||
char *highlight;
|
||||
char c;
|
||||
|
||||
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 (*highlight == text[i]) {
|
||||
/* 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) - 1,
|
||||
y,
|
||||
MIN(maxw - indent, TEXTW(highlight) - lrpad),
|
||||
bh, 0, highlight, 0
|
||||
);
|
||||
highlight[1] = c;
|
||||
i++;
|
||||
}
|
||||
highlight++;
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
#if CENTER_PATCH
|
||||
#include "center.c"
|
||||
#endif
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
#include "fuzzyhighlight.c"
|
||||
#endif
|
||||
#if FUZZYMATCH_PATCH
|
||||
#include "fuzzymatch.c"
|
||||
#endif
|
||||
|
@ -11,6 +11,12 @@
|
||||
*/
|
||||
#define CENTER_PATCH 0
|
||||
|
||||
/* This patch make it so that fuzzy matches gets highlighted and is therefore meant
|
||||
* to be used together with the fuzzymatch patch.
|
||||
* https://tools.suckless.org/dmenu/patches/fuzzyhighlight/
|
||||
*/
|
||||
#define FUZZYHIGHLIGHT_PATCH 0
|
||||
|
||||
/* This patch adds support for fuzzy-matching to dmenu, allowing users to type non-consecutive
|
||||
* portions of the string to be matched.
|
||||
* https://tools.suckless.org/dmenu/patches/fuzzymatch/
|
||||
|
Loading…
x
Reference in New Issue
Block a user