From d8497f0f1ed243ce8ee8eeeedee6d083183284a9 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Mon, 10 Oct 2016 13:53:11 -0700 Subject: [PATCH] Use the nonbright variant of brights on lame terms With this change, 'set_color brred; echo bright red' will at leaat be red on Linux/FreeBSD virt consoles. --- src/output.cpp | 8 ++++++++ src/screen.cpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/output.cpp b/src/output.cpp index d6e81b695..2533a0dd1 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -71,6 +71,14 @@ static bool write_color_escape(char *todo, unsigned char idx, bool is_fg) { // We are attempting to bypass the term here. Generate the ANSI escape sequence ourself. char buff[16] = ""; if (idx < 16) { + // this allows the non-bright color to happen instead of no color working at all when + // a bright is attempted when only colors 0-7 are supported. + // TODO: enter bold mode in builtin_set_color in the same circumstance- doing that + // combined + // with what we do here, will make the brights actually work for virtual + // consoles/ancient emulators. + if (max_colors == 8 && idx > 8) idx -= 8; + snprintf(buff, sizeof buff, "\x1b[%dm", ((idx > 7) ? 82 : 30) + idx + !is_fg * 10); } else { snprintf(buff, sizeof buff, "\x1b[%d;5;%dm", is_fg ? 38 : 48, idx); diff --git a/src/screen.cpp b/src/screen.cpp index 82a711763..391e3876a 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -214,7 +214,7 @@ size_t escape_code_length(const wchar_t *code) { for (size_t p = 0; p < sizeof esc / sizeof *esc && !found; p++) { if (!esc[p]) continue; - for (int k = 0; k < (max_colors - 1); k++) { + for (short k = 0; k < max_colors; k++) { size_t len = try_sequence(tparm(esc[p], k), code); if (len) { resulting_length = len;