add match toggle

This commit is contained in:
speedie 2023-03-04 15:51:26 +01:00
parent 7803e08417
commit 4e9713ddae
5 changed files with 29 additions and 6 deletions

View file

@ -41,6 +41,8 @@ On top of this, you can specify arguments to change the behavior of spmenu. See
- spmenu -nmt text - Set normal mode text to text - spmenu -nmt text - Set normal mode text to text
- spmenu -imt text - Set insert mode text to text - spmenu -imt text - Set insert mode text to text
- 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 -nso - Don't sort matches
- 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
@ -124,6 +126,7 @@ On top of this, you can specify arguments to change the behavior of spmenu. See
There are also extra arguments recognized for dmenu compatibility. These are: There are also extra arguments recognized for dmenu compatibility. These are:
- spmenu -S - Don't sort matches
- spmenu -nb color - Set the normal background color - spmenu -nb color - Set the normal background color
- spmenu -nf color - Set the normal foreground color - spmenu -nf color - Set the normal foreground color
- spmenu -sb color - Set the selected background color - spmenu -sb color - Set the selected background color

View file

@ -60,6 +60,12 @@ readargs(int argc, char *argv[])
else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */ else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */
fstrncmp = strncmp; fstrncmp = strncmp;
fstrstr = strstr; fstrstr = strstr;
} else if (!strcmp(argv[i], "-S")) { /* don't sort */
sortmatches = 0;
} else if (!strcmp(argv[i], "-nso")) { /* don't sort */
sortmatches = 0;
} else if (!strcmp(argv[i], "-so")) { /* don't sort */
sortmatches = 1;
} else if (!strcmp(argv[i], "-i")) { /* case-sensitive item matching, for compatibility reasons */ } else if (!strcmp(argv[i], "-i")) { /* case-sensitive item matching, for compatibility reasons */
fstrncmp = strncasecmp; fstrncmp = strncasecmp;
fstrstr = cistrstr; fstrstr = cistrstr;
@ -293,6 +299,8 @@ usage(void)
"spmenu -nmt <text> Set normal mode text to <text>\n" "spmenu -nmt <text> Set normal mode text to <text>\n"
"spmenu -imt <text> Set insert mode text to <text>\n" "spmenu -imt <text> Set insert mode text to <text>\n"
"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 -nso Don't sort matches\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"
@ -378,6 +386,7 @@ usage(void)
"spmenu -sgr15 Set the SGR 15 color\n" "spmenu -sgr15 Set the SGR 15 color\n"
"\n", stdout); "\n", stdout);
fputs("- dmenu compatibility -\n" fputs("- dmenu compatibility -\n"
"spmenu -S Don't sort matches\n"
"spmenu -nb <color> Set the normal background color\n" "spmenu -nb <color> Set the normal background color\n"
"spmenu -nf <color> Set the normal foreground color\n" "spmenu -nf <color> Set the normal foreground color\n"
"spmenu -sb <color> Set the selected background color\n" "spmenu -sb <color> Set the selected background color\n"

View file

@ -42,6 +42,7 @@ static char *password = "."; /* Password character, when the -P
/* Match options */ /* Match options */
static int type = 1; /* Allow typing into spmenu or only allow keybinds. */ static int type = 1; /* Allow typing into spmenu or only allow keybinds. */
static int sortmatches = 1; /* Sort matches (0/1) */
static int casesensitive = 0; /* Case-sensitive by default? (0/1) */ 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 */

View file

@ -94,6 +94,10 @@ spmenu -imt text - Set insert mode text to text
spmenu -bw - Width of the border. spmenu -bw - Width of the border.
0 will disable the border 0 will disable the border
.IP \[bu] 2 .IP \[bu] 2
spmenu -so - Sort matches
.IP \[bu] 2
spmenu -nso - Don\[cq]t sort matches
.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
@ -256,6 +260,8 @@ spmenu -sgr15 - Set the SGR 15 color
There are also extra arguments recognized for dmenu compatibility. There are also extra arguments recognized for dmenu compatibility.
These are: These are:
.IP \[bu] 2 .IP \[bu] 2
spmenu -S - Don\[cq]t sort matches
.IP \[bu] 2
spmenu -nb color - Set the normal background color spmenu -nb color - Set the normal background color
.IP \[bu] 2 .IP \[bu] 2
spmenu -nf color - Set the normal foreground color spmenu -nf color - Set the normal foreground color

View file

@ -603,13 +603,17 @@ match(void)
break; break;
if (i != tokc) /* not all tokens match */ if (i != tokc) /* not all tokens match */
continue; continue;
/* exact matches go first, then prefixes, then substrings */ if (!sortmatches)
if (!tokc || !fstrncmp(text, item->text, textsize))
appenditem(item, &matches, &matchend); appenditem(item, &matches, &matchend);
else if (!fstrncmp(tokv[0], item->text, len)) else {
appenditem(item, &lprefix, &prefixend); /* exact matches go first, then prefixes, then substrings */
else if (!tokc || !fstrncmp(text, item->text, textsize))
appenditem(item, &lsubstr, &substrend); appenditem(item, &matches, &matchend);
else if (!fstrncmp(tokv[0], item->text, len))
appenditem(item, &lprefix, &prefixend);
else
appenditem(item, &lsubstr, &substrend);
}
} }
if (lprefix) { if (lprefix) {
if (matches) { if (matches) {