add high priority
This commit is contained in:
parent
b84494043f
commit
9b806fa9c0
|
@ -55,6 +55,7 @@ See a list below for a list.
|
||||||
- spmenu -bw - Width of the border. 0 will disable the border
|
- spmenu -bw - Width of the border. 0 will disable the border
|
||||||
- spmenu -so - Sort matches
|
- spmenu -so - Sort matches
|
||||||
- spmenu -nso - Don't sort matches
|
- spmenu -nso - Don't sort matches
|
||||||
|
- spmenu -pri priority - Specify a list of items that take priority
|
||||||
- spmenu -s - Use case-sensitive matching
|
- spmenu -s - Use case-sensitive matching
|
||||||
- spmenu -i - Use case-insensitive matching
|
- spmenu -i - Use case-insensitive matching
|
||||||
- spmenu -nm - Start spmenu in normal mode
|
- spmenu -nm - Start spmenu in normal mode
|
||||||
|
@ -99,6 +100,10 @@ See a list below for a list.
|
||||||
- spmenu -nib color - Set the normal item background color
|
- spmenu -nib color - Set the normal item background color
|
||||||
- spmenu -sif color - Set the selected item foreground color
|
- spmenu -sif color - Set the selected item foreground color
|
||||||
- spmenu -sib color - Set the selected item background color
|
- spmenu -sib color - Set the selected item background color
|
||||||
|
- spmenu -npf color - Set the normal item (high priority) foreground color
|
||||||
|
- spmenu -npb color - Set the normal item (high priority) background color
|
||||||
|
- spmenu -spf color - Set the selected item (high priority) foreground color
|
||||||
|
- spmenu -spb color - Set the selected item (high priority) background color
|
||||||
- spmenu -pfg color - Set the prompt foreground color
|
- spmenu -pfg color - Set the prompt foreground color
|
||||||
- spmenu -pbg color - Set the prompt background color
|
- spmenu -pbg color - Set the prompt background color
|
||||||
- spmenu -ifg color - Set input foreground color
|
- spmenu -ifg color - Set input foreground color
|
||||||
|
|
|
@ -4,6 +4,10 @@ spmenu.col_itemnormfg: #bbbbbb
|
||||||
spmenu.col_itemnormbg: #222222
|
spmenu.col_itemnormbg: #222222
|
||||||
spmenu.col_itemselfg: #eeeeee
|
spmenu.col_itemselfg: #eeeeee
|
||||||
spmenu.col_itemselbg: #35638A
|
spmenu.col_itemselbg: #35638A
|
||||||
|
spmenu.col_itemnormprifg: #bbbbbb
|
||||||
|
spmenu.col_itemnormpribg: #222222
|
||||||
|
spmenu.col_itemselprifg: #eeeeee
|
||||||
|
spmenu.col_itemselpribg: #35638A
|
||||||
spmenu.col_menubgcolor: #222222
|
spmenu.col_menubgcolor: #222222
|
||||||
spmenu.col_promptfg: #eeeeee
|
spmenu.col_promptfg: #eeeeee
|
||||||
spmenu.col_promptbg: #35526b
|
spmenu.col_promptbg: #35526b
|
||||||
|
|
15
libs/argv.c
15
libs/argv.c
|
@ -141,6 +141,8 @@ readargs(int argc, char *argv[])
|
||||||
menupaddingv = atoi(argv[++i]);
|
menupaddingv = atoi(argv[++i]);
|
||||||
} else if (!strcmp(argv[i], "-hp")) {
|
} else if (!strcmp(argv[i], "-hp")) {
|
||||||
menupaddingh = atoi(argv[++i]);
|
menupaddingh = atoi(argv[++i]);
|
||||||
|
} else if (!strcmp(argv[i], "-pri")) {
|
||||||
|
parse_hpitems(argv[++i]);
|
||||||
} else if (!strcmp(argv[i], "-ig")) {
|
} else if (!strcmp(argv[i], "-ig")) {
|
||||||
imagegaps = atoi(argv[++i]);
|
imagegaps = atoi(argv[++i]);
|
||||||
} else if (!strcmp(argv[i], "-la")) {
|
} else if (!strcmp(argv[i], "-la")) {
|
||||||
|
@ -208,6 +210,14 @@ readargs(int argc, char *argv[])
|
||||||
colors[SchemeItemSel][ColFg] = argv[++i];
|
colors[SchemeItemSel][ColFg] = argv[++i];
|
||||||
} else if (!strcmp(argv[i], "-sib")) { /* selected item background color */
|
} else if (!strcmp(argv[i], "-sib")) { /* selected item background color */
|
||||||
colors[SchemeItemSel][ColBg] = argv[++i];
|
colors[SchemeItemSel][ColBg] = argv[++i];
|
||||||
|
} else if (!strcmp(argv[i], "-npf")) { /* normal item priority foreground color */
|
||||||
|
colors[SchemeItemNormPri][ColFg] = argv[++i];
|
||||||
|
} else if (!strcmp(argv[i], "-npb")) { /* normal item priority background color */
|
||||||
|
colors[SchemeItemNormPri][ColBg] = argv[++i];
|
||||||
|
} else if (!strcmp(argv[i], "-spf")) { /* selected item priority foreground color */
|
||||||
|
colors[SchemeItemSelPri][ColFg] = argv[++i];
|
||||||
|
} else if (!strcmp(argv[i], "-spb")) { /* selected item priority background color */
|
||||||
|
colors[SchemeItemSelPri][ColBg] = argv[++i];
|
||||||
} else if (!strcmp(argv[i], "-mbg")) { /* menu color */
|
} else if (!strcmp(argv[i], "-mbg")) { /* menu color */
|
||||||
colors[SchemeMenu][ColBg] = argv[++i];
|
colors[SchemeMenu][ColBg] = argv[++i];
|
||||||
} else if (!strcmp(argv[i], "-pfg")) { /* prompt fg color */
|
} else if (!strcmp(argv[i], "-pfg")) { /* prompt fg color */
|
||||||
|
@ -307,6 +317,7 @@ usage(void)
|
||||||
"spmenu -bw Width of the border. 0 will disable the border\n"
|
"spmenu -bw Width of the border. 0 will disable the border\n"
|
||||||
"spmenu -so Sort matches\n"
|
"spmenu -so Sort matches\n"
|
||||||
"spmenu -nso Don't sort matches\n"
|
"spmenu -nso Don't sort matches\n"
|
||||||
|
"spmenu -pri <pri> Specify a list of items that take priority\n"
|
||||||
"spmenu -s Use case-sensitive matching\n"
|
"spmenu -s Use case-sensitive matching\n"
|
||||||
"spmenu -i Use case-insensitive matching\n"
|
"spmenu -i Use case-insensitive matching\n"
|
||||||
"spmenu -nm Start spmenu in normal mode\n"
|
"spmenu -nm Start spmenu in normal mode\n"
|
||||||
|
@ -354,6 +365,10 @@ usage(void)
|
||||||
"spmenu -nib <color> Set the normal item background color\n"
|
"spmenu -nib <color> Set the normal item background color\n"
|
||||||
"spmenu -sif <color> Set the selected item foreground color\n"
|
"spmenu -sif <color> Set the selected item foreground color\n"
|
||||||
"spmenu -sib <color> Set the selected item background color\n"
|
"spmenu -sib <color> Set the selected item background color\n"
|
||||||
|
"spmenu -npf <color> Set the normal item (high priority) foreground color\n"
|
||||||
|
"spmenu -npb <color> Set the normal item (high priority) background color\n"
|
||||||
|
"spmenu -spf <color> Set the selected item (high priority) foreground color\n"
|
||||||
|
"spmenu -spb <color> Set the selected item (high priority) background color\n"
|
||||||
"spmenu -pfg <color> Set the prompt foreground color\n"
|
"spmenu -pfg <color> Set the prompt foreground color\n"
|
||||||
"spmenu -pbg <color> Set the prompt background color\n"
|
"spmenu -pbg <color> Set the prompt background color\n"
|
||||||
"spmenu -ifg <color> Set input foreground color\n"
|
"spmenu -ifg <color> Set input foreground color\n"
|
||||||
|
|
|
@ -7,6 +7,8 @@ static const unsigned int alphas[][3] = {
|
||||||
[SchemeRArrow] = { fgalpha, bgalpha, borderalpha },
|
[SchemeRArrow] = { fgalpha, bgalpha, borderalpha },
|
||||||
[SchemeItemNorm] = { fgalpha, bgalpha, borderalpha },
|
[SchemeItemNorm] = { fgalpha, bgalpha, borderalpha },
|
||||||
[SchemeItemSel] = { fgalpha, bgalpha, borderalpha },
|
[SchemeItemSel] = { fgalpha, bgalpha, borderalpha },
|
||||||
|
[SchemeItemNormPri] = { fgalpha, bgalpha, borderalpha },
|
||||||
|
[SchemeItemSelPri] = { fgalpha, bgalpha, borderalpha },
|
||||||
[SchemeMenu] = { fgalpha, bgalpha, borderalpha },
|
[SchemeMenu] = { fgalpha, bgalpha, borderalpha },
|
||||||
[SchemeInput] = { fgalpha, bgalpha, borderalpha },
|
[SchemeInput] = { fgalpha, bgalpha, borderalpha },
|
||||||
[SchemePrompt] = { fgalpha, bgalpha, borderalpha },
|
[SchemePrompt] = { fgalpha, bgalpha, borderalpha },
|
||||||
|
@ -25,6 +27,8 @@ static const char *colors[SchemeLast][2] = {
|
||||||
[SchemeRArrow] = { col_rarrowfg, col_rarrowbg },
|
[SchemeRArrow] = { col_rarrowfg, col_rarrowbg },
|
||||||
[SchemeItemNorm] = { col_itemnormfg, col_itemnormbg },
|
[SchemeItemNorm] = { col_itemnormfg, col_itemnormbg },
|
||||||
[SchemeItemSel] = { col_itemselfg, col_itemselbg },
|
[SchemeItemSel] = { col_itemselfg, col_itemselbg },
|
||||||
|
[SchemeItemNormPri] = { col_itemnormprifg, col_itemnormpribg },
|
||||||
|
[SchemeItemSelPri] = { col_itemselprifg, col_itemselpribg },
|
||||||
[SchemeInput] = { col_inputfg, col_inputbg, },
|
[SchemeInput] = { col_inputfg, col_inputbg, },
|
||||||
[SchemeMenu] = { NULL, col_menubgcolor },
|
[SchemeMenu] = { NULL, col_menubgcolor },
|
||||||
[SchemePrompt] = { col_promptfg, col_promptbg },
|
[SchemePrompt] = { col_promptfg, col_promptbg },
|
||||||
|
|
|
@ -50,8 +50,14 @@ drawitem(struct item *item, int x, int y, int w)
|
||||||
|
|
||||||
if (item == sel) {
|
if (item == sel) {
|
||||||
memcpy(scm, scheme[SchemeItemSel], sizeof(scm));
|
memcpy(scm, scheme[SchemeItemSel], sizeof(scm));
|
||||||
|
|
||||||
|
if (item->hp)
|
||||||
|
memcpy(scm, scheme[SchemeItemSelPri], sizeof(scm));
|
||||||
} else {
|
} else {
|
||||||
memcpy(scm, scheme[SchemeItemNorm], sizeof(scm));
|
memcpy(scm, scheme[SchemeItemNorm], sizeof(scm));
|
||||||
|
|
||||||
|
if (item->hp)
|
||||||
|
memcpy(scm, scheme[SchemeItemNormPri], sizeof(scm));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set scheme */
|
/* set scheme */
|
||||||
|
|
|
@ -4,6 +4,8 @@ enum { SchemeLArrow,
|
||||||
SchemeRArrow,
|
SchemeRArrow,
|
||||||
SchemeItemNorm,
|
SchemeItemNorm,
|
||||||
SchemeItemSel,
|
SchemeItemSel,
|
||||||
|
SchemeItemNormPri,
|
||||||
|
SchemeItemSelPri,
|
||||||
SchemeMenu,
|
SchemeMenu,
|
||||||
SchemeInput,
|
SchemeInput,
|
||||||
SchemePrompt,
|
SchemePrompt,
|
||||||
|
|
22
libs/sort.c
Normal file
22
libs/sort.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
int
|
||||||
|
str_compar(const void *s0_in, const void *s1_in)
|
||||||
|
{
|
||||||
|
const char *s0 = *(const char **)s0_in;
|
||||||
|
const char *s1 = *(const char **)s1_in;
|
||||||
|
return fstrncmp == strncasecmp ? strcasecmp(s0, s1) : strcmp(s0, s1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
parse_hpitems(char *src)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
char *t;
|
||||||
|
|
||||||
|
for (t = strtok(src, ","); t; t = strtok(NULL, ",")) {
|
||||||
|
if (hplength + 1 >= n) {
|
||||||
|
if (!(hpitems = realloc(hpitems, (n += 8) * sizeof *hpitems)))
|
||||||
|
die("Unable to realloc %zu bytes\n", n * sizeof *hpitems);
|
||||||
|
}
|
||||||
|
hpitems[hplength++] = t;
|
||||||
|
}
|
||||||
|
}
|
2
libs/sort.h
Normal file
2
libs/sort.h
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
static int str_compar(const void *s0_in, const void *s1_in);
|
||||||
|
static void parse_hpitems(char *src);
|
|
@ -13,6 +13,10 @@ ResourcePref resources[] = {
|
||||||
{ "col_itemnormbg", STRING, &col_itemnormbg },
|
{ "col_itemnormbg", STRING, &col_itemnormbg },
|
||||||
{ "col_itemselfg", STRING, &col_itemselfg },
|
{ "col_itemselfg", STRING, &col_itemselfg },
|
||||||
{ "col_itemselbg", STRING, &col_itemselbg },
|
{ "col_itemselbg", STRING, &col_itemselbg },
|
||||||
|
{ "col_itemnormprifg", STRING, &col_itemnormprifg },
|
||||||
|
{ "col_itemnormpribg", STRING, &col_itemnormpribg },
|
||||||
|
{ "col_itemselprifg", STRING, &col_itemselprifg },
|
||||||
|
{ "col_itemselpribg", STRING, &col_itemselpribg },
|
||||||
{ "col_inputbg", STRING, &col_inputbg },
|
{ "col_inputbg", STRING, &col_inputbg },
|
||||||
{ "col_inputfg", STRING, &col_inputfg },
|
{ "col_inputfg", STRING, &col_inputfg },
|
||||||
{ "col_menubgcolor", STRING, &col_menubgcolor },
|
{ "col_menubgcolor", STRING, &col_menubgcolor },
|
||||||
|
@ -33,16 +37,20 @@ ResourcePref resources[] = {
|
||||||
{ "color4", STRING, &col_larrowfg },
|
{ "color4", STRING, &col_larrowfg },
|
||||||
{ "color4", STRING, &col_rarrowfg },
|
{ "color4", STRING, &col_rarrowfg },
|
||||||
{ "color10", STRING, &col_itemnormfg },
|
{ "color10", STRING, &col_itemnormfg },
|
||||||
|
{ "color10", STRING, &col_itemnormprifg },
|
||||||
{ "color10", STRING, &col_inputfg },
|
{ "color10", STRING, &col_inputfg },
|
||||||
{ "color0", STRING, &col_itemnormbg },
|
{ "color0", STRING, &col_itemnormbg },
|
||||||
|
{ "color0", STRING, &col_itemnormpribg },
|
||||||
{ "color0", STRING, &col_menubgcolor },
|
{ "color0", STRING, &col_menubgcolor },
|
||||||
{ "color0", STRING, &col_larrowbg },
|
{ "color0", STRING, &col_larrowbg },
|
||||||
{ "color0", STRING, &col_rarrowbg },
|
{ "color0", STRING, &col_rarrowbg },
|
||||||
{ "color0", STRING, &col_itemselfg },
|
{ "color0", STRING, &col_itemselfg },
|
||||||
|
{ "color0", STRING, &col_itemselprifg },
|
||||||
{ "color0", STRING, &col_inputbg },
|
{ "color0", STRING, &col_inputbg },
|
||||||
{ "color12", STRING, &col_promptbg },
|
{ "color12", STRING, &col_promptbg },
|
||||||
{ "color0", STRING, &col_promptfg },
|
{ "color0", STRING, &col_promptfg },
|
||||||
{ "color6", STRING, &col_itemselbg },
|
{ "color6", STRING, &col_itemselbg },
|
||||||
|
{ "color6", STRING, &col_itemselpribg },
|
||||||
{ "color6", STRING, &col_bordercolor },
|
{ "color6", STRING, &col_bordercolor },
|
||||||
{ "color0", STRING, &col_numfgcolor },
|
{ "color0", STRING, &col_numfgcolor },
|
||||||
{ "color5", STRING, &col_numbgcolor },
|
{ "color5", STRING, &col_numbgcolor },
|
||||||
|
|
|
@ -48,6 +48,7 @@ static int casesensitive = 0; /* Case-sensitive by default? (0/1)
|
||||||
static int preselected = 0; /* Which line should spmenu preselect? */
|
static int preselected = 0; /* Which line should spmenu preselect? */
|
||||||
static int accuratewidth = 1; /* Enable accurate width. May have a performance hit if you are matching a lot of items at once */
|
static int accuratewidth = 1; /* Enable accurate width. May have a performance hit if you are matching a lot of items at once */
|
||||||
static int fuzzy = 1; /* Whether or not to enable fuzzy matching by default */
|
static int fuzzy = 1; /* Whether or not to enable fuzzy matching by default */
|
||||||
|
static char **hpitems = NULL; /* High priority items */
|
||||||
|
|
||||||
/* Line options */
|
/* Line options */
|
||||||
static int lineheight = 5; /* Line height (0: Calculate automatically) */
|
static int lineheight = 5; /* Line height (0: Calculate automatically) */
|
||||||
|
@ -79,6 +80,10 @@ static char col_itemnormfg[] = "#bbbbbb"; /* Normal foreground item co
|
||||||
static char col_itemnormbg[] = "#222222"; /* Normal background item color */
|
static char col_itemnormbg[] = "#222222"; /* Normal background item color */
|
||||||
static char col_itemselfg[] = "#eeeeee"; /* Selected foreground item color */
|
static char col_itemselfg[] = "#eeeeee"; /* Selected foreground item color */
|
||||||
static char col_itemselbg[] = "#35638A"; /* Selected background item color */
|
static char col_itemselbg[] = "#35638A"; /* Selected background item color */
|
||||||
|
static char col_itemnormprifg[] = "#bbbbbb"; /* Normal foreground item (high priority) color */
|
||||||
|
static char col_itemnormpribg[] = "#222222"; /* Normal background item (high priority) color */
|
||||||
|
static char col_itemselprifg[] = "#eeeeee"; /* Selected foreground item (high priority) color */
|
||||||
|
static char col_itemselpribg[] = "#35638A"; /* Selected background item (high priority) color */
|
||||||
|
|
||||||
/* Input colors */
|
/* Input colors */
|
||||||
static char col_inputbg[] = "#222222"; /* Input field background color */
|
static char col_inputbg[] = "#222222"; /* Input field background color */
|
||||||
|
|
14
spmenu.1
14
spmenu.1
|
@ -14,7 +14,7 @@
|
||||||
. ftr VB CB
|
. ftr VB CB
|
||||||
. ftr VBI CBI
|
. ftr VBI CBI
|
||||||
.\}
|
.\}
|
||||||
.TH "spmenu" "1" "" "0.2.1" "dynamic menu"
|
.TH "spmenu" "1" "" "0.2.2" "dynamic menu"
|
||||||
.hy
|
.hy
|
||||||
.SH spmenu
|
.SH spmenu
|
||||||
.SS 1. What is spmenu?
|
.SS 1. What is spmenu?
|
||||||
|
@ -103,6 +103,8 @@ spmenu -so - Sort matches
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
spmenu -nso - Don\[cq]t sort matches
|
spmenu -nso - Don\[cq]t sort matches
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
|
spmenu -pri priority - Specify a list of items that take priority
|
||||||
|
.IP \[bu] 2
|
||||||
spmenu -s - Use case-sensitive matching
|
spmenu -s - Use case-sensitive matching
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
spmenu -i - Use case-insensitive matching
|
spmenu -i - Use case-insensitive matching
|
||||||
|
@ -189,6 +191,16 @@ spmenu -sif color - Set the selected item foreground color
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
spmenu -sib color - Set the selected item background color
|
spmenu -sib color - Set the selected item background color
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
|
spmenu -npf color - Set the normal item (high priority) foreground color
|
||||||
|
.IP \[bu] 2
|
||||||
|
spmenu -npb color - Set the normal item (high priority) background color
|
||||||
|
.IP \[bu] 2
|
||||||
|
spmenu -spf color - Set the selected item (high priority) foreground
|
||||||
|
color
|
||||||
|
.IP \[bu] 2
|
||||||
|
spmenu -spb color - Set the selected item (high priority) background
|
||||||
|
color
|
||||||
|
.IP \[bu] 2
|
||||||
spmenu -pfg color - Set the prompt foreground color
|
spmenu -pfg color - Set the prompt foreground color
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
spmenu -pbg color - Set the prompt background color
|
spmenu -pbg color - Set the prompt background color
|
||||||
|
|
29
spmenu.c
29
spmenu.c
|
@ -112,6 +112,7 @@
|
||||||
#include "libs/xrdb.h"
|
#include "libs/xrdb.h"
|
||||||
#include "libs/key.h"
|
#include "libs/key.h"
|
||||||
#include "libs/mouse.h"
|
#include "libs/mouse.h"
|
||||||
|
#include "libs/sort.h"
|
||||||
|
|
||||||
static char text[BUFSIZ] = "";
|
static char text[BUFSIZ] = "";
|
||||||
|
|
||||||
|
@ -120,6 +121,7 @@ struct item {
|
||||||
char *image;
|
char *image;
|
||||||
char *ex;
|
char *ex;
|
||||||
struct item *left, *right;
|
struct item *left, *right;
|
||||||
|
int hp;
|
||||||
double distance;
|
double distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,6 +134,7 @@ typedef struct {
|
||||||
} Key;
|
} Key;
|
||||||
|
|
||||||
static char numbers[NUMBERSBUFSIZE] = "";
|
static char numbers[NUMBERSBUFSIZE] = "";
|
||||||
|
static int hplength = 0;
|
||||||
static char *embed;
|
static char *embed;
|
||||||
static int numlockmask = 0;
|
static int numlockmask = 0;
|
||||||
static int bh, mw, mh;
|
static int bh, mw, mh;
|
||||||
|
@ -230,6 +233,7 @@ static char *(*fstrstr)(const char *, const char *) = cistrstr;
|
||||||
#include "libs/event.c"
|
#include "libs/event.c"
|
||||||
#include "libs/key.c"
|
#include "libs/key.c"
|
||||||
#include "libs/mouse.c"
|
#include "libs/mouse.c"
|
||||||
|
#include "libs/sort.c"
|
||||||
#include "libs/draw.c"
|
#include "libs/draw.c"
|
||||||
#include "libs/schemes.c"
|
#include "libs/schemes.c"
|
||||||
#include "libs/arg.c"
|
#include "libs/arg.c"
|
||||||
|
@ -489,7 +493,8 @@ match(void)
|
||||||
char buf[sizeof text], *s;
|
char buf[sizeof text], *s;
|
||||||
int i, tokc = 0;
|
int i, tokc = 0;
|
||||||
size_t len, textsize;
|
size_t len, textsize;
|
||||||
struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
|
struct item *item, *lhpprefix, *lprefix, *lsubstr, *hpprefixend, *prefixend, *substrend;
|
||||||
|
|
||||||
|
|
||||||
strcpy(buf, text);
|
strcpy(buf, text);
|
||||||
/* separate input text into tokens to be matched individually */
|
/* separate input text into tokens to be matched individually */
|
||||||
|
@ -498,7 +503,7 @@ match(void)
|
||||||
die("cannot realloc %u bytes:", tokn * sizeof *tokv);
|
die("cannot realloc %u bytes:", tokn * sizeof *tokv);
|
||||||
len = tokc ? strlen(tokv[0]) : 0;
|
len = tokc ? strlen(tokv[0]) : 0;
|
||||||
|
|
||||||
matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
|
matches = lhpprefix = lprefix = lsubstr = matchend = hpprefixend = prefixend = substrend = NULL;
|
||||||
textsize = strlen(text) + 1;
|
textsize = strlen(text) + 1;
|
||||||
for (item = items; item && item->text; item++) {
|
for (item = items; item && item->text; item++) {
|
||||||
for (i = 0; i < tokc; i++)
|
for (i = 0; i < tokc; i++)
|
||||||
|
@ -509,15 +514,25 @@ match(void)
|
||||||
if (!sortmatches)
|
if (!sortmatches)
|
||||||
appenditem(item, &matches, &matchend);
|
appenditem(item, &matches, &matchend);
|
||||||
else {
|
else {
|
||||||
/* exact matches go first, then prefixes, then substrings */
|
/* exact matches go first, then prefixes with high priority, then prefixes, then substrings */
|
||||||
if (!tokc || !fstrncmp(text, item->text, textsize))
|
if (!tokc || !fstrncmp(text, item->text, textsize))
|
||||||
appenditem(item, &matches, &matchend);
|
appenditem(item, &matches, &matchend);
|
||||||
|
else if (item->hp && !fstrncmp(tokv[0], item->text, len))
|
||||||
|
appenditem(item, &lhpprefix, &hpprefixend);
|
||||||
else if (!fstrncmp(tokv[0], item->text, len))
|
else if (!fstrncmp(tokv[0], item->text, len))
|
||||||
appenditem(item, &lprefix, &prefixend);
|
appenditem(item, &lprefix, &prefixend);
|
||||||
else
|
else
|
||||||
appenditem(item, &lsubstr, &substrend);
|
appenditem(item, &lsubstr, &substrend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (lhpprefix) {
|
||||||
|
if (matches) {
|
||||||
|
matchend->right = lhpprefix;
|
||||||
|
lhpprefix->left = matchend;
|
||||||
|
} else
|
||||||
|
matches = lhpprefix;
|
||||||
|
matchend = hpprefixend;
|
||||||
|
}
|
||||||
if (lprefix) {
|
if (lprefix) {
|
||||||
if (matches) {
|
if (matches) {
|
||||||
matchend->right = lprefix;
|
matchend->right = lprefix;
|
||||||
|
@ -734,6 +749,9 @@ readstdin(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hpitems && hplength > 0)
|
||||||
|
qsort(hpitems, hplength, sizeof *hpitems, str_compar);
|
||||||
|
|
||||||
/* read each line from stdin and add it to the item list */
|
/* read each line from stdin and add it to the item list */
|
||||||
for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
|
for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
|
||||||
if (i + 1 >= itemsiz) {
|
if (i + 1 >= itemsiz) {
|
||||||
|
@ -745,6 +763,11 @@ readstdin(void)
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (!(items[i].text = strdup(buf)))
|
if (!(items[i].text = strdup(buf)))
|
||||||
die("cannot strdup %u bytes:", strlen(buf) + 1);
|
die("cannot strdup %u bytes:", strlen(buf) + 1);
|
||||||
|
p = hpitems == NULL ? NULL : bsearch(
|
||||||
|
&items[i].text, hpitems, hplength, sizeof *hpitems,
|
||||||
|
str_compar
|
||||||
|
);
|
||||||
|
items[i].hp = p != NULL;
|
||||||
drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True);
|
drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True);
|
||||||
if (tmpmax > inputw) {
|
if (tmpmax > inputw) {
|
||||||
inputw = tmpmax;
|
inputw = tmpmax;
|
||||||
|
|
Loading…
Reference in a new issue