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