]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: Display sysinfo type & identifier
authorJeremy Kerr <jk@ozlabs.org>
Wed, 9 Oct 2013 08:48:38 +0000 (16:48 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 9 Oct 2013 09:40:41 +0000 (17:40 +0800)
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>
ui/ncurses/generic-main.c
ui/ncurses/nc-boot-editor.c
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h
ui/ncurses/nc-scr.c
ui/ncurses/nc-scr.h

index 9236a800beac18a11d1041037955687f109364c6..d0563f0cac7137bda3d53aaa3980fd84e3afc7a5 100644 (file)
@@ -145,8 +145,9 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui)
 
        m->on_open = cui_on_open;
 
 
        m->on_open = cui_on_open;
 
-       m->scr.frame.title = talloc_asprintf(m,
+       m->scr.frame.ltitle = talloc_asprintf(m,
                "Petitboot (" PACKAGE_VERSION ")");
                "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");
        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");
index 0b658f240fabe89dfbf3592c651d152fe9fc6b62..100830c462540a4498fd87fb834f56fb0216ee36 100644 (file)
@@ -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);
 
                        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");
                        "Petitboot Option Editor");
+       boot_editor->scr.frame.rtitle = NULL;
        boot_editor->scr.frame.help = talloc_strdup(boot_editor,
                        "ESC=cancel, Enter=accept");
 
        boot_editor->scr.frame.help = talloc_strdup(boot_editor,
                        "ESC=cancel, Enter=accept");
 
index 4f7b121b21ec760be378de3b4ccf78cf94ec11e6..35c9debfbe1113ff315eb0e9cc610b50641aea24 100644 (file)
@@ -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,
 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,
 };
 
 /**
 };
 
 /**
index 4c13ddfd115f0723d39a4723a92c79768f1a4e4f..5298cade7ce97c55de140c9eb96ea385e4fe31e8 100644 (file)
@@ -55,6 +55,7 @@ struct cui {
        struct pmenu *main;
        struct waitset *waitset;
        struct discover_client *client;
        struct pmenu *main;
        struct waitset *waitset;
        struct discover_client *client;
+       struct system_info *sysinfo;
        struct pjs *pjs;
        void *platform_info;
        unsigned int default_item;
        struct pjs *pjs;
        void *platform_info;
        unsigned int default_item;
index ff20d637781289572d962430b0a094e7195447ce..9a3f3dfc77d0dd1b45dfdbdfff40256ba0e36899 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <assert.h>
 #include <stdarg.h>
 
 #include <assert.h>
 #include <stdarg.h>
+#include <string.h>
 
 #include "log/log.h"
 #include "talloc/talloc.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)
 {
 
 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);
 
        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,
        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,
index a8aa314cfa86bec9a2108d2c22f1aa8b140c13e0..298aa7d2f44b5dc1f0f8aad8fe7cd1f31a8abe65 100644 (file)
@@ -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,
 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,
        nc_scr_pos_sub = 2,
 
        nc_scr_pos_help_sep = 3,
@@ -74,7 +75,8 @@ enum nc_scr_pos {
 };
 
 struct nc_frame {
 };
 
 struct nc_frame {
-       char *title;
+       char *ltitle;
+       char *rtitle;
        char *help;
        char *status;
 };
        char *help;
        char *status;
 };