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.
This commit is contained in:
Aaron Gyes 2016-10-10 13:53:11 -07:00
parent f464704884
commit d8497f0f1e
2 changed files with 9 additions and 1 deletions

View file

@ -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);

View file

@ -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;