|
29 | 29 | #define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 |
30 | 30 |
|
31 | 31 | /* enums */ |
32 | | -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ |
| 32 | +enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight, |
| 33 | + SchemeOut, SchemeLast }; /* color schemes */ |
| 34 | + |
33 | 35 |
|
34 | 36 | struct item { |
35 | 37 | char *text; |
@@ -118,17 +120,59 @@ cistrstr(const char *s, const char *sub) |
118 | 120 | return NULL; |
119 | 121 | } |
120 | 122 |
|
| 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 | + |
121 | 162 | static int |
122 | 163 | drawitem(struct item *item, int x, int y, int w) |
123 | 164 | { |
| 165 | + int r; |
124 | 166 | if (item == sel) |
125 | 167 | drw_setscheme(drw, scheme[SchemeSel]); |
126 | 168 | else if (item->out) |
127 | 169 | drw_setscheme(drw, scheme[SchemeOut]); |
128 | 170 | else |
129 | 171 | drw_setscheme(drw, scheme[SchemeNorm]); |
130 | 172 |
|
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; |
132 | 176 | } |
133 | 177 |
|
134 | 178 | static void |
@@ -816,7 +860,8 @@ static void |
816 | 860 | usage(void) |
817 | 861 | { |
818 | 862 | 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); |
820 | 865 | exit(1); |
821 | 866 | } |
822 | 867 |
|
@@ -863,6 +908,14 @@ main(int argc, char *argv[]) |
863 | 908 | colors[SchemeSel][ColBg] = argv[++i]; |
864 | 909 | else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ |
865 | 910 | 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]; |
866 | 919 | else if (!strcmp(argv[i], "-w")) /* embedding window id */ |
867 | 920 | embed = argv[++i]; |
868 | 921 | else |
|
0 commit comments