aboutsummaryrefslogtreecommitdiff
path: root/src/include/ipxe/dynui.h
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2024-06-20 14:24:53 -0700
committerMichael Brown <mcb30@ipxe.org>2024-06-20 14:26:06 -0700
commit5719cde838b6e86a02831373dae81642653b872f (patch)
treee4159ca36ce356a80df7909dfabeaececc6fefdc /src/include/ipxe/dynui.h
parent122777f789a68512593e4aa6da3ace3d0d8664ec (diff)
downloadipxe-5719cde838b6e86a02831373dae81642653b872f.zip
ipxe-5719cde838b6e86a02831373dae81642653b872f.tar.gz
ipxe-5719cde838b6e86a02831373dae81642653b872f.tar.bz2
[dynui] Generalise the concept of a menu to a dynamic user interface
We currently have an abstract model of a dynamic menu as a list of items, each of which has a name, a description, and assorted metadata such as a shortcut key. The "menu" and "item" commands construct representations in this abstract model, and the "choose" command then presents the items as a single-choice menu, with the selected item's name used as the output value. This same abstraction may be used to model a dynamic form as a list of editable items, each of which has a corresponding setting name, an optional description label, and assorted metadata such as a shortcut key. By defining a "form" command as an alias for the "menu" command, we could construct and present forms using commands such as: #!ipxe form Login to ${url} item username Username or email address item --secret password Password present or #!ipxe form Configure IPv4 networking for ${netX/ifname} item netX/ip IPv4 address item netX/netmask Subnet mask item netX/gateway Gateway address item netX/dns DNS server address present Reusing the same abstract model for both menus and forms allows us to minimise the increase in code size, since the implementation of the "form" and "item" commands is essentially zero-cost. Rename everything within the abstract data model from "menu" to "dynamic user interface" to reflect this generalisation. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/dynui.h')
-rw-r--r--src/include/ipxe/dynui.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/include/ipxe/dynui.h b/src/include/ipxe/dynui.h
new file mode 100644
index 0000000..25124a3
--- /dev/null
+++ b/src/include/ipxe/dynui.h
@@ -0,0 +1,50 @@
+#ifndef _IPXE_DYNUI_H
+#define _IPXE_DYNUI_H
+
+/** @file
+ *
+ * Dynamic user interfaces
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/list.h>
+
+/** A dynamic user interface */
+struct dynamic_ui {
+ /** List of dynamic user interfaces */
+ struct list_head list;
+ /** Name */
+ const char *name;
+ /** Title */
+ const char *title;
+ /** Dynamic user interface items */
+ struct list_head items;
+};
+
+/** A dynamic user interface item */
+struct dynamic_item {
+ /** List of dynamic user interface items */
+ struct list_head list;
+ /** Name */
+ const char *name;
+ /** Text */
+ const char *text;
+ /** Shortcut key */
+ int shortcut;
+ /** Is default item */
+ int is_default;
+};
+
+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 );
+extern void destroy_dynui ( struct dynamic_ui *dynui );
+extern struct dynamic_ui * find_dynui ( const char *name );
+extern int show_menu ( struct dynamic_ui *dynui, unsigned long timeout,
+ const char *select, struct dynamic_item **selected );
+
+#endif /* _IPXE_DYNUI_H */