highlight.c (2734B)
1 static void 2 #if EMOJI_HIGHLIGHT_PATCH 3 drawhighlights(struct item *item, char *output, int x, int y, int maxw) 4 #else 5 drawhighlights(struct item *item, int x, int y, int maxw) 6 #endif // EMOJI_HIGHLIGHT_PATCH 7 { 8 char restorechar, tokens[sizeof text], *highlight, *token; 9 int indent, highlightlen; 10 11 #if FUZZYMATCH_PATCH 12 int i; 13 #endif // FUZZYMATCH_PATCH 14 15 #if EMOJI_HIGHLIGHT_PATCH 16 char *itemtext = output; 17 #elif TSV_PATCH && !SEPARATOR_PATCH 18 char *itemtext = item->stext; 19 #else 20 char *itemtext = item->text; 21 #endif // EMOJI_HIGHLIGHT_PATCH | TSV_PATCH 22 23 if (!(strlen(itemtext) && strlen(text))) 24 return; 25 26 /* Do not highlight items scheduled for output */ 27 #if MULTI_SELECTION_PATCH 28 if (issel(item->id)) 29 return; 30 #else 31 if (item->out) 32 return; 33 #endif // MULTI_SELECTION_PATCH 34 35 drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]); 36 37 #if FUZZYMATCH_PATCH 38 if (fuzzy) { 39 for (i = 0, highlight = itemtext; *highlight && text[i];) { 40 highlightlen = utf8len(highlight); 41 #if FUZZYMATCH_PATCH 42 if (!fstrncmp(&(*highlight), &text[i], highlightlen)) 43 #else 44 if (*highlight == text[i]) 45 #endif // FUZZYMATCH_PATCH 46 { 47 /* get indentation */ 48 restorechar = *highlight; 49 *highlight = '\0'; 50 indent = TEXTW(itemtext) - lrpad; 51 *highlight = restorechar; 52 53 /* highlight character */ 54 restorechar = highlight[highlightlen]; 55 highlight[highlightlen] = '\0'; 56 drw_text( 57 drw, 58 x + indent + (lrpad / 2), 59 y, 60 MIN(maxw - indent - lrpad, TEXTW(highlight) - lrpad), 61 bh, 0, highlight, 0 62 #if PANGO_PATCH 63 , True 64 #endif // PANGO_PATCH 65 ); 66 highlight[highlightlen] = restorechar; 67 i += highlightlen; 68 } 69 highlight++; 70 } 71 return; 72 } 73 #endif // FUZZYMATCH_PATCH 74 75 strcpy(tokens, text); 76 for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) { 77 highlight = fstrstr(itemtext, token); 78 while (highlight) { 79 // Move item str end, calc width for highlight indent, & restore 80 highlightlen = highlight - itemtext; 81 restorechar = *highlight; 82 itemtext[highlightlen] = '\0'; 83 indent = TEXTW(itemtext); 84 itemtext[highlightlen] = restorechar; 85 86 // Move highlight str end, draw highlight, & restore 87 restorechar = highlight[strlen(token)]; 88 highlight[strlen(token)] = '\0'; 89 if (indent - (lrpad / 2) - 1 < maxw) 90 drw_text( 91 drw, 92 x + indent - (lrpad / 2) - 1, 93 y, 94 MIN(maxw - indent, TEXTW(highlight) - lrpad), 95 bh, 0, highlight, 0 96 #if PANGO_PATCH 97 , True 98 #endif // PANGO_PATCH 99 ); 100 highlight[strlen(token)] = restorechar; 101 102 if (strlen(highlight) - strlen(token) < strlen(token)) 103 break; 104 highlight = fstrstr(highlight + strlen(token), token); 105 } 106 } 107 }