parse ansi

This commit is contained in:
y4my4my4m 2023-04-29 20:08:20 +09:00
parent 81bf25c5ba
commit a16030394a

View file

@ -32,6 +32,7 @@ I64 TelnetOpen(U8 *host, U16 port) {
// StrCopy(buf, ""); // Default to empty string if an invalid color code is given // StrCopy(buf, ""); // Default to empty string if an invalid color code is given
// } // }
// } // }
U0 GetColorString(I64 color_code, U8 *buf) { U0 GetColorString(I64 color_code, U8 *buf) {
switch (color_code) { switch (color_code) {
case 0: StrCopy(buf, "$$BLACK$$"); break; case 0: StrCopy(buf, "$$BLACK$$"); break;
@ -73,17 +74,23 @@ U0 TelnetClient(U8 *host, U16 port) {
ptr++; ptr++;
if (*ptr == '[') { if (*ptr == '[') {
ptr++; ptr++;
I64 ansi_code = 0; I64 ansi_code;
while (1) {
ansi_code = 0;
while (*ptr >= '0' && *ptr <= '9') { while (*ptr >= '0' && *ptr <= '9') {
ansi_code = ansi_code * 10 + (*ptr - '0'); ansi_code = ansi_code * 10 + (*ptr - '0');
ptr++; ptr++;
} }
// Convert ANSI color code to ZealOS color // Process ansi_code
I64 templeos_color = 7; // Default color if (*ptr == ';') {
if (ansi_code >= 30 && ansi_code <= 37) { ptr++; // Move to next part of the sequence
templeos_color = ansi_code - 30; } else if (*ptr == 'm') {
ptr++; // Move past 'm'
break; // End of the escape sequence
} else {
break; // Invalid character, exit loop
}
} }
// GrColor(templeos_color);
} }
} else { } else {
// Print the received character // Print the received character