]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[dynui] Allow for multiple flags on a user interface item
authorMichael Brown <mcb30@ipxe.org>
Thu, 20 Jun 2024 23:20:05 +0000 (16:20 -0700)
committerMichael Brown <mcb30@ipxe.org>
Thu, 20 Jun 2024 23:24:38 +0000 (16:24 -0700)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/dynui.c
src/hci/commands/dynui_cmd.c
src/hci/tui/menu_ui.c
src/include/ipxe/dynui.h

index 33218f5982f42d530ed1ab261812a260ff3b0153..3d139c02af48726f2c65a470ffae1d9b8280553d 100644 (file)
@@ -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 );
index dbaa669efc44d425cadbc03bc92799f724606f08..557c5db5d691e295a261c49afcf3104c10fb658f 100644 (file)
@@ -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;
index 00cdab8df6fd228f5b96f04ddf3ec382bd04475a..b7b52ee62180722180f3e20ec39036ea4c6295bf 100644 (file)
@@ -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;
                        }
                }
index f38d448250d87bae449a2629f62d79564b035d4e..5ba007032f5b639f9e1700b2edc921d3ff563984 100644 (file)
@@ -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,