CeDOS - Commit 12e2ef8f

Rudimentary ANSI escape code support
Celina Sophie Kalus
Fri, 01 Dec 2023 00:03:53 +0100
2 files changed, 29 insertions(+), 2 deletions(-)
M kernel/drivers/vga_console.ckernel/drivers/vga_console.c

@@ -112,7 +112,34 @@ return 1;

} void vga_con_write_c(const char c) { - if (c == 0x08) { + static enum { + NORMAL = 0, + ESCAPE_START = 1, + ESCAPE_N = 2, + ESCAPE_M = 3, + ESCAPE_C = 4 + } state; + static int n, m; + + if (c == '\e') { + // beginning of escape sequence + state = ESCAPE_START; + n = 0; + m = 0; + } else if (state == ESCAPE_START && c == '[') { + state = ESCAPE_N; + } else if (state == ESCAPE_N && c >= '0' && c <= '9') { + n = n * 10 + (c - '0'); + } else if (state == ESCAPE_N && c == 'm') { + if (n < 38) { + color = n - 30; + } else if (n < 98) { + color = n - 90 + 8; + } + state = NORMAL; + } else if (state != NORMAL) { + state = NORMAL; + } else if (c == 0x08) { vga_con_backspace(); set_cursor(line, column); } else {
M shell/shelf.cshell/shelf.c

@@ -67,7 +67,7 @@

void main(char *args) { uint32_t a = 0, b = 1, i = 0; printf("\n"); - printf("ShELF shell interface for CeDOS\n"); + printf("\e[94mShELF shell interface for CeDOS\e[97m\n"); printf("Version: " VERSION "\n"); while (1) {