menu: only timeout when menu is displayed

Make the menu timeout apply only when prompt flag is set and after the
menu is displayed. This allows auto boot to work no matter whether prompt
is set or cleared. Use the default selection if the menu times out.

This also fixes the timeout value given to readline_into_buffer to be
seconds instead of 10th of seconds.

Old behavior:

if prompt
  display menu and wait for choice
else
  wait for timeout
  if key pressed
    display menu and wait for choice
  else
    exit command

New behavior:

if prompt
  display menu
  if key pressed
    wait for choice
  else
    boot default entry on timeout
else
  boot default entry

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
This commit is contained in:
Rob Herring 2012-03-28 05:51:32 +00:00 committed by Wolfgang Denk
parent 172a3a82af
commit 8594753ba0

View file

@ -170,32 +170,6 @@ static inline struct menu_item *menu_item_by_key(struct menu *m,
return menu_items_iter(m, menu_item_key_match, item_key);
}
/*
* Wait for the user to hit a key according to the timeout set for the menu.
* Returns 1 if the user hit a key, or 0 if the timeout expired.
*/
static inline int menu_interrupted(struct menu *m)
{
if (!m->timeout)
return 0;
if (abortboot(m->timeout/10))
return 1;
return 0;
}
/*
* Checks whether or not the default menu item should be used without
* prompting for a user choice. If the menu is set to always prompt, or the
* user hits a key during the timeout period, return 0. Otherwise, return 1 to
* indicate we should use the default menu item.
*/
static inline int menu_use_default(struct menu *m)
{
return !m->prompt && !menu_interrupted(m);
}
/*
* Set *choice to point to the default item's data, if any default item was
* set, and returns 1. If no default item was set, returns -ENOENT.
@ -231,7 +205,7 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)
menu_display(m);
readret = readline_into_buffer("Enter choice: ", cbuf,
m->timeout);
m->timeout / 10);
if (readret >= 0) {
choice_item = menu_item_by_key(m, cbuf);
@ -240,10 +214,8 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)
printf("%s not found\n", cbuf);
m->timeout = 0;
}
} else {
puts("^C\n");
return -EINTR;
}
} else
return menu_default_choice(m, choice);
}
*choice = choice_item->data;
@ -300,7 +272,7 @@ int menu_get_choice(struct menu *m, void **choice)
if (!m || !choice)
return -EINVAL;
if (menu_use_default(m))
if (!m->prompt)
return menu_default_choice(m, choice);
return menu_interactive_choice(m, choice);