summaryrefslogtreecommitdiffstats
path: root/commands/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'commands/menu.c')
-rw-r--r--commands/menu.c54
1 files changed, 44 insertions, 10 deletions
diff --git a/commands/menu.c b/commands/menu.c
index f734db3874..b9d66996a4 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -48,11 +48,14 @@ struct cmd_menu {
char *command;
char *submenu;
int num;
+ int auto_select;
+ menu_entry_type type;
+ int box_state;
#endif
};
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
-#define OPTS "m:earlc:d:RsSn:u:"
+#define OPTS "m:earlc:d:RsSn:u:A:b:B:"
#define is_entry(x) ((x)->entry)
#else
#define OPTS "m:ls"
@@ -61,8 +64,8 @@ struct cmd_menu {
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
/*
- * menu -e -a -m <menu> -c <command> [-R] -d <description>
- * menu -e -a -m <menu> -u submenu -d <description>
+ * menu -e -a -m <menu> -c <command> [-R] [-b 0|1 ] -d <description>
+ * menu -e -a -m <menu> -u submenu -d [-b 0|1] <description>
*/
static int do_menu_entry_add(struct cmd_menu *cm)
{
@@ -82,11 +85,15 @@ static int do_menu_entry_add(struct cmd_menu *cm)
if (cm->submenu)
me = menu_add_submenu(m, cm->submenu, cm->description);
else
- me = menu_add_command_entry(m, cm->description, cm->command);
+ me = menu_add_command_entry(m, cm->description, cm->command,
+ cm->type);
if (!me)
return PTR_ERR(me);
- me->non_re_ent = !cm->re_entrant;
+ me->box_state = cm->box_state > 0 ? 1 : 0;
+
+ if (!cm->submenu)
+ me->non_re_ent = !cm->re_entrant;
return 0;
}
@@ -202,7 +209,7 @@ static int do_menu_select(struct cmd_menu *cm)
return -EINVAL;
}
- if (!menu_set_selected(m, cm->num)) {
+ if (menu_set_selected(m, cm->num) < 0) {
eprintf("Entry '%d' not found\n", cm->num);
return -EINVAL;
}
@@ -212,7 +219,7 @@ static int do_menu_select(struct cmd_menu *cm)
#endif
/*
- * menu -s -m <menu>
+ * menu -s -m <menu> [-A <auto select delay>] [-d <display]
*/
static int do_menu_show(struct cmd_menu *cm)
{
@@ -223,6 +230,17 @@ static int do_menu_show(struct cmd_menu *cm)
else
m = menu_get_by_name("boot");
+ if (!m)
+ return -EINVAL;
+
+ if (cm->auto_select != -EINVAL) {
+ menu_set_auto_select(m, cm->auto_select);
+
+ free(m->auto_display);
+
+ m->auto_display = strdup(cm->description);
+ }
+
return menu_show(m);
}
@@ -300,6 +318,7 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[])
memset(&cm, 0, sizeof(struct cmd_menu));
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
cm.num = -EINVAL;
+ cm.auto_select = -EINVAL;
#endif
cm.action = action_show;
@@ -343,6 +362,15 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[])
case 'n':
cm.num = simple_strtoul(optarg, NULL, 10);
break;
+ case 'A':
+ cm.auto_select = simple_strtoul(optarg, NULL, 10);
+ case 'b':
+ cm.type = MENU_ENTRY_BOX;
+ cm.box_state = simple_strtoul(optarg, NULL, 10);
+ break;
+ case 'B':
+ cm.command = optarg;
+ break;
#endif
default:
return 1;
@@ -398,7 +426,9 @@ static const __maybe_unused char cmd_menu_help[] =
"How to\n"
"\n"
"Show menu\n"
-" menu -s -m <menu>\n"
+" (-A auto select delay)\n"
+" (-d auto select description)\n"
+" menu -s -m <menu> [-A delay] [-d auto_display]\n"
"\n"
"List menu\n"
" menu -l\n"
@@ -412,11 +442,15 @@ static const __maybe_unused char cmd_menu_help[] =
"\n"
"Add an entry\n"
" (-R for do no exit the menu after executing the command)\n"
-" menu -e -a -m <menu> -c <command> [-R] -d <description>\n"
+" (-b for box style 1 for selected)\n"
+" (and optional -c for the command to run when we change the state)\n"
+" menu -e -a -m <menu> -c <command> [-R] [-b 0|1] -d <description>\n"
"Add a submenu entry\n"
" (-R is not needed)\n"
-" menu -e -a -m <menu> -u <menu> -d <description>\n"
+" (-b for box style 1 for selected)\n"
+" (and -c is not needed)\n"
+" menu -e -a -m <menu> -u submenu -d [-b 0|1] <description>\n"
"\n"
"Remove an entry\n"
" menu -e -r -m <name> -n <num>\n"