X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fgui_shell_src%2Fvt100.c;h=09a96d9dafa48f9f56254160e7eb4f386b78fcdd;hb=e5deb25fdad3bf008df40679082abdc999d5d1d9;hp=190f42c11cc64fedbf4dc3fd86f1515c6a982fd5;hpb=55ef4dd6e0ce70e703d79129ba66bed63b296e45;p=tpg%2Facess2.git diff --git a/Usermode/Applications/gui_shell_src/vt100.c b/Usermode/Applications/gui_shell_src/vt100.c index 190f42c1..09a96d9d 100644 --- a/Usermode/Applications/gui_shell_src/vt100.c +++ b/Usermode/Applications/gui_shell_src/vt100.c @@ -9,6 +9,17 @@ #include #include "include/vt100.h" #include "include/display.h" +#include // isalpha +#include // _SysDebug + +const uint32_t caVT100Colours[] = { + // Black, Red, Green, Yellow, Blue, Purple, Cyan, Gray + // Same again, but bright + 0x000000, 0x770000, 0x007700, 0x777700, 0x000077, 0x770077, 0x007777, 0xAAAAAAA, + 0xCCCCCC, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFFF +}; + + int Term_HandleVT100_Long(int Len, const char *Buf); static inline int min(int a, int b) { @@ -23,18 +34,43 @@ int Term_HandleVT100(int Len, const char *Buf) if( inc_len > 0 || *Buf == '\x1b' ) { - memcpy(inc_buf + inc_len, Buf, min(MAX_VT100_ESCAPE_LEN - inc_len, Len)); // Handle VT100 (like) escape sequence - - inc_len = 0; - return 1; + int new_bytes = min(MAX_VT100_ESCAPE_LEN - inc_len, Len); + int ret = 0, old_inc_len = inc_len; + memcpy(inc_buf + inc_len, Buf, new_bytes); + + inc_len += new_bytes; + + if( inc_len <= 1 ) + return 1; // Skip 1 character (the '\x1b') + + switch(inc_buf[1]) + { + case '[': // Multibyte, funtime starts + ret = Term_HandleVT100_Long(inc_len-2, inc_buf+2); + if( ret > 0 ) { + ret += 2; + } + break; + default: + ret = 2; + break; + } + + if( ret != 0 ) { + inc_len = 0; + ret -= old_inc_len; // counter cached bytes + } + return ret; } switch( *Buf ) { case '\b': - // TODO: Backspace Display_MoveCursor(-1, 0); + Display_AddText(1, " "); + Display_MoveCursor(-1, 0); + // TODO: Need to handle \t and ^A-Z return 1; case '\t': // TODO: tab (get current cursor pos, space until multiple of 8) @@ -43,7 +79,6 @@ int Term_HandleVT100(int Len, const char *Buf) Display_Newline(1); return 1; case '\r': - // TODO: Carriage return Display_MoveCursor(INT_MIN, 0); return 1; } @@ -60,3 +95,100 @@ int Term_HandleVT100(int Len, const char *Buf) } return -ret; } + +int Term_HandleVT100_Long(int Len, const char *Buffer) +{ + char c; + int argc = 0, j = 0; + int args[6] = {0,0,0,0,0,0}; + int bQuestionMark = 0; + + // Get Arguments + if(j == Len) return 0; + c = Buffer[j++]; + if(c == '?') { + bQuestionMark = 1; + if(j == Len) return 0; + c = Buffer[j++]; + } + if( '0' <= c && c <= '9' ) + { + do { + if(c == ';') { + if(j == Len) return 0; + c = Buffer[j++]; + } + while('0' <= c && c <= '9') { + args[argc] *= 10; + args[argc] += c-'0'; + if(j == Len) return 0; + c = Buffer[j++]; + } + argc ++; + } while(c == ';'); + } + + // Get Command + if( !isalpha(c) ) { + // Bother. + _SysDebug("Unexpected char 0x%x in VT100 escape code", c); + return 1; + } + + if( bQuestionMark ) + { + // Special commands + switch( c ) + { + default: + _SysDebug("Unknown VT100 extended escape char 0x%x", c); + break; + } + } + else + { + // Standard commands + switch( c ) + { + case 'J': + if( argc == 0 ) + Display_ClearLine(0); + else if( args[0] == 2 ) + Display_ClearLines(0); // Entire screen! + else + _SysDebug("TODO: VT100 %i J", args[0]); + break; + case 'm': + if( argc == 0 ) + { + // Reset + } + else + { + int i; + for( i = 0; i < argc; i ++ ) + { + if( args[i] < 8 ) + { + // TODO: Flags? + } + else if( 30 <= args[i] && args[i] <= 37 ) + { + // TODO: Bold/bright + Display_SetForeground( caVT100Colours[ args[i]-30 ] ); + } + else if( 40 <= args[i] && args[i] <= 47 ) + { + // TODO: Bold/bright + Display_SetBackground( caVT100Colours[ args[i]-30 ] ); + } + } + } + break; + default: + _SysDebug("Unknown VT100 escape char 0x%x", c); + break; + } + } + return j; +}