From: John Hodge Date: Mon, 18 Nov 2013 06:36:37 +0000 (+0800) Subject: Kernel/VTerm - VT100 emulation fixes exposed by dropbear+irssi X-Git-Tag: rel0.15~94 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=8b9fec5cdcd6243d401fd0013d5946d296a04e43;p=tpg%2Facess2.git Kernel/VTerm - VT100 emulation fixes exposed by dropbear+irssi --- diff --git a/KernelLand/Kernel/drv/vterm_termbuf.c b/KernelLand/Kernel/drv/vterm_termbuf.c index e3ddff1f..1ce80516 100644 --- a/KernelLand/Kernel/drv/vterm_termbuf.c +++ b/KernelLand/Kernel/drv/vterm_termbuf.c @@ -24,6 +24,7 @@ void VT_int_PutString(tVTerm *Term, const Uint8 *Buffer, Uint Count) int esc_len = Term_HandleVT100(Term, Count - ofs, (const void*)(Buffer + ofs)); if( esc_len < 0 ) { esc_len = -esc_len; + LOG("%i '%*c'", esc_len, esc_len, Buffer+ofs); VT_int_PutRawString(Term, Buffer + ofs, esc_len); //Debug("Raw string '%.*s'", esc_len, Buffer+ofs); } diff --git a/KernelLand/Kernel/drv/vterm_vt100.c b/KernelLand/Kernel/drv/vterm_vt100.c index bab78022..5c2e35d7 100644 --- a/KernelLand/Kernel/drv/vterm_vt100.c +++ b/KernelLand/Kernel/drv/vterm_vt100.c @@ -5,7 +5,7 @@ * drv/vterm_vt100.c * - Virtual Terminal - VT100 (Kinda) Emulation */ -#define DEBUG 0 +#define DEBUG 1 #include "vterm.h" #define sTerminal sVTerm @@ -13,6 +13,7 @@ void Display_AddText(tTerminal *Term, size_t Length, const char *UTF8Text) { + LOG("'%.*s'", Length, UTF8Text); VT_int_PutRawString(Term, (const void*)UTF8Text, Length); } void Display_Newline(tTerminal *Term, bool bCarriageReturn) @@ -63,7 +64,7 @@ void Display_MoveCursor(tTerminal *Term, int RelRow, int RelCol) // if( RelCol < 0 ) { - size_t avail = *wrpos % Term->TextWidth; + int avail = *wrpos % Term->TextWidth; if( RelCol < -avail ) RelCol = -avail; } @@ -81,8 +82,8 @@ void Display_MoveCursor(tTerminal *Term, int RelRow, int RelCol) int maxrows = ((Term->Flags & VT_FLAG_ALTBUF) ? 1 : (giVT_Scrollback+1))*Term->TextHeight; if( RelRow < 0 ) { - if( currow + RelRow < 0 ) - RelRow = currow; + if( RelRow < -currow ) + RelRow = -currow; } else { @@ -91,6 +92,7 @@ void Display_MoveCursor(tTerminal *Term, int RelRow, int RelCol) } *wrpos += RelRow*Term->TextWidth; } + LOG("=(R%i,C%i)", *wrpos / Term->TextWidth, *wrpos % Term->TextWidth); } void Display_SaveCursor(tTerminal *Term) { @@ -192,7 +194,7 @@ void Display_SetBackground(tTerminal *Term, uint32_t RGB) { LOG("(%06x)", RGB); Term->CurColour &= 0xFFFF8000; - Term->CurColour |= (Uint32)VT_Colour24to12(RGB) <<06; + Term->CurColour |= (Uint32)VT_Colour24to12(RGB) << 0; } void Display_Flush(tTerminal *Term) { diff --git a/Usermode/Applications/gui_terminal_src/vt100.c b/Usermode/Applications/gui_terminal_src/vt100.c index c1d51777..1c473817 100644 --- a/Usermode/Applications/gui_terminal_src/vt100.c +++ b/Usermode/Applications/gui_terminal_src/vt100.c @@ -18,10 +18,10 @@ #endif const uint32_t caVT100Colours[] = { - // Black, Red, Green, Yellow, Blue, Purple, Cyan, Gray + // Black, Red, Green, Yellow, Blue, Magenta, Cyan, Gray // Same again, but bright - 0x000000, 0x770000, 0x007700, 0x777700, 0x000077, 0x770077, 0x007777, 0xAAAAAAA, - 0xCCCCCC, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFFF + 0x000000, 0x770000, 0x007700, 0x777700, 0x000077, 0x770077, 0x007777, 0xAAAAAA, + 0xCCCCCC, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFF, }; int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buf); @@ -46,6 +46,7 @@ int Term_HandleVT100(tTerminal *Term, int Len, const char *Buf) memcpy(inc_buf + inc_len, Buf, new_bytes); if( new_bytes == 0 ) { + _SysDebug("Term_HandleVT100: Hit max? (Len=%i)", Len); inc_len = 0; return 0; } @@ -188,6 +189,9 @@ int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buffer) case 'l': // unset switch(args[0]) { + case 1: // Aplication cursor keys + _SysDebug("TODO: \\e[?1%c Application cursor keys", c); + break; case 25: // Hide cursor _SysDebug("TODO: \\e[?25%c Show/Hide cursor", c); break; @@ -209,6 +213,18 @@ int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buffer) // Standard commands switch( c ) { + case 'A': + Display_MoveCursor(Term, -(argc >= 1 ? args[0] : 1), 0); + break; + case 'B': + Display_MoveCursor(Term, (argc >= 1 ? args[0] : 1), 0); + break; + case 'C': + Display_MoveCursor(Term, 0, (argc >= 1 ? args[0] : 1)); + break; + case 'D': + Display_MoveCursor(Term, 0, -(argc >= 1 ? args[0] : 1)); + break; case 'H': if( argc != 2 ) { } @@ -216,15 +232,17 @@ int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buffer) Display_SetCursor(Term, args[0], args[1]); } break; - case 'J': + case 'J': // Clear lines switch( args[0] ) { case 0: + Display_ClearLines(Term, 1); // Down + break; case 1: - _SysDebug("TODO: VT100 %i J", args[0]); + Display_ClearLines(Term, -1); // Up break; - case 2: // Everything - Display_ClearLines(Term, 0); + case 2: + Display_ClearLines(Term, 0); // All break; default: _SysDebug("Unknown VT100 %i J", args[0]); @@ -235,8 +253,10 @@ int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buffer) switch( args[0] ) { case 0: // To EOL + Display_ClearLine(Term, -1); + break; case 1: // To SOL - _SysDebug("TODO: VT100 %i K", args[0]); + Display_ClearLine(Term, 1); break; case 2: Display_ClearLine(Term, 0); @@ -245,8 +265,11 @@ int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buffer) _SysDebug("Unknown VT100 %i K", args[0]); break; } + case 'S': // Scroll down n=1 + Display_ScrollDown(Term, -(argc >= 1 ? args[0] : 1)); + break; case 'T': // Scroll down n=1 - Display_ScrollDown(Term, 1); + Display_ScrollDown(Term, (argc >= 1 ? args[0] : 1)); break; case 'm': if( argc == 0 ) @@ -263,13 +286,19 @@ int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buffer) case 0: Display_ResetAttributes(Term); break; + case 1: + _SysDebug("TODO: VT100 \\e[1m - Bold"); + break; + case 2: + _SysDebug("TODO: VT100 \\e[1m - Reverse"); + break; case 30 ... 37: // TODO: Bold/bright Display_SetForeground( Term, caVT100Colours[ args[i]-30 ] ); break; case 40 ... 47: // TODO: Bold/bright - Display_SetBackground( Term, caVT100Colours[ args[i]-30 ] ); + Display_SetBackground( Term, caVT100Colours[ args[i]-40 ] ); break; default: _SysDebug("TODO: VT100 \\e[%im", args[i]); @@ -280,7 +309,7 @@ int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buffer) break; // Set scrolling region case 'r': - Display_SetScrollArea(Term, args[0], args[1] - args[0]); + Display_SetScrollArea(Term, args[0], (args[1] - args[0])); break; case 's':