From 1740950132fbf4fab7cbdc493fce52eb8d3b1096 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 4 Jun 2025 22:47:37 +0100 Subject: [PATCH] ansi console: implement bright foreground and background codes --- libctru/include/3ds/console.h | 2 ++ libctru/source/console.c | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libctru/include/3ds/console.h b/libctru/include/3ds/console.h index 29104ef85..f445f0b9d 100644 --- a/libctru/include/3ds/console.h +++ b/libctru/include/3ds/console.h @@ -114,6 +114,8 @@ typedef struct PrintConsole #define CONSOLE_CROSSED_OUT (1<<8) ///< Crossed out text #define CONSOLE_FG_CUSTOM (1<<9) ///< Foreground custom color #define CONSOLE_BG_CUSTOM (1<<10) ///< Background custom color +#define CONSOLE_COLOR_FG_BRIGHT (1<<11) ///< Bright foreground color +#define CONSOLE_COLOR_BG_BRIGHT (1<<12) ///< Bright background color /// Console debug devices supported by libnds. typedef enum { diff --git a/libctru/source/console.c b/libctru/source/console.c index 09571cfc7..184e387a5 100644 --- a/libctru/source/console.c +++ b/libctru/source/console.c @@ -363,6 +363,18 @@ static void consoleHandleColorEsc(int code) escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM; escapeSeq.color.fg = 0; break; + case 90 ... 97: // bright foreground + escapeSeq.color.flags &= ~CONSOLE_COLOR_FAINT; + escapeSeq.color.flags |= CONSOLE_COLOR_FG_BRIGHT; + escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM; + escapeSeq.color.fg = code - 90; + break; + case 100 ... 107: // bright background + escapeSeq.color.flags &= ~CONSOLE_COLOR_FAINT; + escapeSeq.color.flags |= CONSOLE_COLOR_BG_BRIGHT; + escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM; + escapeSeq.color.bg = code - 100; + break; } break; case ESC_BUILDING_FORMAT_FG: @@ -831,23 +843,17 @@ void consoleDrawChar(int c) { u16 bg = currentConsole->bg; if (!(currentConsole->flags & CONSOLE_FG_CUSTOM)) { - if (currentConsole->flags & CONSOLE_COLOR_BOLD) { - fg = colorTable[fg + 8]; + if (currentConsole->flags & (CONSOLE_COLOR_BOLD | CONSOLE_COLOR_FG_BRIGHT)) { + fg += 8; } else if (currentConsole->flags & CONSOLE_COLOR_FAINT) { - fg = colorTable[fg + 16]; - } else { - fg = colorTable[fg]; + fg += 16; } + fg = colorTable[fg]; } if (!(currentConsole->flags & CONSOLE_BG_CUSTOM)) { - if (currentConsole->flags & CONSOLE_COLOR_BOLD) { - bg = colorTable[bg + 8]; - } else if (currentConsole->flags & CONSOLE_COLOR_FAINT) { - bg = colorTable[bg + 16]; - } else { - bg = colorTable[bg]; - } + if (currentConsole->flags & CONSOLE_COLOR_BG_BRIGHT) bg +=8; + bg = colorTable[bg]; } if (currentConsole->flags & CONSOLE_COLOR_REVERSE) {