add min width option

This commit is contained in:
finbargiusti 2025-07-08 19:36:21 +01:00
parent c726a7307c
commit 6452c98c15
2 changed files with 11 additions and 2 deletions

11
menu.c
View file

@ -86,10 +86,10 @@ static bool parse_color(const char *color, uint32_t *result) {
void menu_getopts(struct menu *menu, int argc, char *argv[]) {
const char *usage =
"Usage: wmenu [-bciPv] [-f font] [-l lines] [-o output] [-p prompt]\n"
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color] [-w minwidth]\n";
int opt;
while ((opt = getopt(argc, argv, "bchiPvf:l:o:p:N:n:M:m:S:s:")) != -1) {
while ((opt = getopt(argc, argv, "bchiPvf:l:o:p:N:n:M:m:S:s:w:")) != -1) {
switch (opt) {
case 'b':
menu->position = POSITION_BOTTOM;
@ -148,6 +148,13 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
fprintf(stderr, "Invalid selection foreground color: %s", optarg);
}
break;
case 'w':
menu->minwidth = atoi(optarg);
if (menu->minwidth < 0) {
fprintf(stderr, "Invalid minimum width: %s", optarg);
exit(EXIT_FAILURE);
}
break;
default:
fprintf(stderr, "%s", usage);
exit(EXIT_FAILURE);

2
menu.h
View file

@ -39,6 +39,8 @@ typedef enum e_position POSITION;
struct menu {
// Whether the menu appears at the bottom of the screen
POSITION position;
// The minimum width of the menu (relevant for center position)
int minwidth;
// The function used to match menu items
int (*strncmp)(const char *, const char *, size_t);
// Whether the input is a password