mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-04-14 19:58:37 +01:00
ansi parse
This commit is contained in:
parent
b215d4f0a2
commit
f775f9feb4
1 changed files with 30 additions and 27 deletions
|
@ -37,17 +37,18 @@ I64 TelnetOpen(U8 *host, U16 port) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
U0 GetColorString(I64 color_code, U8 *buf) {
|
U0 AppendColorString(I64 color_code, U8 *buf) {
|
||||||
|
SysLog("AppendColorString(%d, %p)\n", color_code, buf);
|
||||||
switch (color_code) {
|
switch (color_code) {
|
||||||
case 0: StrCopy(buf, "$$BLACK$$"); break;
|
case 0: CatPrint(buf, "$$BLACK$$"); break;
|
||||||
case 1: StrCopy(buf, "$$RED$$"); break;
|
case 1: CatPrint(buf, "$$RED$$"); break;
|
||||||
case 2: StrCopy(buf, "$$GREEN$$"); break;
|
case 2: CatPrint(buf, "$$GREEN$$"); break;
|
||||||
case 3: StrCopy(buf, "$$BROWN$$"); break; // ANSI yellow is mapped to ZealOS brown
|
case 3: CatPrint(buf, "$$BROWN$$"); break; // ANSI yellow is mapped to ZealOS brown
|
||||||
case 4: StrCopy(buf, "$$BLUE$$"); break;
|
case 4: CatPrint(buf, "$$BLUE$$"); break;
|
||||||
case 5: StrCopy(buf, "$$MAGENTA$$"); break;
|
case 5: CatPrint(buf, "$$MAGENTA$$"); break;
|
||||||
case 6: StrCopy(buf, "$$CYAN$$"); break;
|
case 6: CatPrint(buf, "$$CYAN$$"); break;
|
||||||
case 7: StrCopy(buf, "$$GREY$$"); break; // ANSI white is mapped to ZealOS grey
|
case 7: CatPrint(buf, "$$GREY$$"); break; // ANSI white is mapped to ZealOS grey
|
||||||
default: StrCopy(buf, ""); break; // Default to empty string if an invalid color code is given
|
default: CatPrint(buf, ""); break; // Default to empty string if an invalid color code is given
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,29 +158,30 @@ U0 TelnetClient(U8 *host, U16 port) {
|
||||||
}
|
}
|
||||||
// Process ansi_code
|
// Process ansi_code
|
||||||
if (*ptr == ';') {
|
if (*ptr == ';') {
|
||||||
ptr++; // Move to next part of the sequence
|
ptr++; // Move to the next part of the sequence
|
||||||
} else if (*ptr == 'm' ) {
|
} else if (*ptr == 'm') {
|
||||||
ptr++;
|
ptr++;
|
||||||
break;
|
|
||||||
} else if (*ptr == 'H' || *ptr == 'J' || *ptr == 'K' ) {
|
|
||||||
ptr++; // Move past the current character
|
|
||||||
// Process color codes
|
|
||||||
if (ansi_code >= 30 && ansi_code <= 37) {
|
if (ansi_code >= 30 && ansi_code <= 37) {
|
||||||
// Set foreground color
|
// Set foreground color
|
||||||
U8 color_buf_fg[16];
|
AppendColorString(ansi_code - 30, buffer);
|
||||||
GetColorString(ansi_code - 30, color_buf_fg);
|
|
||||||
// Print(color_buf_fg);
|
|
||||||
"%s", color_buf_fg;
|
|
||||||
} else if (ansi_code >= 40 && ansi_code <= 47) {
|
} else if (ansi_code >= 40 && ansi_code <= 47) {
|
||||||
// Set background color
|
// Set background color
|
||||||
U8 color_buf_bg[16];
|
AppendColorString(ansi_code - 40, buffer);
|
||||||
GetColorString(ansi_code - 40, color_buf_bg);
|
|
||||||
// Print(color_buf_bg);
|
|
||||||
"%s", color_buf_bg;
|
|
||||||
}
|
}
|
||||||
// End of the escape sequence
|
|
||||||
break;
|
break;
|
||||||
} else if (*ptr == 'C') {
|
} else if (*ptr == 'H') {
|
||||||
|
// TODO: Handle cursor positioning
|
||||||
|
ptr++;
|
||||||
|
break;
|
||||||
|
} else if (*ptr == 'J') {
|
||||||
|
// TODO: Handle screen clearing
|
||||||
|
ptr++;
|
||||||
|
break;
|
||||||
|
} else if (*ptr == 'K') {
|
||||||
|
// TODO: Handle line clearing
|
||||||
|
ptr++;
|
||||||
|
break;
|
||||||
|
} else if (*ptr == 'C') {
|
||||||
// Custom 'C' escape code for centering text
|
// Custom 'C' escape code for centering text
|
||||||
// TODO: Handle the centering here
|
// TODO: Handle the centering here
|
||||||
ptr++;
|
ptr++;
|
||||||
|
@ -187,6 +189,7 @@ U0 TelnetClient(U8 *host, U16 port) {
|
||||||
} else if (*ptr == '?') {
|
} else if (*ptr == '?') {
|
||||||
ptr++; // Skip the '?'
|
ptr++; // Skip the '?'
|
||||||
} else if (*ptr == 'h' || *ptr == 'l') {
|
} else if (*ptr == 'h' || *ptr == 'l') {
|
||||||
|
// TODO: Handle 'h' (set mode) or 'l' (reset mode) codes
|
||||||
ptr++; // Skip 'h' or 'l'
|
ptr++; // Skip 'h' or 'l'
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue