From 47bc66a0c744f68a84147b0bd616ab25a242fb70 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 9 Oct 2013 16:48:38 +0800 Subject: [PATCH] ui/ncurses: Display sysinfo type & identifier Hook into the sysinfo updates to display the type & id at the top of the petitboot main menu. Signed-off-by: Jeremy Kerr --- ui/ncurses/generic-main.c | 3 ++- ui/ncurses/nc-boot-editor.c | 3 ++- ui/ncurses/nc-cui.c | 23 +++++++++++++++++++++++ ui/ncurses/nc-cui.h | 1 + ui/ncurses/nc-scr.c | 17 +++++++++++++++-- ui/ncurses/nc-scr.h | 4 +++- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 9236a80..d0563f0 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -145,8 +145,9 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui) m->on_open = cui_on_open; - m->scr.frame.title = talloc_asprintf(m, + 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"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); diff --git a/ui/ncurses/nc-boot-editor.c b/ui/ncurses/nc-boot-editor.c index 0b658f2..100830c 100644 --- a/ui/ncurses/nc-boot-editor.c +++ b/ui/ncurses/nc-boot-editor.c @@ -336,8 +336,9 @@ struct boot_editor *boot_editor_init(void *ui_ctx, ui_ctx, boot_editor_process_key, boot_editor_post, boot_editor_unpost, boot_editor_resize); - boot_editor->scr.frame.title = talloc_strdup(boot_editor, + boot_editor->scr.frame.ltitle = talloc_strdup(boot_editor, "Petitboot Option Editor"); + boot_editor->scr.frame.rtitle = NULL; boot_editor->scr.frame.help = talloc_strdup(boot_editor, "ESC=cancel, Enter=accept"); diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 4f7b121..35c9deb 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -473,11 +473,34 @@ static void cui_update_status(struct boot_status *status, void *arg) } +static void cui_update_mm_title(struct cui *cui) +{ + struct nc_frame *frame = &cui->main->scr.frame; + + talloc_free(frame->rtitle); + + frame->rtitle = talloc_strdup(cui->main, cui->sysinfo->type); + if (cui->sysinfo->identifier) + frame->rtitle = talloc_asprintf_append(frame->rtitle, + " %s", cui->sysinfo->identifier); + + if (cui->current == &cui->main->scr) + cui->current->post(cui->current); +} + +static void cui_update_sysinfo(struct system_info *sysinfo, void *arg) +{ + struct cui *cui = cui_from_arg(arg); + cui->sysinfo = talloc_steal(cui, sysinfo); + cui_update_mm_title(cui); +} + static struct discover_client_ops cui_client_ops = { .device_add = NULL, .boot_option_add = cui_boot_option_add, .device_remove = cui_device_remove, .update_status = cui_update_status, + .update_sysinfo = cui_update_sysinfo, }; /** diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h index 4c13ddf..5298cad 100644 --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -55,6 +55,7 @@ struct cui { struct pmenu *main; struct waitset *waitset; struct discover_client *client; + struct system_info *sysinfo; struct pjs *pjs; void *platform_info; unsigned int default_item; diff --git a/ui/ncurses/nc-scr.c b/ui/ncurses/nc-scr.c index ff20d63..9a3f3df 100644 --- a/ui/ncurses/nc-scr.c +++ b/ui/ncurses/nc-scr.c @@ -22,6 +22,7 @@ #include #include +#include #include "log/log.h" #include "talloc/talloc.h" @@ -70,11 +71,23 @@ static void nc_scr_status_draw(struct nc_scr *scr) void nc_scr_frame_draw(struct nc_scr *scr) { - DBGS("title '%s'\n", scr->frame.title); + int ltitle_len, rtitle_len; + + DBGS("ltitle '%s'\n", scr->frame.ltitle); + DBGS("rtitle '%s'\n", scr->frame.rtitle); DBGS("help '%s'\n", scr->frame.help); DBGS("status '%s'\n", scr->frame.status); - mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.title); + ltitle_len = strlen(scr->frame.ltitle); + rtitle_len = scr->frame.rtitle ? strlen(scr->frame.rtitle) : 0; + + /* if both ltitle and rtitle don't fit, trim rtitle */ + if (ltitle_len + rtitle_len + nc_scr_pos_lrtitle_space > COLS - 2) + rtitle_len = COLS - 2 - ltitle_len - nc_scr_pos_lrtitle_space; + + mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.ltitle); + mvwaddnstr(scr->main_ncw, nc_scr_pos_title, COLS - rtitle_len - 1, + scr->frame.rtitle, rtitle_len); mvwhline(scr->main_ncw, nc_scr_pos_title_sep, 1, ACS_HLINE, COLS - 2); mvwhline(scr->main_ncw, LINES - nc_scr_pos_help_sep, 1, ACS_HLINE, diff --git a/ui/ncurses/nc-scr.h b/ui/ncurses/nc-scr.h index a8aa314..298aa7d 100644 --- a/ui/ncurses/nc-scr.h +++ b/ui/ncurses/nc-scr.h @@ -64,6 +64,7 @@ static inline void nc_flush_keys(void) enum nc_scr_pos { nc_scr_pos_title = 0, nc_scr_pos_title_sep = 1, + nc_scr_pos_lrtitle_space = 2, nc_scr_pos_sub = 2, nc_scr_pos_help_sep = 3, @@ -74,7 +75,8 @@ enum nc_scr_pos { }; struct nc_frame { - char *title; + char *ltitle; + char *rtitle; char *help; char *status; }; -- 2.39.2