Browse Source

[menu] Add "--default" option to "choose" command

Suggested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
838a76a042
3 changed files with 16 additions and 7 deletions
  1. 7
    3
      src/hci/commands/menu_cmd.c
  2. 8
    3
      src/hci/tui/menu_ui.c
  3. 1
    1
      src/include/ipxe/menu.h

+ 7
- 3
src/hci/commands/menu_cmd.c View File

194
 	const char *menu;
194
 	const char *menu;
195
 	/** Timeout */
195
 	/** Timeout */
196
 	unsigned int timeout;
196
 	unsigned int timeout;
197
+	/** Default selection */
198
+	const char *select;
197
 	/** Keep menu */
199
 	/** Keep menu */
198
 	int keep;
200
 	int keep;
199
 };
201
 };
202
 static struct option_descriptor choose_opts[] = {
204
 static struct option_descriptor choose_opts[] = {
203
 	OPTION_DESC ( "menu", 'm', required_argument,
205
 	OPTION_DESC ( "menu", 'm', required_argument,
204
 		      struct choose_options, menu, parse_string ),
206
 		      struct choose_options, menu, parse_string ),
207
+	OPTION_DESC ( "default", 'd', required_argument,
208
+		      struct choose_options, select, parse_string ),
205
 	OPTION_DESC ( "timeout", 't', required_argument,
209
 	OPTION_DESC ( "timeout", 't', required_argument,
206
 		      struct choose_options, timeout, parse_integer ),
210
 		      struct choose_options, timeout, parse_integer ),
207
 	OPTION_DESC ( "keep", 'k', no_argument,
211
 	OPTION_DESC ( "keep", 'k', no_argument,
211
 /** "choose" command descriptor */
215
 /** "choose" command descriptor */
212
 static struct command_descriptor choose_cmd =
216
 static struct command_descriptor choose_cmd =
213
 	COMMAND_DESC ( struct choose_options, choose_opts, 1, 1,
217
 	COMMAND_DESC ( struct choose_options, choose_opts, 1, 1,
214
-		       "[--menu <menu>] [--timeout <timeout>] [--keep] "
215
-		       "<setting>" );
218
+		       "[--menu <menu>] [--default <label>] "
219
+		       "[--timeout <timeout>] [--keep] <setting>" );
216
 
220
 
217
 /**
221
 /**
218
  * The "choose" command
222
  * The "choose" command
240
 		goto err_parse_menu;
244
 		goto err_parse_menu;
241
 
245
 
242
 	/* Show menu */
246
 	/* Show menu */
243
-	if ( ( rc = show_menu ( menu, opts.timeout, &item ) ) != 0 )
247
+	if ( ( rc = show_menu ( menu, opts.timeout, opts.select, &item ) ) != 0)
244
 		goto err_show_menu;
248
 		goto err_show_menu;
245
 
249
 
246
 	/* Store setting */
250
 	/* Store setting */

+ 8
- 3
src/hci/tui/menu_ui.c View File

303
  * @ret rc		Return status code
303
  * @ret rc		Return status code
304
  */
304
  */
305
 int show_menu ( struct menu *menu, unsigned int timeout_ms,
305
 int show_menu ( struct menu *menu, unsigned int timeout_ms,
306
-		struct menu_item **selected ) {
306
+		const char *select, struct menu_item **selected ) {
307
 	struct menu_item *item;
307
 	struct menu_item *item;
308
 	struct menu_ui ui;
308
 	struct menu_ui ui;
309
 	int labelled_count = 0;
309
 	int labelled_count = 0;
318
 			if ( ! labelled_count )
318
 			if ( ! labelled_count )
319
 				ui.selected = ui.count;
319
 				ui.selected = ui.count;
320
 			labelled_count++;
320
 			labelled_count++;
321
-			if ( item->is_default )
322
-				ui.selected = ui.count;
321
+			if ( select ) {
322
+				if ( strcmp ( select, item->label ) == 0 )
323
+					ui.selected = ui.count;
324
+			} else {
325
+				if ( item->is_default )
326
+					ui.selected = ui.count;
327
+			}
323
 		}
328
 		}
324
 		ui.count++;
329
 		ui.count++;
325
 	}
330
 	}

+ 1
- 1
src/include/ipxe/menu.h View File

44
 extern void destroy_menu ( struct menu *menu );
44
 extern void destroy_menu ( struct menu *menu );
45
 extern struct menu * find_menu ( const char *name );
45
 extern struct menu * find_menu ( const char *name );
46
 extern int show_menu ( struct menu *menu, unsigned int timeout_ms,
46
 extern int show_menu ( struct menu *menu, unsigned int timeout_ms,
47
-		       struct menu_item **selected );
47
+		       const char *select, struct menu_item **selected );
48
 
48
 
49
 #endif /* _IPXE_MENU_H */
49
 #endif /* _IPXE_MENU_H */

Loading…
Cancel
Save