From: John Hodge (sonata) Date: Sun, 20 Jan 2013 13:27:11 +0000 (+0800) Subject: Usermode/GUITerminal - Backspace and over-greedy fix X-Git-Tag: rel0.15~598^2 X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=commitdiff_plain;h=ee247b1e92a4a92eb0fa8f842e34e454b47b8327 Usermode/GUITerminal - Backspace and over-greedy fix --- diff --git a/Usermode/Applications/gui_shell_src/display.c b/Usermode/Applications/gui_shell_src/display.c index 06516345..1665e448 100644 --- a/Usermode/Applications/gui_shell_src/display.c +++ b/Usermode/Applications/gui_shell_src/display.c @@ -79,8 +79,10 @@ void Display_AddText(int Length, const char *UTF8Text) { uint32_t cp; bytes += ReadUTF8(UTF8Text+bytes, &cp); - if( Unicode_IsPrinting(cp) ) + if( Unicode_IsPrinting(cp) ) { space --; + giCurrentCol ++; + } } Display_int_PushString(bytes, UTF8Text); @@ -146,7 +148,23 @@ void Display_SetCursor(int Row, int Col) void Display_MoveCursor(int RelRow, int RelCol) { - UNIMPLIMENTED(); + if( RelRow < 0 ) + { + for( ; RelRow < 0; RelRow ++ ) + { + uint32_t cp; + int delta = ReadUTF8Rev(gasDisplayLines[giCurrentLine], giCurrentLinePos, &cp); + if( !Unicode_IsPrinting(cp) ) + RelRow --; + else + giCurrentCol --; + giCurrentLinePos -= delta; + } + } + else + { + UNIMPLIMENTED(); + } } void Display_ClearLine(int Dir) // 0: All, 1: Forward, -1: Reverse diff --git a/Usermode/Applications/gui_shell_src/vt100.c b/Usermode/Applications/gui_shell_src/vt100.c index 621cb10a..2a87ca4f 100644 --- a/Usermode/Applications/gui_shell_src/vt100.c +++ b/Usermode/Applications/gui_shell_src/vt100.c @@ -34,13 +34,12 @@ int Term_HandleVT100(int Len, const char *Buf) if( inc_len > 0 || *Buf == '\x1b' ) { + // Handle VT100 (like) escape sequence int new_bytes = min(MAX_VT100_ESCAPE_LEN - inc_len, Len); - int ret = 0; + int ret = 0, old_inc_len = inc_len; memcpy(inc_buf + inc_len, Buf, new_bytes); - inc_len += new_bytes; - // Handle VT100 (like) escape sequence - _SysDebug("inc_len = %i, new_bytes = %i", inc_len, new_bytes); + inc_len += new_bytes; if( inc_len <= 1 ) return 1; // Skip 1 character (the '\x1b') @@ -49,16 +48,19 @@ int Term_HandleVT100(int Len, const char *Buf) { case '[': // Multibyte, funtime starts ret = Term_HandleVT100_Long(inc_len-2, inc_buf+2); - if( ret > 0 ) + if( ret > 0 ) { ret += 2; + } break; default: ret = 2; break; } - if( ret != 0 ) + if( ret != 0 ) { inc_len = 0; + ret -= old_inc_len; // counter cached bytes + } return ret; } @@ -67,6 +69,8 @@ int Term_HandleVT100(int Len, const char *Buf) case '\b': // TODO: Backspace Display_MoveCursor(-1, 0); + Display_AddText(1, " "); + Display_MoveCursor(-1, 0); return 1; case '\t': // TODO: tab (get current cursor pos, space until multiple of 8) @@ -129,7 +133,7 @@ int Term_HandleVT100_Long(int Len, const char *Buffer) if( !isalpha(c) ) { // Bother. _SysDebug("Unexpected char 0x%x in VT100 escape code", c); - return -1; + return 1; } if( bQuestionMark )