add option to not allow selecting multiple items to spmenu itself

This commit is contained in:
speedie 2023-05-19 02:13:13 +02:00
parent 5aeea3230b
commit 620cb0ca63
8 changed files with 26 additions and 1 deletions

View file

@ -81,6 +81,12 @@ You may use long, descriptive arguments or the shorter arguments.
`-nrm, --no-require-match`
: Don't require that input text matches an item
`-ma, --mark-items`
: Allow marking/selecting multiple items
`-nma, --no-mark-items`
: Don't allow marking/selecting multiple items
`-F, --fuzzy`
: Enable fuzzy matching
@ -349,6 +355,9 @@ You may use long, descriptive arguments or the shorter arguments.
`-v, --version`
: Print spmenu version to stdout
`-rv, --raw-version`
: Print raw spmenu version number to stdout
`-fn, --font font`
: Set the spmenu font to font

View file

@ -128,6 +128,7 @@ spmenu.type: 1
spmenu.passwd: 0
spmenu.fuzzy: 1
spmenu.sortmatches: 1
spmenu.mark: 1
spmenu.casesensitive: 0
!! Menu

View file

@ -166,6 +166,7 @@ spmenu = {
casesensitive = 0; // Enable case sensitivity when matching (0/1)
fuzzy = 1; // Enable fuzzy finding (0/1)
preselected = 0; // Preselect an item, 0 is the first item (number)
mark = 1; // Allow marking/selecting multiple items (0/1)
accuratewidth = 0; // Enable accurate width, could be noticeably slower in some cases (0/1)
delimiters = " "; // Word delimiter, used to delete words (text)
listfile = "NULL"; // File to read entries from. If set to NULL standard input is read. This is read every time a key is pressed. (text)

View file

@ -241,6 +241,7 @@ void backspace(Arg *arg) {
}
void markitem(Arg *arg) {
if (!mark) return;
if (sel && is_selected(sel->index)) {
for (int i = 0; i < sel_size; i++) {
if (sel_index[i] == sel->index) {

View file

@ -65,6 +65,9 @@ void readargs(int argc, char *argv[]) {
if (!strcmp(argv[i], "-v") || (!strcmp(argv[i], "--version"))) { // prints version information
puts("spmenu-"VERSION);
exit(0);
} else if (!strcmp(argv[i], "-rv") || (!strcmp(argv[i], "--raw-version"))) { // help
puts(VERSION);
exit(0);
} else if (!strcmp(argv[i], "-h") || (!strcmp(argv[i], "--help"))) { // help
usage(0);
} else if (!strcmp(argv[i], "-it") || (!strcmp(argv[i], "--image-top"))) { // image: top
@ -93,8 +96,12 @@ void readargs(int argc, char *argv[]) {
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
} else if (!strcmp(argv[i], "-nrm") || (!strcmp(argv[i], "--no-require-match"))) { // no require match
requirematch = 0;
} else if (!strcmp(argv[i], "-ma") || (!strcmp(argv[i], "--mark-items"))) { // allow marking items
mark = 1;
} else if (!strcmp(argv[i], "-nma") || (!strcmp(argv[i], "--no-mark-items"))) { // don't allow marking items
mark = 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
@ -482,6 +489,8 @@ void usage(int status) {
"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 -ma, --mark-items Allow marking/selecting multiple items\n"
"spmenu -nma, --no-mark-items Don't allow marking/selecting multiple items\n"
"spmenu -F, --fuzzy Enable fuzzy matching\n"
"spmenu -NF, --no-fuzzy Disable fuzzy matching\n"
"spmenu -P, --password Hide characters\n"
@ -578,6 +587,7 @@ void usage(int status) {
"spmenu -tm, --theme <theme> Load theme <theme>\n"
"spmenu -ltm, --load-theme Load theme\n"
"spmenu -nltm, --no-load-theme Don't load theme\n"
"spmenu -rv, --raw-version Print spmenu version number to stdout\n"
"spmenu -v, --version Print spmenu version to stdout\n"
"\n", status ? stderr : stdout);

View file

@ -476,6 +476,7 @@ void conf_init(void) {
config_setting_lookup_int(conf, "casesensitive", &casesensitive); // spmenu.match.casesensitive
config_setting_lookup_int(conf, "fuzzy", &fuzzy); // spmenu.match.fuzzy
config_setting_lookup_int(conf, "preselected", &preselected); // spmenu.match.preselected
config_setting_lookup_int(conf, "mark", &mark); // spmenu.match.mark
config_setting_lookup_int(conf, "accuratewidth", &accuratewidth); // spmenu.match.accuratewidth
config_setting_lookup_string(conf, "delimiters", &dest); // spmenu.match.delimiters
worddelimiters = strdup(dest);

View file

@ -155,6 +155,7 @@ ResourcePref resources[] = {
{ "mode", INTEGER, &mode },
{ "fast", INTEGER, &fast },
{ "managed", INTEGER, &managed },
{ "mark", INTEGER, &mark },
{ "mon", INTEGER, &mon },
{ "sortmatches", INTEGER, &sortmatches },
{ "printindex", INTEGER, &printindex },

View file

@ -77,6 +77,7 @@ static int type = 1; /* Allow typing into spmenu or only
static int passwd = 0; /* Replace input with another character and don't read stdin */
static int sortmatches = 1; /* Sort matches (0/1) */
static int casesensitive = 0; /* Case-sensitive by default? (0/1) */
static int mark = 1; /* Enable marking items (multi selection) (0/1) */
static int preselected = 0; /* Which line should spmenu preselect? */
static int accuratewidth = 0; /* 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 */