06_nosort

This commit is contained in:
yosh 2022-09-18 21:44:32 -04:00
parent b68af1fc3d
commit 07d2c22cb5
2 changed files with 19 additions and 7 deletions

View File

@ -55,6 +55,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
.B \-i
dmenu matches menu items case insensitively.
.TP
.B \-S
dmenu does not sort menu items after matching.
.TP
.BI \-l " lines"
dmenu lists items vertically, with the given number of lines.
.TP

23
dmenu.c
View File

@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
#include <ctype.h>
#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -53,6 +54,7 @@ static struct item *items = NULL;
static struct item *matches, *matchend;
static struct item *prev, *curr, *next, *sel;
static int mon = -1, screen;
static bool sortmatches = true;
static Atom clip, utf8;
static Display *dpy;
@ -325,13 +327,18 @@ match(void)
break;
if (i != tokc) /* not all tokens match */
continue;
/* exact matches go first, then prefixes, then substrings */
if (!tokc || !fstrncmp(text, item->text, textsize))
if (!sortmatches)
appenditem(item, &matches, &matchend);
else if (!fstrncmp(tokv[0], item->text, len))
appenditem(item, &lprefix, &prefixend);
else
appenditem(item, &lsubstr, &substrend);
else {
/* exact matches go first, then prefixes, then substrings */
if (!tokc || !fstrncmp(text, item->text, textsize))
appenditem(item, &matches, &matchend);
else if (!fstrncmp(tokv[0], item->text, len))
appenditem(item, &lprefix, &prefixend);
else
appenditem(item, &lsubstr, &substrend);
}
}
if (lprefix) {
if (matches) {
@ -786,7 +793,7 @@ setup(void)
static void
usage(void)
{
fputs("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
fputs("usage: dmenu [-bfivS] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
" [-x xoffset] [-y yoffset] [-z width]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
exit(1);
@ -807,6 +814,8 @@ main(int argc, char *argv[])
topbar = 0;
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
fast = 1;
else if (!strcmp(argv[i], "-S")) /* do not sort matches */
sortmatches = false;
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
fstrncmp = strncasecmp;
fstrstr = cistrstr;