X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fnc-cui.c;h=88bdd0f18a0a35590609075a56fa5fb7e2946f6a;hp=5f1a5e4433555b4cb742ed2e2e3341a86760dba8;hb=0dd467aef0f1e104faf8ad5b1d4deaaf71732278;hpb=c4b4ebc4c61b7f374582c621aec846aba3795954 diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 5f1a5e4..88bdd0f 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -16,9 +16,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if defined(HAVE_CONFIG_H) #include "config.h" - -#define _GNU_SOURCE +#endif #include #include @@ -38,6 +38,7 @@ #include "nc-boot-editor.h" #include "nc-config.h" #include "nc-sysinfo.h" +#include "nc-helpscreen.h" static void cui_start(void) { @@ -246,6 +247,28 @@ void cui_show_config(struct cui *cui) cui_set_current(cui, config_screen_scr(cui->config_screen)); } +static void cui_help_exit(struct cui *cui) +{ + cui_set_current(cui, help_screen_return_scr(cui->help_screen)); + talloc_free(cui->help_screen); + cui->help_screen = NULL; +} + +void cui_show_help(struct cui *cui, const char *title, const char *text) +{ + if (!cui->current) + return; + + if (cui->help_screen) + return; + + cui->help_screen = help_screen_init(cui, cui->current, + title, text, cui_help_exit); + + if (cui->help_screen) + cui_set_current(cui, help_screen_scr(cui->help_screen)); +} + /** * cui_set_current - Set the currently active screen and redraw it. */ @@ -272,10 +295,8 @@ static bool process_global_keys(struct cui *cui, int key) { switch (key) { case 0xc: - if (cui->current && cui->current->main_ncw) { - redrawwin(cui->current->main_ncw); - wrefresh(cui->current->main_ncw); - } + if (cui->current && cui->current->main_ncw) + wrefresh(curscr); return true; } return false; @@ -298,6 +319,8 @@ static int cui_process_key(void *arg) for (;;) { int c = getch(); + pb_debug("%s: got key %d\n", __func__, c); + if (c == ERR) break; @@ -367,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); @@ -426,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); @@ -547,6 +581,11 @@ int cui_send_config(struct cui *cui, struct config *config) return discover_client_send_config(cui->client, config); } +void cui_send_reinit(struct cui *cui) +{ + discover_client_send_reinit(cui->client); +} + static struct discover_client_ops cui_client_ops = { .device_add = NULL, .boot_option_add = cui_boot_option_add,