add option to not allow typing if what is being typed doesn't have any

matches
This commit is contained in:
speedie 2023-05-09 19:30:01 +02:00
parent 671dbffa1b
commit 2e9cb1e408
9 changed files with 43 additions and 1 deletions

View file

@ -349,7 +349,11 @@ state.</li>
<h3 id="bugs">Bugs</h3>
<ul>
<li>Text drawing: Pango will sometimes spit out errors for invalid
markup. Silencing this would be a good idea.</li>
markup. Silencing this would be a good idea.
<ul>
<li>Simply make sure characters are valid UTF-8 characters. Remove
anything else in the drw_text function.</li>
</ul></li>
<li>Image support: Images take a long time to load sometimes,
particularly when items are selected using the cursor so what we really
need is a way to skip over images after a set time limit.</li>

View file

@ -69,6 +69,12 @@ You may use long, descriptive arguments or the shorter arguments.
`-nr, --no-incremental`
: Don't print text every time a key is pressed
`-rm, --require-match`
: Require that input text matches an item
`-nrm, --no-require-match`
: Don't require that input text matches an item
`-F, --fuzzy`
: Enable fuzzy matching

View file

@ -144,6 +144,7 @@ spmenu.managed: 0
spmenu.mon: -1
spmenu.printindex: 0
spmenu.incremental: 0
spmenu.requirematch: 0
spmenu.coloritems: 1
spmenu.sgr: 1

View file

@ -90,6 +90,10 @@ void readargs(int argc, char *argv[]) {
incremental = 1;
} else if (!strcmp(argv[i], "-nr") || (!strcmp(argv[i], "--no-incremental"))) { // no incremental
incremental = 0;
} else if (!strcmp(argv[i], "-rm") || (!strcmp(argv[i], "--require-match"))) { // require match
requirematch = 1;
} else if (!strcmp(argv[i], "-nrm") || (!strcmp(argv[i], "--no-require-match"))) { // no incremental
requirematch = 0;
} else if (!strcmp(argv[i], "-rw") || (!strcmp(argv[i], "--relative-width"))) { // relative width
accuratewidth = 1;
} else if (!strcmp(argv[i], "-nrw") || (!strcmp(argv[i], "--no-relative-width"))) { // no relative width
@ -463,6 +467,8 @@ void usage(void) {
"spmenu -f, --fast Grabs keyboard before reading stdin\n"
"spmenu -r, --incremental Print text every time a key is pressed\n"
"spmenu -nr, --no-incremental Don't print text every time a key is pressed\n"
"spmenu -rm, --require-match Require that input text matches an item\n"
"spmenu -nrm, --no-require-match Don't require that input text matches an item\n"
"spmenu -F, --fuzzy Enable fuzzy matching\n"
"spmenu -NF, --no-fuzzy Disable fuzzy matching\n"
"spmenu -P, --password Hide characters\n"

View file

@ -96,6 +96,7 @@ ResourcePref resources[] = {
{ "globalcolors", INTEGER, &globalcolors },
{ "coloritems", INTEGER, &coloritems },
{ "sgr", INTEGER, &sgr },
{ "requirematch", INTEGER, &requirematch },
{ "menuposition", INTEGER, &menuposition },
{ "xpos", INTEGER, &xpos },
{ "ypos", INTEGER, &ypos },

View file

@ -227,6 +227,7 @@ static int pango_password = 0; /* Enable support for pango markup f
/* Misc */
static int printindex = 0; /* Print index instead of the text itself (0/1) */
static int requirematch = 0; /* Require input text to match an item (0/1) */
static int incremental = 0; /* Print text every time a key is pressed (0/1) */
static int coloritems = 1; /* Color items (0/1) */
static int sgr = 1; /* Support SGR sequences (0/1) */

View file

@ -89,6 +89,12 @@ Print text every time a key is pressed
\f[V]-nr, --no-incremental\f[R]
Don\[cq]t print text every time a key is pressed
.TP
\f[V]-rm, --require-match\f[R]
Require that input text matches an item
.TP
\f[V]-nrm, --no-require-match\f[R]
Don\[cq]t require that input text matches an item
.TP
\f[V]-F, --fuzzy\f[R]
Enable fuzzy matching
.TP

View file

@ -436,6 +436,9 @@ void insert(const char *str, ssize_t n) {
if (strlen(text) + n > sizeof text - 1)
return;
static char l[BUFSIZ] = "";
if (requirematch) memcpy(l, text, BUFSIZ);
// move existing text out of the way, insert new text, and update cursor
memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0));
@ -446,6 +449,12 @@ void insert(const char *str, ssize_t n) {
// add to cursor position and continue matching
cursor += n;
match();
if (!matches && requirematch) {
memcpy(text, l, BUFSIZ);
cursor -= n;
match();
}
}
size_t nextrune(int inc) {

View file

@ -243,6 +243,14 @@ Print text every time a key is pressed
<dd>
Dont print text every time a key is pressed
</dd>
<dt><code>-rm, --require-match</code></dt>
<dd>
Require that input text matches an item
</dd>
<dt><code>-nrm, --no-require-match</code></dt>
<dd>
Dont require that input text matches an item
</dd>
<dt><code>-F, --fuzzy</code></dt>
<dd>
Enable fuzzy matching