diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-05-31 10:10:53 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-06-20 16:28:46 -0700 |
commit | f417f0b6a56956137d75c77f344d798f6b30a27c (patch) | |
tree | c87b523ab9f64a267555f20e8ffef84d40c6c87d /src/hci/commands/dynui_cmd.c | |
parent | 1c3c5e2b22ca31bbf77c39aef51671d0b6e95767 (diff) | |
download | ipxe-f417f0b6a56956137d75c77f344d798f6b30a27c.tar.gz |
[form] Add support for dynamically created interactive forms
Add support for presenting a dynamic user interface as an interactive
form, alongside the existing support for presenting a dynamic user
interface as a menu.
An interactive form may be used to allow a user to input (or edit)
values for multiple settings on a single screen, as a user-friendly
alternative to prompting for setting values via the "read" command.
In the present implementation, all input fields must fit on a single
screen (with no scrolling), and the only supported widget type is an
editable text box.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci/commands/dynui_cmd.c')
-rw-r--r-- | src/hci/commands/dynui_cmd.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/hci/commands/dynui_cmd.c b/src/hci/commands/dynui_cmd.c index 5aed3d034..d4446dc7c 100644 --- a/src/hci/commands/dynui_cmd.c +++ b/src/hci/commands/dynui_cmd.c @@ -126,6 +126,8 @@ struct item_options { static struct option_descriptor item_opts[] = { OPTION_DESC ( "menu", 'm', required_argument, struct item_options, dynui, parse_string ), + OPTION_DESC ( "form", 'f', required_argument, + struct item_options, dynui, parse_string ), OPTION_DESC ( "key", 'k', required_argument, struct item_options, key, parse_key ), OPTION_DESC ( "default", 'd', no_argument, @@ -287,6 +289,62 @@ static int choose_exec ( int argc, char **argv ) { return rc; } +/** "present" options */ +struct present_options { + /** Dynamic user interface name */ + char *dynui; + /** Keep dynamic user interface */ + int keep; +}; + +/** "present" option list */ +static struct option_descriptor present_opts[] = { + OPTION_DESC ( "form", 'f', required_argument, + struct present_options, dynui, parse_string ), + OPTION_DESC ( "keep", 'k', no_argument, + struct present_options, keep, parse_flag ), +}; + +/** "present" command descriptor */ +static struct command_descriptor present_cmd = + COMMAND_DESC ( struct present_options, present_opts, 0, 0, NULL ); + +/** + * The "present" command + * + * @v argc Argument count + * @v argv Argument list + * @ret rc Return status code + */ +static int present_exec ( int argc, char **argv ) { + struct present_options opts; + struct dynamic_ui *dynui; + int rc; + + /* Parse options */ + if ( ( rc = parse_options ( argc, argv, &present_cmd, &opts ) ) != 0 ) + goto err_parse_options; + + /* Identify dynamic user interface */ + if ( ( rc = parse_dynui ( opts.dynui, &dynui ) ) != 0 ) + goto err_parse_dynui; + + /* Show as form */ + if ( ( rc = show_form ( dynui ) ) != 0 ) + goto err_show_form; + + /* Success */ + rc = 0; + + err_show_form: + /* Destroy dynamic user interface, if applicable */ + if ( ! opts.keep ) + destroy_dynui ( dynui ); + err_parse_dynui: + err_parse_options: + return rc; +} + /** Dynamic user interface commands */ struct command dynui_commands[] __command = { { @@ -294,6 +352,10 @@ struct command dynui_commands[] __command = { .exec = dynui_exec, }, { + .name = "form", + .exec = dynui_exec, + }, + { .name = "item", .exec = item_exec, }, @@ -301,4 +363,8 @@ struct command dynui_commands[] __command = { .name = "choose", .exec = choose_exec, }, + { + .name = "present", + .exec = present_exec, + }, }; |