Usermode/GUITerminal - Backspace and over-greedy fix
authorJohn Hodge (sonata) <[email protected]>
Sun, 20 Jan 2013 13:27:11 +0000 (21:27 +0800)
committerJohn Hodge (sonata) <[email protected]>
Sun, 20 Jan 2013 13:27:11 +0000 (21:27 +0800)
Usermode/Applications/gui_shell_src/display.c
Usermode/Applications/gui_shell_src/vt100.c

index 0651634..1665e44 100644 (file)
@@ -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
index 621cb10..2a87ca4 100644 (file)
@@ -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 )

UCC git Repository :: git.ucc.asn.au