summaryrefslogtreecommitdiffstats
path: root/ui/ncurses
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-10-09 16:48:38 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-10-09 17:40:41 +0800
commit47bc66a0c744f68a84147b0bd616ab25a242fb70 (patch)
tree13aad60595c03209847954c0222a37db81f7a85f /ui/ncurses
parent8ec7ea724de780a6a428a8485b2760bf1d9e0a4e (diff)
downloadtalos-petitboot-47bc66a0c744f68a84147b0bd616ab25a242fb70.tar.gz
talos-petitboot-47bc66a0c744f68a84147b0bd616ab25a242fb70.zip
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 <jk@ozlabs.org>
Diffstat (limited to 'ui/ncurses')
-rw-r--r--ui/ncurses/generic-main.c3
-rw-r--r--ui/ncurses/nc-boot-editor.c3
-rw-r--r--ui/ncurses/nc-cui.c23
-rw-r--r--ui/ncurses/nc-cui.h1
-rw-r--r--ui/ncurses/nc-scr.c17
-rw-r--r--ui/ncurses/nc-scr.h4
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 <assert.h>
#include <stdarg.h>
+#include <string.h>
#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;
};
OpenPOWER on IntegriCloud