From a16030394ae7a0e1ff7d896f12284fa8eae15a25 Mon Sep 17 00:00:00 2001 From: y4my4my4m <8145020+y4my4my4m@users.noreply.github.com> Date: Sat, 29 Apr 2023 20:08:20 +0900 Subject: [PATCH] parse ansi --- src/Home/Net/Programs/Telnet.ZC | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Home/Net/Programs/Telnet.ZC b/src/Home/Net/Programs/Telnet.ZC index f456f65b..d3839a51 100755 --- a/src/Home/Net/Programs/Telnet.ZC +++ b/src/Home/Net/Programs/Telnet.ZC @@ -32,6 +32,7 @@ I64 TelnetOpen(U8 *host, U16 port) { // StrCopy(buf, ""); // Default to empty string if an invalid color code is given // } // } + U0 GetColorString(I64 color_code, U8 *buf) { switch (color_code) { case 0: StrCopy(buf, "$$BLACK$$"); break; @@ -73,17 +74,23 @@ U0 TelnetClient(U8 *host, U16 port) { ptr++; if (*ptr == '[') { ptr++; - I64 ansi_code = 0; - while (*ptr >= '0' && *ptr <= '9') { - ansi_code = ansi_code * 10 + (*ptr - '0'); - ptr++; + I64 ansi_code; + while (1) { + ansi_code = 0; + while (*ptr >= '0' && *ptr <= '9') { + ansi_code = ansi_code * 10 + (*ptr - '0'); + ptr++; + } + // Process ansi_code + if (*ptr == ';') { + ptr++; // Move to next part of the sequence + } else if (*ptr == 'm') { + ptr++; // Move past 'm' + break; // End of the escape sequence + } else { + break; // Invalid character, exit loop + } } - // Convert ANSI color code to ZealOS color - I64 templeos_color = 7; // Default color - if (ansi_code >= 30 && ansi_code <= 37) { - templeos_color = ansi_code - 30; - } - // GrColor(templeos_color); } } else { // Print the received character