From 8eeb93452d794e5e923573a85dac5de8890661ef Mon Sep 17 00:00:00 2001 From: Golem64 <65229557+Golem642@users.noreply.github.com> Date: Sun, 20 Apr 2025 15:45:37 +0200 Subject: [PATCH 1/2] Test ansi escape RGB fix Entirely with brain logic, might not work --- libctru/source/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libctru/source/console.c b/libctru/source/console.c index 17ecbfc39..1621a6654 100644 --- a/libctru/source/console.c +++ b/libctru/source/console.c @@ -460,7 +460,7 @@ static void consoleColorStateShift(void) break; case ESC_BUILDING_FORMAT_FG_RGB: case ESC_BUILDING_FORMAT_BG_RGB: - if (escapeSeq.argIdx < 3) + if (escapeSeq.argIdx < 2) escapeSeq.argIdx++; else consoleHandleColorEsc(0); // Nothing passed here because three RGB items From 0b655da7dcd6cc871ce48899d28aec80cc0190f5 Mon Sep 17 00:00:00 2001 From: Golem64 <65229557+Golem642@users.noreply.github.com> Date: Sun, 20 Apr 2025 18:52:22 +0200 Subject: [PATCH 2/2] Fix escape color codes I was half right, the debugging process was painful but i fixed it. I also quickly checked the other escape codes and there doesn't seem to be any problem, needs confirmation. --- libctru/source/console.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libctru/source/console.c b/libctru/source/console.c index 1621a6654..54da77951 100644 --- a/libctru/source/console.c +++ b/libctru/source/console.c @@ -366,17 +366,17 @@ static void consoleHandleColorEsc(int code) } break; case ESC_BUILDING_FORMAT_FG: - if (escapeSeq.color.args[0] == 5) + if (code == 5) escapeSeq.state = ESC_BUILDING_FORMAT_FG_NONRGB; - else if (escapeSeq.color.args[0] == 2) + else if (code == 2) escapeSeq.state = ESC_BUILDING_FORMAT_FG_RGB; else escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN; break; case ESC_BUILDING_FORMAT_BG: - if (escapeSeq.color.args[0] == 5) + if (code == 5) escapeSeq.state = ESC_BUILDING_FORMAT_BG_NONRGB; - else if (escapeSeq.color.args[0] == 2) + else if (code == 2) escapeSeq.state = ESC_BUILDING_FORMAT_BG_RGB; else escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN; @@ -448,6 +448,7 @@ static void consoleColorStateShift(void) if (escapeSeq.hasArg[1]) consoleHandleColorEsc(escapeSeq.color.args[1]); escapeSeq.argIdx = 0; + escapeSeq.rawBuf[0] = escapeSeq.rawBuf[1] = 0; escapeSeq.hasArg[0] = escapeSeq.hasArg[1] = false; break; case ESC_BUILDING_FORMAT_BG: @@ -456,6 +457,7 @@ static void consoleColorStateShift(void) case ESC_BUILDING_FORMAT_BG_NONRGB: consoleHandleColorEsc(escapeSeq.color.args[0]); escapeSeq.argIdx = 0; + escapeSeq.rawBuf[0] = escapeSeq.rawBuf[1] = 0; escapeSeq.hasArg[0] = escapeSeq.hasArg[1] = false; break; case ESC_BUILDING_FORMAT_FG_RGB: @@ -538,7 +540,7 @@ ssize_t con_write(struct _reent *r,void *fd,const char *ptr, size_t len) { escapeSeq.rawBuf[escapeSeq.argIdx] = escapeSeq.rawBuf[escapeSeq.argIdx] * 10 + (chr - '0'); break; case ';': - if (escapeSeq.argIdx < 2) + if (escapeSeq.argIdx < 1) escapeSeq.argIdx++; else consoleColorStateShift(); @@ -836,7 +838,13 @@ void consoleDrawChar(int c) { } if (!(currentConsole->flags & CONSOLE_BG_CUSTOM)) { - bg = colorTable[bg]; + 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_REVERSE) {