summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--payloads/libpayload/curses/tinycurses.c10
-rw-r--r--payloads/libpayload/drivers/serial.c15
-rw-r--r--payloads/libpayload/include/libpayload.h1
3 files changed, 26 insertions, 0 deletions
diff --git a/payloads/libpayload/curses/tinycurses.c b/payloads/libpayload/curses/tinycurses.c
index 16e06ec473..960e74fc9e 100644
--- a/payloads/libpayload/curses/tinycurses.c
+++ b/payloads/libpayload/curses/tinycurses.c
@@ -669,10 +669,12 @@ int wnoutrefresh(WINDOW *win)
// FIXME.
int serial_is_bold = 0;
int serial_is_altcharset = 0;
+ int serial_cur_pair = 0;
int x, y;
chtype ch;
int need_altcharset;
+ short fg, bg;
serial_end_bold();
serial_end_altcharset();
@@ -703,6 +705,7 @@ int wnoutrefresh(WINDOW *win)
if (serial_is_bold) {
serial_end_bold();
serial_is_bold = 0;
+ serial_cur_pair = 0;
}
}
@@ -723,6 +726,13 @@ int wnoutrefresh(WINDOW *win)
serial_is_altcharset = 0;
}
+ if (serial_cur_pair != PAIR_NUMBER(attr)) {
+ pair_content(PAIR_NUMBER(attr),
+ &fg, &bg);
+ serial_set_color(fg, bg);
+ serial_cur_pair = PAIR_NUMBER(attr);
+ }
+
serial_putchar(ch);
}
diff --git a/payloads/libpayload/drivers/serial.c b/payloads/libpayload/drivers/serial.c
index 6e46e06581..8d7273c3a5 100644
--- a/payloads/libpayload/drivers/serial.c
+++ b/payloads/libpayload/drivers/serial.c
@@ -110,6 +110,8 @@ int serial_getchar(void)
enacs=\E(B\E)0, smacs=^N, rmacs=^O. */
#define VT100_SMACS "\e(0"
#define VT100_RMACS "\e(B"
+/* A vt100 doesn't do color, setaf/setab below are from xterm-color. */
+#define VT100_SET_COLOR "\e[3%d;4%dm"
static void serial_putcmd(char *str)
{
@@ -142,6 +144,19 @@ void serial_end_altcharset(void)
serial_putcmd(VT100_RMACS);
}
+/**
+ * Set the foreground and background colors on the serial console.
+ *
+ * @param fg Foreground color number.
+ * @param bg Background color number.
+ */
+void serial_set_color(short fg, short bg)
+{
+ char buffer[32];
+ snprintf(buffer, sizeof(buffer), VT100_SET_COLOR, fg, bg);
+ serial_putcmd(buffer);
+}
+
void serial_set_cursor(int y, int x)
{
char buffer[32];
diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h
index cc50fd0671..7af19dee06 100644
--- a/payloads/libpayload/include/libpayload.h
+++ b/payloads/libpayload/include/libpayload.h
@@ -139,6 +139,7 @@ void serial_start_bold(void);
void serial_end_bold(void);
void serial_start_altcharset(void);
void serial_end_altcharset(void);
+void serial_set_color(short fg, short bg);
void serial_set_cursor(int y, int x);
/** @} */