summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-cui.c
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-11-06 15:34:51 +1100
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-11-16 13:55:29 +1100
commit2bc0df4aa35a89c5af7e54f459e2bbde20ca6a7e (patch)
treea66664ea5f4d51c8c1b92033843d5d75f50d7cef /ui/ncurses/nc-cui.c
parent646d77d8156ad72da1c24f734a029a525ba4bed9 (diff)
downloadtalos-petitboot-2bc0df4aa35a89c5af7e54f459e2bbde20ca6a7e.tar.gz
talos-petitboot-2bc0df4aa35a89c5af7e54f459e2bbde20ca6a7e.zip
ui/ncurses: Reset console options on boot
The ncurses UI sets a few console options at startup that are needed for ncurses to work properly. These aren't reset however and can lead to quirks like the cursor being invisible after kexecing to the next kernel. The UI process doesn't have time to reset these when it is killed by kexec, so instead add a 'boot_active' field to status updates. This is set by boot.c's update handler so the UI can assume it is about to boot if it receives a status update with this field, and resets the console options. If the boot is cancelled for any reason the status update will reflect that and the console options are restored. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'ui/ncurses/nc-cui.c')
-rw-r--r--ui/ncurses/nc-cui.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
index d3e00aa..8ad8955 100644
--- a/ui/ncurses/nc-cui.c
+++ b/ui/ncurses/nc-cui.c
@@ -92,16 +92,30 @@ static bool lockdown_active(void)
#endif
}
+static void cui_set_curses_options(bool curses_mode)
+{
+ if (curses_mode) {
+ cbreak(); /* Disable line buffering. */
+ noecho(); /* Disable getch() echo. */
+ nonl(); /* Disable new-line translation. */
+ intrflush(stdscr, FALSE); /* Disable interrupt flush. */
+ curs_set(0); /* Make cursor invisible */
+ nodelay(stdscr, TRUE); /* Enable non-blocking getch() */
+ } else {
+ nocbreak(); /* Enable line buffering. */
+ echo(); /* Enable getch() echo. */
+ nl(); /* Enable new-line translation. */
+ intrflush(stdscr, TRUE); /* Enable interrupt flush. */
+ curs_set(1); /* Make cursor visible */
+ nodelay(stdscr, FALSE); /* Disable non-blocking getch() */
+ }
+}
+
static void cui_start(void)
{
initscr(); /* Initialize ncurses. */
- cbreak(); /* Disable line buffering. */
- noecho(); /* Disable getch() echo. */
keypad(stdscr, TRUE); /* Enable num keypad keys. */
- nonl(); /* Disable new-line translation. */
- intrflush(stdscr, FALSE); /* Disable interrupt flush. */
- curs_set(0); /* Make cursor invisible */
- nodelay(stdscr, TRUE); /* Enable non-blocking getch() */
+ cui_set_curses_options(true);
/* We may be operating with an incorrect $TERM type; in this case
* the keymappings will be slightly broken. We want at least
@@ -650,6 +664,12 @@ static int cui_process_key(void *arg)
}
}
+ if (cui->preboot_mode) {
+ /* Turn curses options back on if the user interacts */
+ cui->preboot_mode = false;
+ cui_set_curses_options(true);
+ }
+
if (!cui->has_input && key_cancels_boot(c)) {
cui->has_input = true;
if (cui->client) {
@@ -980,8 +1000,21 @@ static void cui_update_status(struct status *status, void *arg)
statuslog_append_steal(cui, cui->statuslog, status);
/* Ignore status messages from the backlog */
- if (!status->backlog)
- nc_scr_status_printf(cui->current, "%s", status->message);
+ if (status->backlog)
+ return;
+
+ nc_scr_status_printf(cui->current, "%s", status->message);
+
+ if (cui->preboot_mode &&
+ (!status->boot_active || status->type == STATUS_ERROR)) {
+ cui_set_curses_options(true);
+ cui->preboot_mode = false;
+ } else {
+ cui->preboot_mode = status->boot_active &&
+ status->type == STATUS_INFO;
+ if (cui->preboot_mode)
+ cui_set_curses_options(false);
+ }
}
/*
OpenPOWER on IntegriCloud