[edk2,3/4] accept [3~ as delete for TtyTerm terminals

Message ID 1435015811-25912-4-git-send-email-roy.franz@linaro.org
State New
Headers show

Commit Message

Roy Franz June 22, 2015, 11:30 p.m.
Accept the VT200 escape code [3~ as backspace for TtyTerm
terminals.  This is sent by many Linux terminals by default.
This is the first 3 charactar escape sequency handled,
so a new state is added to the escape sequence handling
state machine.

Signed-off-by: Roy Franz <roy.franz@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.0
---
 MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h      |  1 +
 MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

Patch hide | download patch | download mbox

diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
index 03542a4..4616ab3 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
@@ -118,6 +118,7 @@  typedef struct {
 #define INPUT_STATE_LEFTOPENBRACKET       0x04
 #define INPUT_STATE_O                     0x08
 #define INPUT_STATE_2                     0x10
+#define INPUT_STATE_LEFTOPENBRACKET_2     0x20
 
 #define RESET_STATE_DEFAULT               0x00
 #define RESET_STATE_ESC_R                 0x01
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c
index 227df85..7849584 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c
@@ -1397,6 +1397,12 @@  UnicodeToEfiKey (
           TerminalDevice->TerminalType == VTUTF8TYPE    ||
           TerminalDevice->TerminalType == TTYTERMTYPE) {
         switch (UnicodeChar) {
+        case '3':
+          if (TerminalDevice->TerminalType == TTYTERMTYPE) {
+            TerminalDevice->InputState |= INPUT_STATE_LEFTOPENBRACKET_2;
+            continue;
+          }
+          break;
         case 'A':
           Key.ScanCode = SCAN_UP;
           break;
@@ -1527,6 +1533,33 @@  UnicodeToEfiKey (
       break;
 
 
+    case INPUT_STATE_ESC | INPUT_STATE_LEFTOPENBRACKET | INPUT_STATE_LEFTOPENBRACKET_2:
+
+        Key.ScanCode = SCAN_NULL;
+
+        if (TerminalDevice->TerminalType == TTYTERMTYPE) {
+          switch (UnicodeChar) {
+          case '~':
+              Key.ScanCode = SCAN_DELETE;
+            break;
+          }
+        }
+
+      TerminalDevice->ResetState = RESET_STATE_DEFAULT;
+
+      if (Key.ScanCode != SCAN_NULL) {
+        Key.UnicodeChar = 0;
+        EfiKeyFiFoInsertOneKey (TerminalDevice, &Key);
+        TerminalDevice->InputState = INPUT_STATE_DEFAULT;
+        UnicodeToEfiKeyFlushState (TerminalDevice);
+        continue;
+      }
+
+      UnicodeToEfiKeyFlushState (TerminalDevice);
+
+      break;
+
+
     default:
       //
       // Invalid state. This should never happen.