summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-03-03 18:15:31 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-03-03 18:15:31 +0800
commit67d0ca0764e5ab9a0d0e5baa5bf062d0ac5c8596 (patch)
treed9cbfa9de19a06bfcd7b633884202041974361e8 /ui
parent5a604632c54671d65ccb3398a928c0c38c5f13ad (diff)
downloadtalos-petitboot-67d0ca0764e5ab9a0d0e5baa5bf062d0ac5c8596.tar.gz
talos-petitboot-67d0ca0764e5ab9a0d0e5baa5bf062d0ac5c8596.zip
ui/ncurses: Ensure that the selected menu item is visible
When adding new items to the petitboot menu, we need to ensure that the scroll position of the menu includes the currently-selected item. This change adds a call to set_top_row, calculated from the selected item index, and the number of rows in the menu. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/ncurses/nc-cui.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
index 650e903..fd90419 100644
--- a/ui/ncurses/nc-cui.c
+++ b/ui/ncurses/nc-cui.c
@@ -390,13 +390,14 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
struct cui *cui = cui_from_arg(arg);
struct cui_opt_data *cod;
unsigned int insert_pt;
+ int result, rows, cols;
struct pmenu_item *i;
ITEM *selected;
- int result;
pb_debug("%s: %p %s\n", __func__, opt, opt->id);
selected = current_item(cui->main->ncm);
+ menu_format(cui->main->ncm, &rows, &cols);
if (cui->current == &cui->main->scr)
nc_scr_unpost(cui->current);
@@ -449,10 +450,20 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
item_count(cui->main->ncm) + 1);
}
- /* FIXME: need to make item visible somehow */
- menu_driver(cui->main->ncm, REQ_SCR_UPAGE);
- menu_driver(cui->main->ncm, REQ_SCR_DPAGE);
- set_current_item(cui->main->ncm, selected);
+ if (!item_visible(selected)) {
+ int idx, top;
+
+ top = top_row(cui->main->ncm);
+ idx = item_index(selected);
+
+ /* If our index is above the current top row, align
+ * us to the new top. Otherwise, align us to the new
+ * bottom */
+ top = top < idx ? idx - rows : idx;
+
+ set_top_row(cui->main->ncm, top);
+ set_current_item(cui->main->ncm, selected);
+ }
if (cui->current == &cui->main->scr)
nc_scr_post(cui->current);
OpenPOWER on IntegriCloud