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");
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");
}
+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,
};
/**
struct pmenu *main;
struct waitset *waitset;
struct discover_client *client;
+ struct system_info *sysinfo;
struct pjs *pjs;
void *platform_info;
unsigned int default_item;
#include <assert.h>
#include <stdarg.h>
+#include <string.h>
#include "log/log.h"
#include "talloc/talloc.h"
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,
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,
};
struct nc_frame {
- char *title;
+ char *ltitle;
+ char *rtitle;
char *help;
char *status;
};