mirror of https://github.com/ipxe/ipxe.git
[hci] Rename "item" command's first parameter from "label" to "name"
Switch terminology for the "item" command from "item <label> <text>" to "item <name> <text>", in preparation for repurposing the "item" command to cover interactive forms as well as menus. Since this renaming affects only a positional parameter, it does not break compatibility with any existing scripts. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1243/head
parent
bf98eae5da
commit
76e0933d78
|
@ -94,20 +94,20 @@ struct menu * create_menu ( const char *name, const char *title ) {
|
||||||
* Add menu item
|
* Add menu item
|
||||||
*
|
*
|
||||||
* @v menu Menu
|
* @v menu Menu
|
||||||
* @v label Label, or NULL
|
* @v name Name, or NULL
|
||||||
* @v text Text, or NULL
|
* @v text Text, or NULL
|
||||||
* @v shortcut Shortcut key
|
* @v shortcut Shortcut key
|
||||||
* @v is_default Item is the default item
|
* @v is_default Item is the default item
|
||||||
* @ret item Menu item, or NULL on failure
|
* @ret item Menu item, or NULL on failure
|
||||||
*/
|
*/
|
||||||
struct menu_item * add_menu_item ( struct menu *menu, const char *label,
|
struct menu_item * add_menu_item ( struct menu *menu, const char *name,
|
||||||
const char *text, int shortcut,
|
const char *text, int shortcut,
|
||||||
int is_default ) {
|
int is_default ) {
|
||||||
size_t label_len;
|
size_t name_len;
|
||||||
size_t text_len;
|
size_t text_len;
|
||||||
size_t len;
|
size_t len;
|
||||||
struct menu_item *item;
|
struct menu_item *item;
|
||||||
char *label_copy;
|
char *name_copy;
|
||||||
char *text_copy;
|
char *text_copy;
|
||||||
|
|
||||||
/* Use empty text if none given */
|
/* Use empty text if none given */
|
||||||
|
@ -115,19 +115,19 @@ struct menu_item * add_menu_item ( struct menu *menu, const char *label,
|
||||||
text = "";
|
text = "";
|
||||||
|
|
||||||
/* Allocate item */
|
/* Allocate item */
|
||||||
label_len = ( label ? ( strlen ( label ) + 1 /* NUL */ ) : 0 );
|
name_len = ( name ? ( strlen ( name ) + 1 /* NUL */ ) : 0 );
|
||||||
text_len = ( strlen ( text ) + 1 /* NUL */ );
|
text_len = ( strlen ( text ) + 1 /* NUL */ );
|
||||||
len = ( sizeof ( *item ) + label_len + text_len );
|
len = ( sizeof ( *item ) + name_len + text_len );
|
||||||
item = zalloc ( len );
|
item = zalloc ( len );
|
||||||
if ( ! item )
|
if ( ! item )
|
||||||
return NULL;
|
return NULL;
|
||||||
label_copy = ( ( void * ) ( item + 1 ) );
|
name_copy = ( ( void * ) ( item + 1 ) );
|
||||||
text_copy = ( label_copy + label_len );
|
text_copy = ( name_copy + name_len );
|
||||||
|
|
||||||
/* Initialise item */
|
/* Initialise item */
|
||||||
if ( label ) {
|
if ( name ) {
|
||||||
strcpy ( label_copy, label );
|
strcpy ( name_copy, name );
|
||||||
item->label = label_copy;
|
item->name = name_copy;
|
||||||
}
|
}
|
||||||
strcpy ( text_copy, text );
|
strcpy ( text_copy, text );
|
||||||
item->text = text_copy;
|
item->text = text_copy;
|
||||||
|
|
|
@ -135,7 +135,7 @@ static struct option_descriptor item_opts[] = {
|
||||||
/** "item" command descriptor */
|
/** "item" command descriptor */
|
||||||
static struct command_descriptor item_cmd =
|
static struct command_descriptor item_cmd =
|
||||||
COMMAND_DESC ( struct item_options, item_opts, 0, MAX_ARGUMENTS,
|
COMMAND_DESC ( struct item_options, item_opts, 0, MAX_ARGUMENTS,
|
||||||
"[<label> [<text>]]" );
|
"[<name> [<text>]]" );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "item" command
|
* The "item" command
|
||||||
|
@ -148,7 +148,7 @@ static int item_exec ( int argc, char **argv ) {
|
||||||
struct item_options opts;
|
struct item_options opts;
|
||||||
struct menu *menu;
|
struct menu *menu;
|
||||||
struct menu_item *item;
|
struct menu_item *item;
|
||||||
char *label = NULL;
|
char *name = NULL;
|
||||||
char *text = NULL;
|
char *text = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -156,9 +156,9 @@ static int item_exec ( int argc, char **argv ) {
|
||||||
if ( ( rc = parse_options ( argc, argv, &item_cmd, &opts ) ) != 0 )
|
if ( ( rc = parse_options ( argc, argv, &item_cmd, &opts ) ) != 0 )
|
||||||
goto err_parse_options;
|
goto err_parse_options;
|
||||||
|
|
||||||
/* Parse label, if present */
|
/* Parse name, if present */
|
||||||
if ( ! opts.is_gap )
|
if ( ! opts.is_gap )
|
||||||
label = argv[optind++]; /* May be NULL */
|
name = argv[optind++]; /* May be NULL */
|
||||||
|
|
||||||
/* Parse text, if present */
|
/* Parse text, if present */
|
||||||
if ( optind < argc ) {
|
if ( optind < argc ) {
|
||||||
|
@ -174,7 +174,7 @@ static int item_exec ( int argc, char **argv ) {
|
||||||
goto err_parse_menu;
|
goto err_parse_menu;
|
||||||
|
|
||||||
/* Add menu item */
|
/* Add menu item */
|
||||||
item = add_menu_item ( menu, label, ( text ? text : "" ),
|
item = add_menu_item ( menu, name, ( text ? text : "" ),
|
||||||
opts.key, opts.is_default );
|
opts.key, opts.is_default );
|
||||||
if ( ! item ) {
|
if ( ! item ) {
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
|
@ -257,7 +257,7 @@ static int choose_exec ( int argc, char **argv ) {
|
||||||
|
|
||||||
/* Store setting */
|
/* Store setting */
|
||||||
if ( ( rc = storef_setting ( setting.settings, &setting.setting,
|
if ( ( rc = storef_setting ( setting.settings, &setting.setting,
|
||||||
item->label ) ) != 0 ) {
|
item->name ) ) != 0 ) {
|
||||||
printf ( "Could not store \"%s\": %s\n",
|
printf ( "Could not store \"%s\": %s\n",
|
||||||
setting.setting.name, strerror ( rc ) );
|
setting.setting.name, strerror ( rc ) );
|
||||||
goto err_store;
|
goto err_store;
|
||||||
|
|
|
@ -99,7 +99,7 @@ static void draw_menu_item ( struct menu_ui *ui, unsigned int index ) {
|
||||||
if ( item ) {
|
if ( item ) {
|
||||||
|
|
||||||
/* Draw separators in a different colour */
|
/* Draw separators in a different colour */
|
||||||
if ( ! item->label )
|
if ( ! item->name )
|
||||||
color_set ( CPAIR_SEPARATOR, NULL );
|
color_set ( CPAIR_SEPARATOR, NULL );
|
||||||
|
|
||||||
/* Highlight if this is the selected item */
|
/* Highlight if this is the selected item */
|
||||||
|
@ -225,7 +225,7 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ui->scroll.current = i;
|
ui->scroll.current = i;
|
||||||
if ( item->label ) {
|
if ( item->name ) {
|
||||||
chosen = 1;
|
chosen = 1;
|
||||||
} else {
|
} else {
|
||||||
move = +1;
|
move = +1;
|
||||||
|
@ -239,7 +239,7 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
|
||||||
while ( move ) {
|
while ( move ) {
|
||||||
move = jump_scroll_move ( &ui->scroll, move );
|
move = jump_scroll_move ( &ui->scroll, move );
|
||||||
item = menu_item ( ui->menu, ui->scroll.current );
|
item = menu_item ( ui->menu, ui->scroll.current );
|
||||||
if ( item->label )
|
if ( item->name )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
|
||||||
/* Record selection */
|
/* Record selection */
|
||||||
item = menu_item ( ui->menu, ui->scroll.current );
|
item = menu_item ( ui->menu, ui->scroll.current );
|
||||||
assert ( item != NULL );
|
assert ( item != NULL );
|
||||||
assert ( item->label != NULL );
|
assert ( item->name != NULL );
|
||||||
*selected = item;
|
*selected = item;
|
||||||
|
|
||||||
} while ( ( rc == 0 ) && ! chosen );
|
} while ( ( rc == 0 ) && ! chosen );
|
||||||
|
@ -275,7 +275,7 @@ int show_menu ( struct menu *menu, unsigned long timeout,
|
||||||
struct menu_item *item;
|
struct menu_item *item;
|
||||||
struct menu_ui ui;
|
struct menu_ui ui;
|
||||||
char buf[ MENU_COLS + 1 /* NUL */ ];
|
char buf[ MENU_COLS + 1 /* NUL */ ];
|
||||||
int labelled_count = 0;
|
int named_count = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Initialise UI */
|
/* Initialise UI */
|
||||||
|
@ -284,12 +284,12 @@ int show_menu ( struct menu *menu, unsigned long timeout,
|
||||||
ui.scroll.rows = MENU_ROWS;
|
ui.scroll.rows = MENU_ROWS;
|
||||||
ui.timeout = timeout;
|
ui.timeout = timeout;
|
||||||
list_for_each_entry ( item, &menu->items, list ) {
|
list_for_each_entry ( item, &menu->items, list ) {
|
||||||
if ( item->label ) {
|
if ( item->name ) {
|
||||||
if ( ! labelled_count )
|
if ( ! named_count )
|
||||||
ui.scroll.current = ui.scroll.count;
|
ui.scroll.current = ui.scroll.count;
|
||||||
labelled_count++;
|
named_count++;
|
||||||
if ( select ) {
|
if ( select ) {
|
||||||
if ( strcmp ( select, item->label ) == 0 )
|
if ( strcmp ( select, item->name ) == 0 )
|
||||||
ui.scroll.current = ui.scroll.count;
|
ui.scroll.current = ui.scroll.count;
|
||||||
} else {
|
} else {
|
||||||
if ( item->is_default )
|
if ( item->is_default )
|
||||||
|
@ -298,10 +298,10 @@ int show_menu ( struct menu *menu, unsigned long timeout,
|
||||||
}
|
}
|
||||||
ui.scroll.count++;
|
ui.scroll.count++;
|
||||||
}
|
}
|
||||||
if ( ! labelled_count ) {
|
if ( ! named_count ) {
|
||||||
/* Menus with no labelled items cannot be selected
|
/* Menus with no named items cannot be selected from,
|
||||||
* from, and will seriously confuse the navigation
|
* and will seriously confuse the navigation logic.
|
||||||
* logic. Refuse to display any such menus.
|
* Refuse to display any such menus.
|
||||||
*/
|
*/
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ struct menu {
|
||||||
struct menu_item {
|
struct menu_item {
|
||||||
/** List of menu items */
|
/** List of menu items */
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
/** Label */
|
/** Name */
|
||||||
const char *label;
|
const char *name;
|
||||||
/** Text */
|
/** Text */
|
||||||
const char *text;
|
const char *text;
|
||||||
/** Shortcut key */
|
/** Shortcut key */
|
||||||
|
@ -38,7 +38,7 @@ struct menu_item {
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct menu * create_menu ( const char *name, const char *title );
|
extern struct menu * create_menu ( const char *name, const char *title );
|
||||||
extern struct menu_item * add_menu_item ( struct menu *menu, const char *label,
|
extern struct menu_item * add_menu_item ( struct menu *menu, const char *name,
|
||||||
const char *text, int shortcut,
|
const char *text, int shortcut,
|
||||||
int is_default );
|
int is_default );
|
||||||
extern void destroy_menu ( struct menu *menu );
|
extern void destroy_menu ( struct menu *menu );
|
||||||
|
|
Loading…
Reference in New Issue