Kernel/VTerm - Minor cleanup to VT input (remove logging)
[tpg/acess2.git] / KernelLand / Kernel / drv / vterm_input.c
index 20e47db..15da798 100644 (file)
@@ -7,6 +7,7 @@
  */
 #include "vterm.h"
 #include <api_drv_keyboard.h>
+#define DEBUG  1
 
 // === GLOBALS ===
 // --- Key States --- (Used for VT Switching/Magic Combos)
@@ -27,6 +28,7 @@ void VT_InitInput()
                return ;
        }
        VFS_IOCtl(giVT_InputDevHandle, KB_IOCTL_SETCALLBACK, VT_KBCallBack);
+       LOG("VTerm input initialised");
 }
 
 /**
@@ -73,6 +75,9 @@ void VT_KBCallBack(Uint32 Codepoint)
                
                switch(term->RawScancode)
                {
+               case KEYSYM_DELETE:
+                       // TODO: Reboot, or poke secure registered app
+                       return;
                case KEYSYM_F1 :        VT_SetTerminal(0);      return;
                case KEYSYM_F2 :        VT_SetTerminal(1);      return;
                case KEYSYM_F3 :        VT_SetTerminal(2);      return;
@@ -93,22 +98,26 @@ void VT_KBCallBack(Uint32 Codepoint)
                
 //             Log_Debug("VTerm", "Magic Ctrl-Alt-0x%x", term->RawScancode);   
 
+               const unsigned int scroll_step = term->TextHeight / 2;
+               // Note the lack of giVT_Scrollback+1, view top can't go above size-onescreen
+               const unsigned int scroll_max = term->TextHeight * giVT_Scrollback;
                switch(term->RawScancode)
                {
-               // Scrolling
+               // VTerm scrolling
+               // - Scrolls half a screen at a time
+               // - View up (text goes down)
                case KEYSYM_PGUP:
                        if( term->Flags & VT_FLAG_ALTBUF )
                                return ;
-                       term->ViewPos = MAX( 0, term->ViewPos - term->Width );
+                       term->ViewTopRow = (term->ViewTopRow > scroll_step ? term->ViewTopRow - scroll_step : 0);
                        VT_int_UpdateScreen(term, 1);
                        return;
+               // - View down (text goes up)
                case KEYSYM_PGDN:
                        if( term->Flags & VT_FLAG_ALTBUF )
                                return ;
-                       term->ViewPos = MIN(
-                               term->ViewPos + term->Width,
-                               term->Width * term->Height * giVT_Scrollback
-                               );
+                       
+                       term->ViewTopRow = MIN(term->ViewTopRow + scroll_step, scroll_max);
                        VT_int_UpdateScreen(term, 1);
                        return;
                }
@@ -116,7 +125,7 @@ void VT_KBCallBack(Uint32 Codepoint)
        }
        
        // Encode key
-       if(term->Mode == TERM_MODE_TEXT)
+       if(term->Mode == PTYBUFFMT_TEXT)
        {
                Uint8   buf[6] = {0};
                 int    len = 0;
@@ -131,9 +140,6 @@ void VT_KBCallBack(Uint32 Codepoint)
        
                Codepoint &= KEY_CODEPOINT_MASK;
 
-               // Ignore Modifer Keys
-               if(Codepoint > KEY_MODIFIERS)   return;
-               
                // Get UTF-8/ANSI Encoding
                if( Codepoint == 0 )
                {
@@ -173,30 +179,53 @@ void VT_KBCallBack(Uint32 Codepoint)
                                break;
                        
                        case KEYSYM_HOME:
-                       case KEYSYM_KP7:
+                       case KEYSYM_KP7:        // Codepoint==0, then it's home (not translated)
                                buf[0] = '\x1B'; buf[1] = 'O'; buf[2] = 'H';
                                len = 3;
                                break;
                        case KEYSYM_END:
-                       case KEYSYM_KP1:
+                       case KEYSYM_KP1:        // You get the drill
                                buf[0] = '\x1B'; buf[1] = 'O'; buf[2] = 'F';
                                len = 3;
                                break;
                        
                        case KEYSYM_INSERT:
-                       case KEYSYM_KP0:
+                       case KEYSYM_KP0:        // See above
                                buf[0] = '\x1B'; buf[1] = '['; buf[2] = '2'; buf[3] = '~';
                                len = 4;
                                break;
                        case KEYSYM_DELETE:
-                       case KEYSYM_KPPERIOD:
+                       case KEYSYM_KPPERIOD:   // Are you that dumb? Look up
                                buf[0] = '\x1B'; buf[1] = '['; buf[2] = '3'; buf[3] = '~';
                                len = 4;
                                break;
                        }
                }
+               else if( gbVT_CtrlDown )
+               {
+                       len = 1;
+                       switch( term->RawScancode )
+                       {
+                       case KEYSYM_2:
+                               buf[0] = '\0';
+                               break;
+                       case KEYSYM_3 ... KEYSYM_7:
+                               buf[0] = 0x1b + (term->RawScancode - KEYSYM_3);
+                               break;
+                       case KEYSYM_8:
+                               buf[0] = 0x7f;
+                               break;
+                       // - Ctrl-A = \1, Ctrl-Z = \x1a
+                       case KEYSYM_a ... KEYSYM_z:
+                               buf[0] = 0x01 + (term->RawScancode - KEYSYM_a);
+                               break;
+                       default:
+                               goto utf_encode;
+                       }
+               }
                else
                {
+               utf_encode:
                        // Attempt to encode in UTF-8
                        len = WriteUTF8( buf, Codepoint );
                        if(len == 0) {
@@ -209,61 +238,11 @@ void VT_KBCallBack(Uint32 Codepoint)
                        return;
                }
 
-               // TODO: Implement Ctrl-C etc
-#if 0
-               // Handle meta characters
-               if( !(term->Flags & VT_FLAG_RAWIN) )
-               {
-                       switch(buf[0])
-                       {
-                       case '\3':      // ^C
-                               
-                               break;
-                       }
-               }
-#endif
-               
-               // Write
-               if( MAX_INPUT_CHARS8 - term->InputWrite >= len )
-                       memcpy( &term->InputBuffer[term->InputWrite], buf, len );
-               else {
-                       memcpy( &term->InputBuffer[term->InputWrite], buf, MAX_INPUT_CHARS8 - term->InputWrite );
-                       memcpy( &term->InputBuffer[0], buf, len - (MAX_INPUT_CHARS8 - term->InputWrite) );
-               }
-               // Roll the buffer over
-               term->InputWrite += len;
-               term->InputWrite %= MAX_INPUT_CHARS8;
-               if( (term->InputWrite - term->InputRead + MAX_INPUT_CHARS8)%MAX_INPUT_CHARS8 < len ) {
-                       term->InputRead = term->InputWrite + 1;
-                       term->InputRead %= MAX_INPUT_CHARS8;
-               }
+               PTY_SendInput(term->PTY, (void*)buf, len);
        }
        else
        {
-               // Encode the raw key event
-               Uint32  *raw_in = (void*)term->InputBuffer;
-       
-               #if 0
-               // Drop new keys
-               if( term->InputWrite == term->InputRead )
-                       return ;                
-               #endif
-
-               raw_in[ term->InputWrite ] = Codepoint;
-               term->InputWrite ++;
-               if(term->InputWrite >= MAX_INPUT_CHARS32)
-                       term->InputWrite -= MAX_INPUT_CHARS32;
-               
-               #if 1
-               // TODO: Should old or new be dropped?
-               if(term->InputRead == term->InputWrite) {
-                       term->InputRead ++;
-                       if( term->InputRead >= MAX_INPUT_CHARS32 )
-                               term->InputRead -= MAX_INPUT_CHARS32;
-               }
-               #endif
+               PTY_SendInput(term->PTY, (void*)&Codepoint, sizeof(Codepoint));
        }
-       
-       VFS_MarkAvaliable(&term->Node, 1);
 }
 

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