dmenu/patch/fuzzyhighlight.c

58 lines
1.2 KiB
C
Raw Normal View History

2020-04-04 09:58:35 +02:00
static void
2021-05-24 13:29:40 +02:00
#if EMOJI_HIGHLIGHT_PATCH
drawhighlights(struct item *item, char *output, int x, int y, int maxw)
#else
2020-04-04 09:58:35 +02:00
drawhighlights(struct item *item, int x, int y, int maxw)
2021-05-24 13:29:40 +02:00
#endif // EMOJI_HIGHLIGHT_PATCH
2020-04-04 09:58:35 +02:00
{
int i, indent;
char *highlight;
char c;
2021-05-24 13:29:40 +02:00
#if EMOJI_HIGHLIGHT_PATCH
char *itemtext = output;
#elif TSV_PATCH
char *itemtext = item->stext;
#else
char *itemtext = item->text;
#endif // TSV_PATCH
if (!(strlen(itemtext) && strlen(text)))
2020-04-04 09:58:35 +02:00
return;
drw_setscheme(drw, scheme[item == sel
? SchemeSelHighlight
: SchemeNormHighlight]);
2021-05-24 13:29:40 +02:00
for (i = 0, highlight = itemtext; *highlight && text[i];) {
#if FUZZYMATCH_PATCH
if (!fstrncmp(&(*highlight), &text[i], 1))
#else
if (*highlight == text[i])
#endif // FUZZYMATCH_PATCH
{
2020-04-04 09:58:35 +02:00
/* get indentation */
c = *highlight;
*highlight = '\0';
2021-05-24 13:29:40 +02:00
indent = TEXTW(itemtext);
2020-04-04 09:58:35 +02:00
*highlight = c;
/* highlight character */
c = highlight[1];
highlight[1] = '\0';
drw_text(
drw,
x + indent - (lrpad / 2),
2020-04-04 09:58:35 +02:00
y,
MIN(maxw - indent, TEXTW(highlight) - lrpad),
bh, 0, highlight, 0
2020-06-13 15:32:41 +02:00
#if PANGO_PATCH
, True
#endif // PANGO_PATCH
2020-04-04 09:58:35 +02:00
);
highlight[1] = c;
i++;
}
highlight++;
}
}