X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fgeneric-main.c;h=7616788d6b7ea9dd583af198a982f24091794713;hp=dfeb1ba6217a331dd3ce181d1b49282ea781e0b7;hb=a68cae0b9d1b165eef07011011a163b906e0587c;hpb=52b9db95764fcdee9195113d7df225634a19c9f4 diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index dfeb1ba..7616788 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -22,7 +22,7 @@ #include "config.h" #endif -#define _GNU_SOURCE +#include #include #include #include @@ -36,6 +36,8 @@ #include "ui/common/discover-client.h" #include "nc-cui.h" +extern const char *main_menu_help_text; + static void print_version(void) { printf("petitboot-nc (" PACKAGE_NAME ") " PACKAGE_VERSION "\n"); @@ -45,7 +47,7 @@ static void print_usage(void) { print_version(); printf( -"Usage: petitboot-nc [-d, --dry-run] [-h, --help] [-l, --log log-file]\n" +"Usage: petitboot-nc [-h, --help] [-l, --log log-file]\n" " [-s, --start-daemon] [-V, --version]\n"); } @@ -60,7 +62,6 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no}; */ struct opts { - enum opt_value dry_run; enum opt_value show_help; const char *log_file; enum opt_value start_daemon; @@ -74,7 +75,6 @@ struct opts { static int opts_parse(struct opts *opts, int argc, char *argv[]) { static const struct option long_options[] = { - {"dry-run", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, {"log", required_argument, NULL, 'l'}, {"start-daemon", no_argument, NULL, 's'}, @@ -96,9 +96,6 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) break; switch (c) { - case 'd': - opts->dry_run = opt_yes; - break; case 'h': opts->show_help = opt_yes; break; @@ -131,29 +128,16 @@ struct pb_cui { struct cui *cui; }; -static struct pb_cui *pb_from_cui(struct cui *cui) +static int pmenu_sysinfo(struct pmenu_item *item) { - struct pb_cui *pb; - - assert(cui->c_sig == pb_cui_sig); - pb = cui->platform_info; - assert(pb->cui->c_sig == pb_cui_sig); - return pb; + cui_show_sysinfo(cui_from_item(item)); + return 0; } -/** - * pb_kexec_cb - The kexec callback. - */ - -static int pb_kexec_cb(struct cui *cui, struct cui_opt_data *cod) +static int pmenu_config(struct pmenu_item *item) { - struct pb_cui *pb = pb_from_cui(cui); - - pb_log("%s: %s\n", __func__, cod->name); - - assert(pb->cui->current == &pb->cui->main->scr); - - return pb_run_kexec(cod->kd, pb->cui->dry_run); + cui_show_config(cui_from_item(item)); + return 0; } /** @@ -166,23 +150,29 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui) struct pmenu *m; struct pmenu_item *i; - m = pmenu_init(pb_cui->cui, 1, cui_on_exit); + m = pmenu_init(pb_cui->cui, 4, cui_on_exit); if (!m) { pb_log("%s: failed\n", __func__); return NULL; } - m->on_open = cui_on_open; + m->on_new = cui_item_new; - m->scr.frame.title = talloc_asprintf(m, - "Petitboot (" PACKAGE_VERSION ")%s", - (pb_cui->cui->dry_run ? " (dry-run)" : "")); + m->scr.frame.ltitle = talloc_asprintf(m, + "Petitboot (" PACKAGE_VERSION ")"); + m->scr.frame.rtitle = NULL; m->scr.frame.help = talloc_strdup(m, - "ESC=exit, Enter=accept, e=edit, o=open"); + "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, "Exit to Shell"); + i = pmenu_item_init(m, 0, " "); + item_opts_off(i->nci, O_SELECTABLE); + i = pmenu_item_init(m, 1, "System information"); + i->on_execute = pmenu_sysinfo; + i = pmenu_item_init(m, 2, "System configuration"); + i->on_execute = pmenu_config; + i = pmenu_item_init(m, 3, "Exit to shell"); i->on_execute = pmenu_exit_cb; result = pmenu_setup(m); @@ -193,6 +183,9 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui) goto fail_setup; } + m->help_title = "main menu"; + m->help_text = main_menu_help_text; + menu_opts_off(m->ncm, O_SHOWDESC); set_menu_mark(m->ncm, " *"); set_current_item(m->ncm, i->nci); @@ -211,10 +204,6 @@ static void sig_handler(int signum) DBGS("%d\n", signum); switch (signum) { - case SIGALRM: - if (pb.cui) - ui_timer_sigalrm(&pb.cui->timer); - break; case SIGWINCH: if (pb.cui) cui_resize(pb.cui); @@ -241,6 +230,7 @@ int main(int argc, char *argv[]) int result; int cui_result; struct opts opts; + FILE *log; result = opts_parse(&opts, argc, argv); @@ -259,17 +249,15 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } + log = stderr; if (strcmp(opts.log_file, "-")) { - FILE *log = fopen(opts.log_file, "a"); + log = fopen(opts.log_file, "a"); - assert(log); - pb_log_set_stream(log); - } else - pb_log_set_stream(stderr); + if (!log) + log = fopen("/dev/null", "a"); + } -#if defined(DEBUG) - pb_log_always_flush(1); -#endif + pb_log_init(log); pb_log("--- petitboot-nc ---\n"); @@ -285,14 +273,12 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - pb.cui = cui_init(&pb, pb_kexec_cb, NULL, opts.start_daemon, - opts.dry_run); + pb.cui = cui_init(&pb, NULL, opts.start_daemon); if (!pb.cui) return EXIT_FAILURE; pb.mm = pb_mm_init(&pb); - ui_timer_disable(&pb.cui->timer); cui_result = cui_run(pb.cui, pb.mm, 0);