From 6452c98c15daec0ac2301eb7079c11deff73d499 Mon Sep 17 00:00:00 2001 From: finbargiusti Date: Tue, 8 Jul 2025 19:36:21 +0100 Subject: [PATCH] add min width option --- menu.c | 11 +++++++++-- menu.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/menu.c b/menu.c index b4385a7..de822b1 100644 --- a/menu.c +++ b/menu.c @@ -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); diff --git a/menu.h b/menu.h index d1691a0..4c21fba 100644 --- a/menu.h +++ b/menu.h @@ -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