Add --min-lines option

This commit is contained in:
Jacob 2023-08-17 14:56:37 +02:00
parent bfc6c12a86
commit 6b20fe939e
12 changed files with 31 additions and 11 deletions

View file

@ -43,9 +43,15 @@ in the config files.
`-cw, --center-width width`
: Set width to width when centered
`-l, --lines lines`
: Set the number of lines to lines
`-g, --columns grid`
: Set the number of grids to grid
`-ml, --min-lines`
: Set minimum number of lines allowed to lines
`-gc, --generate-cache`
: Generate image cache

View file

@ -247,6 +247,7 @@ spmenu = {
columns = 10; // Number of columns (number)
overridelines = 1; // Allow overriding lines using keybinds (0/1)
overridecolumns = 1; // Allow overriding columns using keybinds (0/1)
minlines = 0; // Minimum number of lines (number)
indentitems = 0; // Indent items to prompt width (0/1)
}
);
@ -353,7 +354,7 @@ spmenu = {
{ click = "None"; button = "Scroll Down"; function = "movenext"; argument = "0"; }, // Scroll Down: Move to the next page
{
scrolldistance = 512; // Distance to scroll for a scroll action to count. Wayland only (num)
scrolldistance = 512; // Distance to scroll for a scroll action to count. Wayland only (number)
ignoreglobalmouse = 1; // Ignore hardcoded mouse binds (0/1)
}
);

View file

@ -567,7 +567,9 @@ void setlines(Arg *arg) {
insert(NULL, 0 - sp.cursor);
selecteditem = currentitem = matches;
lines += arg->i;
if (lines + arg->i >= minlines) {
lines += arg->i;
}
if (lines < 0) {
lines = 0;

View file

@ -321,8 +321,10 @@ void readargs(int argc, char *argv[]) {
} else if (!strcmp(argv[i], "-l") || (!strcmp(argv[i], "--lines"))) { // number of lines in grid
lines = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-mh") || (!strcmp(argv[i], "--lineheight")) || (!strcmp(argv[i], "--line-height"))) { // line height
lineheight += atoi(argv[++i]);
lineheight = atoi(argv[++i]);
if (columns == 0) columns = 1;
} else if (!strcmp(argv[i], "-ml") || (!strcmp(argv[i], "--min-lines"))) {
minlines = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-cw") || (!strcmp(argv[i], "--center-width")) || (!strcmp(argv[i], "-mw") || (!strcmp(argv[i], "--min-width")))) { // center width
centerwidth = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-txp") || (!strcmp(argv[i], "--text-padding"))) { // text padding
@ -612,10 +614,11 @@ void usage(int status) {
fputs(VERSION, status ? stderr : stdout);
fputs(": fancy dynamic menu\n\n"
"- Arguments -\n"
"spmenu -l, --lines <line> Set line count to stdin\n"
"spmenu -mh, --line-height <height> Set spmenu line height to <height>\n"
"spmenu -cw, --center-width <width> Set width to <width> when centered\n"
"spmenu -l, --lines <line> Set line count to stdin\n"
"spmenu -g, --columns <grid> Set the number of grids to <grid>\n"
"spmenu -ml, --min-lines <lines> Minimum number of lines allowed\n"
"spmenu -gc, --generate-cache Generate image cache\n"
"spmenu -ngc, --no-generate-cache Don't generate image cache\n"
"spmenu -mc, --max-cache <size> Set max image cache size to <size>\n"

View file

@ -788,6 +788,7 @@ void conf_init(void) {
config_setting_lookup_int(conf, "columns", &columns); // spmenu.line.columns
config_setting_lookup_int(conf, "overridelines", &overridelines); // spmenu.line.overridelines
config_setting_lookup_int(conf, "overridecolumns", &overridecolumns); // spmenu.line.overridecolumns
config_setting_lookup_int(conf, "minlines", &minlines); // spmenu.line.minlines
config_setting_lookup_int(conf, "indentitems", &indentitems); // spmenu.line.indentitems
}
}

View file

@ -115,6 +115,7 @@ static int lines = 0; /* Default number of lines */
static int columns = 10; /* Default number of columns */
static int overridelines = 1; /* Allow overriding lines using keybinds */
static int overridecolumns = 1; /* Allow overriding columns using keybinds */
static int minlines = 0; /* Minimum number of lines allowed */
/* History options */
static char *histfile = NULL; /* History file, NULL means no history file */

View file

@ -63,7 +63,7 @@ void readstdin(void) {
#endif
}
lines = MIN(lines, i);
lines = MAX(MIN(lines, i), minlines);
}
void readfile(void) {
@ -130,7 +130,7 @@ void readfile(void) {
#endif
}
lines = columns == 1 ? i : MIN(i, lines); // i = number of items
lines = MAX(columns == 1 ? i : MIN(i, lines), minlines);
#if IMAGE
if (!o) img.longestedge = img.imagegaps = 0;

View file

@ -633,7 +633,7 @@ void resizeclient_wl(struct state *state) {
for (item = items; item && item->text; item++)
ic++;
lines = MIN(ic, MAX(lines, 0));
lines = MAX(MIN(ic, MAX(lines, 0)), minlines);
#if IMAGE
img.setlines = lines;
#endif

View file

@ -78,7 +78,7 @@ void resizeclient_x11(void) {
for (item = items; item && item->text; item++)
ic++;
lines = MIN(ic, MAX(lines, 0));
lines = MAX(MIN(ic, MAX(lines, 0)), minlines);
#if IMAGE
img.setlines = lines;

View file

@ -1,5 +1,5 @@
'\" t
.\" Automatically generated by Pandoc 3.1.3
.\" Automatically generated by Pandoc 3.1.2
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
@ -70,9 +70,15 @@ Set spmenu line height to height
\f[V]-cw, --center-width width\f[R]
Set width to width when centered
.TP
\f[V]-l, --lines lines\f[R]
Set the number of lines to lines
.TP
\f[V]-g, --columns grid\f[R]
Set the number of grids to grid
.TP
\f[V]-ml, --min-lines\f[R]
Set minimum number of lines allowed to lines
.TP
\f[V]-gc, --generate-cache\f[R]
Generate image cache
.TP

View file

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 3.1.3
.\" Automatically generated by Pandoc 3.1.2
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.

View file

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 3.1.3
.\" Automatically generated by Pandoc 3.1.2
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.