dmenu-fuzzyhighlight-4.9.diff 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. Author: Chris Noxz <chris@noxz.tech>
  2. note: This patch is meant to be used together with fuzzymatch
  3. diff -upN dmenu-4.9/config.def.h dmenu-4.9-fuzzyhighlight/config.def.h
  4. --- dmenu-4.9/config.def.h 2019-02-02 13:55:02.000000000 +0100
  5. +++ dmenu-4.9-fuzzyhighlight/config.def.h 2020-04-04 10:26:36.990890854 +0200
  6. @@ -11,6 +11,8 @@ static const char *colors[SchemeLast][2]
  7. /* fg bg */
  8. [SchemeNorm] = { "#bbbbbb", "#222222" },
  9. [SchemeSel] = { "#eeeeee", "#005577" },
  10. + [SchemeSelHighlight] = { "#ffc978", "#005577" },
  11. + [SchemeNormHighlight] = { "#ffc978", "#222222" },
  12. [SchemeOut] = { "#000000", "#00ffff" },
  13. };
  14. /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
  15. diff -upN dmenu-4.9/dmenu.1 dmenu-4.9-fuzzyhighlight/dmenu.1
  16. --- dmenu-4.9/dmenu.1 2019-02-02 13:55:02.000000000 +0100
  17. +++ dmenu-4.9-fuzzyhighlight/dmenu.1 2020-04-04 10:30:16.430054933 +0200
  18. @@ -20,6 +20,14 @@ dmenu \- dynamic menu
  19. .IR color ]
  20. .RB [ \-sf
  21. .IR color ]
  22. +.RB [ \-nhb
  23. +.IR color ]
  24. +.RB [ \-nhf
  25. +.IR color ]
  26. +.RB [ \-shb
  27. +.IR color ]
  28. +.RB [ \-shf
  29. +.IR color ]
  30. .RB [ \-w
  31. .IR windowid ]
  32. .P
  33. @@ -75,6 +83,18 @@ defines the selected background color.
  34. .BI \-sf " color"
  35. defines the selected foreground color.
  36. .TP
  37. +.BI \-nhb " color"
  38. +defines the normal highlight background color.
  39. +.TP
  40. +.BI \-nhf " color"
  41. +defines the normal highlight foreground color.
  42. +.TP
  43. +.BI \-shb " color"
  44. +defines the selected highlight background color.
  45. +.TP
  46. +.BI \-shf " color"
  47. +defines the selected highlight foreground color.
  48. +.TP
  49. .B \-v
  50. prints version information to stdout, then exits.
  51. .TP
  52. diff -upN dmenu-4.9/dmenu.c dmenu-4.9-fuzzyhighlight/dmenu.c
  53. --- dmenu-4.9/dmenu.c 2019-02-02 13:55:02.000000000 +0100
  54. +++ dmenu-4.9-fuzzyhighlight/dmenu.c 2020-04-04 10:27:43.888026309 +0200
  55. @@ -26,7 +26,9 @@
  56. #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
  57. /* enums */
  58. -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
  59. +enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight,
  60. + SchemeOut, SchemeLast }; /* color schemes */
  61. +
  62. struct item {
  63. char *text;
  64. @@ -113,9 +115,49 @@ cistrstr(const char *s, const char *sub)
  65. return NULL;
  66. }
  67. +static void
  68. +drawhighlights(struct item *item, int x, int y, int maxw)
  69. +{
  70. + int i, indent;
  71. + char *highlight;
  72. + char c;
  73. +
  74. + if (!(strlen(item->text) && strlen(text)))
  75. + return;
  76. +
  77. + drw_setscheme(drw, scheme[item == sel
  78. + ? SchemeSelHighlight
  79. + : SchemeNormHighlight]);
  80. + for (i = 0, highlight = item->text; *highlight && text[i];) {
  81. + if (*highlight == text[i]) {
  82. + /* get indentation */
  83. + c = *highlight;
  84. + *highlight = '\0';
  85. + indent = TEXTW(item->text);
  86. + *highlight = c;
  87. +
  88. + /* highlight character */
  89. + c = highlight[1];
  90. + highlight[1] = '\0';
  91. + drw_text(
  92. + drw,
  93. + x + indent - (lrpad / 2),
  94. + y,
  95. + MIN(maxw - indent, TEXTW(highlight) - lrpad),
  96. + bh, 0, highlight, 0
  97. + );
  98. + highlight[1] = c;
  99. + i++;
  100. + }
  101. + highlight++;
  102. + }
  103. +}
  104. +
  105. +
  106. static int
  107. drawitem(struct item *item, int x, int y, int w)
  108. {
  109. + int r;
  110. if (item == sel)
  111. drw_setscheme(drw, scheme[SchemeSel]);
  112. else if (item->out)
  113. @@ -123,7 +165,9 @@ drawitem(struct item *item, int x, int y
  114. else
  115. drw_setscheme(drw, scheme[SchemeNorm]);
  116. - return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
  117. + r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
  118. + drawhighlights(item, x, y, w);
  119. + return r;
  120. }
  121. static void
  122. @@ -683,7 +727,8 @@ static void
  123. usage(void)
  124. {
  125. fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
  126. - " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
  127. + " [-nb color] [-nf color] [-sb color] [-sf color]\n"
  128. + " [-nhb color] [-nhf color] [-shb color] [-shf color] [-w windowid]\n", stderr);
  129. exit(1);
  130. }
  131. @@ -724,6 +769,14 @@ main(int argc, char *argv[])
  132. colors[SchemeSel][ColBg] = argv[++i];
  133. else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
  134. colors[SchemeSel][ColFg] = argv[++i];
  135. + else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
  136. + colors[SchemeNormHighlight][ColBg] = argv[++i];
  137. + else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
  138. + colors[SchemeNormHighlight][ColFg] = argv[++i];
  139. + else if (!strcmp(argv[i], "-shb")) /* selected hi background color */
  140. + colors[SchemeSelHighlight][ColBg] = argv[++i];
  141. + else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
  142. + colors[SchemeSelHighlight][ColFg] = argv[++i];
  143. else if (!strcmp(argv[i], "-w")) /* embedding window id */
  144. embed = argv[++i];
  145. else