diff options
Diffstat (limited to 'src/console')
-rw-r--r-- | src/console/Kconfig | 9 | ||||
-rw-r--r-- | src/console/printk.c | 12 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/console/Kconfig b/src/console/Kconfig index f80d2e49722e..37d8fefe96bc 100644 --- a/src/console/Kconfig +++ b/src/console/Kconfig @@ -395,6 +395,15 @@ config DEFAULT_CONSOLE_LOGLEVEL endif +config CONSOLE_USE_ANSI_ESCAPES + bool "Use ANSI escape sequences for console highlighting" + default y + help + If enabled, certain consoles (e.g. UART) that are meant to be read on + a terminal will use ANSI escape sequences (like `ESC [1m`) to + highlight lines based on their log level. Disable this if your + terminal does not support ANSI escape sequences. + config NO_POST bool "Don't show any POST codes" default n diff --git a/src/console/printk.c b/src/console/printk.c index ddd14c05891a..93aed523779e 100644 --- a/src/console/printk.c +++ b/src/console/printk.c @@ -81,16 +81,26 @@ static void line_start(union log_state state) if (state.speed == CONSOLE_LOG_FAST) return; - /* Interactive consoles get a `[DEBUG] ` style readable prefix. */ + /* Interactive consoles get a `[DEBUG] ` style readable prefix, + and potentially an escape sequence for highlighting. */ + if (CONFIG(CONSOLE_USE_ANSI_ESCAPES)) + wrap_interactive_printf(BIOS_LOG_ESCAPE_PATTERN, bios_log_escape[state.level]); wrap_interactive_printf(BIOS_LOG_PREFIX_PATTERN, bios_log_prefix[state.level]); } +static void line_end(union log_state state) +{ + if (CONFIG(CONSOLE_USE_ANSI_ESCAPES) && state.speed != CONSOLE_LOG_FAST) + wrap_interactive_printf(BIOS_LOG_ESCAPE_RESET); +} + static void wrap_putchar(unsigned char byte, void *data) { union log_state state = { .as_ptr = data }; static bool line_started = false; if (byte == '\n') { + line_end(state); line_started = false; } else if (!line_started) { line_start(state); |