Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k3dar/c27ac2b3fa7985f79c3b9488fa43b577 to your computer and use it in GitHub Desktop.
Save k3dar/c27ac2b3fa7985f79c3b9488fa43b577 to your computer and use it in GitHub Desktop.
iPXE menu item with disabling enter for key shortcut...
diff --git a/src/core/menu.c b/src/core/menu.c
index ab5b0c7f..b36a4bc0 100644
--- a/src/core/menu.c
+++ b/src/core/menu.c
@@ -98,11 +98,12 @@ struct menu * create_menu ( const char *name, const char *title ) {
* @v text Text, or NULL
* @v shortcut Shortcut key
* @v is_default Item is the default item
+ * @v is_noenter Key is without enter
* @ret item Menu item, or NULL on failure
*/
struct menu_item * add_menu_item ( struct menu *menu, const char *label,
const char *text, int shortcut,
- int is_default ) {
+ int is_default, int is_noenter ) {
size_t label_len;
size_t text_len;
size_t len;
@@ -133,6 +134,7 @@ struct menu_item * add_menu_item ( struct menu *menu, const char *label,
item->text = text_copy;
item->shortcut = shortcut;
item->is_default = is_default;
+ item->is_noenter = is_noenter;
/* Add to list of items */
list_add_tail ( &item->list, &menu->items );
diff --git a/src/hci/commands/menu_cmd.c b/src/hci/commands/menu_cmd.c
index 76bce869..4077cc5d 100644
--- a/src/hci/commands/menu_cmd.c
+++ b/src/hci/commands/menu_cmd.c
@@ -116,6 +116,8 @@ struct item_options {
unsigned int key;
/** Use as default */
int is_default;
+ /** Shortcut key is without enter */
+ int is_noenter;
/** Use as a separator */
int is_gap;
};
@@ -128,6 +130,8 @@ static struct option_descriptor item_opts[] = {
struct item_options, key, parse_key ),
OPTION_DESC ( "default", 'd', no_argument,
struct item_options, is_default, parse_flag ),
+ OPTION_DESC ( "noenter", 'n', no_argument,
+ struct item_options, is_noenter, parse_flag ),
OPTION_DESC ( "gap", 'g', no_argument,
struct item_options, is_gap, parse_flag ),
};
@@ -175,7 +179,7 @@ static int item_exec ( int argc, char **argv ) {
/* Add menu item */
item = add_menu_item ( menu, label, ( text ? text : "" ),
- opts.key, opts.is_default );
+ opts.key, opts.is_default, opts.is_noenter );
if ( ! item ) {
rc = -ENOMEM;
goto err_add_menu_item;
diff --git a/src/hci/tui/menu_ui.c b/src/hci/tui/menu_ui.c
index f9dd9d10..f9a930c9 100644
--- a/src/hci/tui/menu_ui.c
+++ b/src/hci/tui/menu_ui.c
@@ -226,7 +226,11 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
}
ui->scroll.current = i;
if ( item->label ) {
- chosen = 1;
+ if ( item->is_noenter ) {
+ continue;
+ } else {
+ chosen = 1;
+ }
} else {
move = +1;
}
diff --git a/src/include/ipxe/menu.h b/src/include/ipxe/menu.h
index 3cc99be4..e8aaf1bf 100644
--- a/src/include/ipxe/menu.h
+++ b/src/include/ipxe/menu.h
@@ -35,12 +35,14 @@ struct menu_item {
int shortcut;
/** Is default item */
int is_default;
+ /** Is key without enter */
+ int is_noenter;
};
extern struct menu * create_menu ( const char *name, const char *title );
extern struct menu_item * add_menu_item ( struct menu *menu, const char *label,
const char *text, int shortcut,
- int is_default );
+ int is_default, int is_noenter );
extern void destroy_menu ( struct menu *menu );
extern struct menu * find_menu ( const char *name );
extern int show_menu ( struct menu *menu, unsigned long timeout,
diff --git a/src/hci/tui/menu_ui.c b/src/hci/tui/menu_ui.c
index f9dd9d10..cf960eb3 100644
--- a/src/hci/tui/menu_ui.c
+++ b/src/hci/tui/menu_ui.c
@@ -226,7 +226,7 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
}
ui->scroll.current = i;
if ( item->label ) {
- chosen = 1;
+ continue;
} else {
move = +1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment