diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-03-12 14:59:03 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-04-10 11:18:24 +0800 |
commit | 1bbd230d618162ccd5ea97540a413c766a07c0cb (patch) | |
tree | 8bf596660165d015328d54930ba2f91ed4c4effd /ui/ncurses/generic-main.c | |
parent | e07bd59ad5f4ba9cd113f8dfdcc72e6ca2e69819 (diff) | |
download | talos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.tar.gz talos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.zip |
ui/ncurses: Separate menu item creation & initialisation from insertion
Currently, the menu item creation is has two main functions:
pmenu_item_alloc and pmenu_item_setup. The latter does initialisation
(it sets item->name), and inserts the item into the menu. We have
pmenu_item_init to combine this into one, but that means we need to do
further initialisation (eg, to set on_execute) after the item has been
added to the menu.
Instead, this change use a more direct _create and _insert interface.
Create does the allocation and initialisation, while _insert does the
actual insertion.
This means new_item failures will be detected at creation time, rather
than during pmenu_insert. Also, we're now insert a completely-populated
item into the menu, rather than populating on_edit, on_execute and data
after insertion.
Because we can detect errors from creation (ie, from new_item failing),
we add handling code to cui_boot_option_add and cui_boot_editor_on_exit.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui/ncurses/generic-main.c')
-rw-r--r-- | ui/ncurses/generic-main.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 67b0b61..0d0a38a 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -201,16 +201,25 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui) "Enter=accept, e=edit, n=new, x=exit, h=help"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); - i = pmenu_item_init(m, 0, " "); + i = pmenu_item_create(m, " "); item_opts_off(i->nci, O_SELECTABLE); - i = pmenu_item_init(m, 1, "System information"); + pmenu_item_insert(m, i, 0); + + i = pmenu_item_create(m, "System information"); i->on_execute = pmenu_sysinfo; - i = pmenu_item_init(m, 2, "System configuration"); + pmenu_item_insert(m, i, 1); + + i = pmenu_item_create(m, "System configuration"); i->on_execute = pmenu_config; - i = pmenu_item_init(m, 3, "Rescan devices"); + pmenu_item_insert(m, i, 2); + + i = pmenu_item_create(m, "Rescan devices"); i->on_execute = pmenu_reinit; - i = pmenu_item_init(m, 4, "Exit to shell"); + pmenu_item_insert(m, i, 3); + + i = pmenu_item_create(m, "Exit to shell"); i->on_execute = pmenu_exit_cb; + pmenu_item_insert(m, i, 4); result = pmenu_setup(m); |