X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fnc-cui.c;h=0522bdfe2d900bb38531f78c828c26d9e7a55bcf;hp=3abeac3e2ff29d41a2ecfd34f552339d5637523e;hb=a73d5c25b9de93289b620a54d2ab2c4b4634c793;hpb=c78f9ec47ba92b74698dacdae963dbbefd9b676f diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 3abeac3..0522bdf 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -92,16 +92,30 @@ static bool lockdown_active(void) #endif } +static void cui_set_curses_options(bool curses_mode) +{ + if (curses_mode) { + cbreak(); /* Disable line buffering. */ + noecho(); /* Disable getch() echo. */ + nonl(); /* Disable new-line translation. */ + intrflush(stdscr, FALSE); /* Disable interrupt flush. */ + curs_set(0); /* Make cursor invisible */ + nodelay(stdscr, TRUE); /* Enable non-blocking getch() */ + } else { + nocbreak(); /* Enable line buffering. */ + echo(); /* Enable getch() echo. */ + nl(); /* Enable new-line translation. */ + intrflush(stdscr, TRUE); /* Enable interrupt flush. */ + curs_set(1); /* Make cursor visible */ + nodelay(stdscr, FALSE); /* Disable non-blocking getch() */ + } +} + static void cui_start(void) { initscr(); /* Initialize ncurses. */ - cbreak(); /* Disable line buffering. */ - noecho(); /* Disable getch() echo. */ keypad(stdscr, TRUE); /* Enable num keypad keys. */ - nonl(); /* Disable new-line translation. */ - intrflush(stdscr, FALSE); /* Disable interrupt flush. */ - curs_set(0); /* Make cursor invisible */ - nodelay(stdscr, TRUE); /* Enable non-blocking getch() */ + cui_set_curses_options(true); /* We may be operating with an incorrect $TERM type; in this case * the keymappings will be slightly broken. We want at least @@ -219,6 +233,17 @@ void cui_on_exit(struct pmenu *menu) talloc_free(sh_cmd); } +/** + * cui_abort_on_exit - Force an exit of the main loop on menu exit. + * This is mainly for lockdown situations where + * the exit then triggers an expected reboot. + */ +void cui_abort_on_exit(struct pmenu *menu) +{ + struct cui *cui = cui_from_pmenu(menu); + cui->abort = 1; +} + /** * cui_run_cmd - A generic cb to run the supplied command. */ @@ -298,6 +323,51 @@ static int cui_boot(struct pmenu_item *item) return 0; } +static int menu_sysinfo_execute(struct pmenu_item *item) +{ + cui_show_sysinfo(cui_from_item(item)); + return 0; +} + +static int menu_config_execute(struct pmenu_item *item) +{ + cui_show_config(cui_from_item(item)); + return 0; +} + +static int menu_lang_execute(struct pmenu_item *item) +{ + cui_show_lang(cui_from_item(item)); + return 0; +} + +static int menu_statuslog_execute(struct pmenu_item *item) +{ + cui_show_statuslog(cui_from_item(item)); + return 0; +} + +static int menu_reinit_execute(struct pmenu_item *item) +{ + if (cui_from_item(item)->client) + cui_send_reinit(cui_from_item(item)); + return 0; +} + +static int menu_add_url_execute(struct pmenu_item *item) +{ + if (cui_from_item(item)->client) + cui_show_add_url(cui_from_item(item)); + return 0; +} + +static int menu_plugin_execute(struct pmenu_item *item) +{ + if (cui_from_item(item)->client) + cui_show_plugin_menu(cui_from_item(item)); + return 0; +} + static void cui_boot_editor_on_exit(struct cui *cui, struct pmenu_item *item, struct pb_boot_data *bd) @@ -639,6 +709,12 @@ static int cui_process_key(void *arg) } } + if (cui->preboot_mode) { + /* Turn curses options back on if the user interacts */ + cui->preboot_mode = false; + cui_set_curses_options(true); + } + if (!cui->has_input && key_cancels_boot(c)) { cui->has_input = true; if (cui->client) { @@ -815,10 +891,10 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt, result = set_menu_items(cui->main->ncm, NULL); for (j = 0 ; j < cui->main->item_count; j++) { item = item_userptr(cui->main->items[j]); - if (strncmp(item->nci->name.str, "Plugins", strlen("Plugins"))) + if (item->on_execute != menu_plugin_execute) continue; cui->n_plugins++; - char *label = talloc_asprintf(item, "Plugins (%u)", + char *label = talloc_asprintf(item, _("Plugins (%u)"), cui->n_plugins); pmenu_item_update(item, label); talloc_free(label); @@ -969,8 +1045,21 @@ static void cui_update_status(struct status *status, void *arg) statuslog_append_steal(cui, cui->statuslog, status); /* Ignore status messages from the backlog */ - if (!status->backlog) - nc_scr_status_printf(cui->current, "%s", status->message); + if (status->backlog) + return; + + nc_scr_status_printf(cui->current, "%s", status->message); + + if (cui->preboot_mode && + (!status->boot_active || status->type == STATUS_ERROR)) { + cui_set_curses_options(true); + cui->preboot_mode = false; + } else { + cui->preboot_mode = status->boot_active && + status->type == STATUS_INFO; + if (cui->preboot_mode) + cui_set_curses_options(false); + } } /* @@ -1103,10 +1192,10 @@ static int cui_plugins_remove(void *arg) set_menu_items(cui->main->ncm, NULL); for (i = 0; i < cui->main->item_count; i++) { item = item_userptr(cui->main->items[i]); - if (strncmp(item->nci->name.str, "Plugins", strlen("Plugins"))) + if (item->on_execute != menu_plugin_execute) continue; cui->n_plugins = 0; - pmenu_item_update(item, "Plugins (0)"); + pmenu_item_update(item, _("Plugins (0)")); break; } @@ -1243,51 +1332,6 @@ void cui_send_reinit(struct cui *cui) discover_client_send_reinit(cui->client); } -static int menu_sysinfo_execute(struct pmenu_item *item) -{ - cui_show_sysinfo(cui_from_item(item)); - return 0; -} - -static int menu_config_execute(struct pmenu_item *item) -{ - cui_show_config(cui_from_item(item)); - return 0; -} - -static int menu_lang_execute(struct pmenu_item *item) -{ - cui_show_lang(cui_from_item(item)); - return 0; -} - -static int menu_statuslog_execute(struct pmenu_item *item) -{ - cui_show_statuslog(cui_from_item(item)); - return 0; -} - -static int menu_reinit_execute(struct pmenu_item *item) -{ - if (cui_from_item(item)->client) - cui_send_reinit(cui_from_item(item)); - return 0; -} - -static int menu_add_url_execute(struct pmenu_item *item) -{ - if (cui_from_item(item)->client) - cui_show_add_url(cui_from_item(item)); - return 0; -} - -static int menu_plugin_execute(struct pmenu_item *item) -{ - if (cui_from_item(item)->client) - cui_show_plugin_menu(cui_from_item(item)); - return 0; -} - /** * pb_mm_init - Setup the main menu instance. */ @@ -1298,7 +1342,7 @@ static struct pmenu *main_menu_init(struct cui *cui) int result; bool lockdown = lockdown_active(); - m = pmenu_init(cui, 9, cui_on_exit); + m = pmenu_init(cui, 9, lockdown ? cui_abort_on_exit : cui_on_exit); if (!m) { pb_log_fn("failed\n"); return NULL;