From 039019039e89aedf4c5a0d81c351638a1e036335 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 20 Jun 2024 16:20:05 -0700 Subject: [dynui] Allow for multiple flags on a user interface item Signed-off-by: Michael Brown --- src/core/dynui.c | 6 +++--- src/hci/commands/dynui_cmd.c | 7 +++++-- src/hci/tui/menu_ui.c | 2 +- src/include/ipxe/dynui.h | 12 ++++++++---- 4 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/dynui.c b/src/core/dynui.c index 33218f5..3d139c0 100644 --- a/src/core/dynui.c +++ b/src/core/dynui.c @@ -96,13 +96,13 @@ struct dynamic_ui * create_dynui ( const char *name, const char *title ) { * @v dynui Dynamic user interface * @v name Name, or NULL * @v text Text, or NULL + * @v flags Flags * @v shortcut Shortcut key - * @v is_default Item is the default item * @ret item User interface item, or NULL on failure */ struct dynamic_item * add_dynui_item ( struct dynamic_ui *dynui, const char *name, const char *text, - int shortcut, int is_default ) { + unsigned int flags, int shortcut ) { struct dynamic_item *item; size_t name_len; size_t text_len; @@ -132,8 +132,8 @@ struct dynamic_item * add_dynui_item ( struct dynamic_ui *dynui, strcpy ( text_copy, text ); item->text = text_copy; item->index = dynui->count++; + item->flags = flags; item->shortcut = shortcut; - item->is_default = is_default; /* Add to list of items */ list_add_tail ( &item->list, &dynui->items ); diff --git a/src/hci/commands/dynui_cmd.c b/src/hci/commands/dynui_cmd.c index dbaa669..557c5db 100644 --- a/src/hci/commands/dynui_cmd.c +++ b/src/hci/commands/dynui_cmd.c @@ -148,6 +148,7 @@ static int item_exec ( int argc, char **argv ) { struct item_options opts; struct dynamic_ui *dynui; struct dynamic_item *item; + unsigned int flags = 0; char *name = NULL; char *text = NULL; int rc; @@ -174,8 +175,10 @@ static int item_exec ( int argc, char **argv ) { goto err_parse_dynui; /* Add dynamic user interface item */ - item = add_dynui_item ( dynui, name, ( text ? text : "" ), - opts.key, opts.is_default ); + if ( opts.is_default ) + flags |= DYNUI_DEFAULT; + item = add_dynui_item ( dynui, name, ( text ? text : "" ), flags, + opts.key ); if ( ! item ) { rc = -ENOMEM; goto err_add_dynui_item; diff --git a/src/hci/tui/menu_ui.c b/src/hci/tui/menu_ui.c index 00cdab8..b7b52ee 100644 --- a/src/hci/tui/menu_ui.c +++ b/src/hci/tui/menu_ui.c @@ -267,7 +267,7 @@ int show_menu ( struct dynamic_ui *dynui, unsigned long timeout, if ( strcmp ( select, item->name ) == 0 ) ui.scroll.current = ui.scroll.count; } else { - if ( item->is_default ) + if ( item->flags & DYNUI_DEFAULT ) ui.scroll.current = ui.scroll.count; } } diff --git a/src/include/ipxe/dynui.h b/src/include/ipxe/dynui.h index f38d448..5ba0070 100644 --- a/src/include/ipxe/dynui.h +++ b/src/include/ipxe/dynui.h @@ -35,17 +35,21 @@ struct dynamic_item { const char *text; /** Index */ unsigned int index; + /** Flags */ + unsigned int flags; /** Shortcut key */ int shortcut; - /** Is default item */ - int is_default; }; +/** Dynamic user interface item is default selection */ +#define DYNUI_DEFAULT 0x0001 + extern struct dynamic_ui * create_dynui ( const char *name, const char *title ); extern struct dynamic_item * add_dynui_item ( struct dynamic_ui *dynui, const char *name, - const char *text, int shortcut, - int is_default ); + const char *text, + unsigned int flags, + int shortcut ); extern void destroy_dynui ( struct dynamic_ui *dynui ); extern struct dynamic_ui * find_dynui ( const char *name ); extern struct dynamic_item * dynui_item ( struct dynamic_ui *dynui, -- cgit v1.1