]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Handle C0 codes via handler map in Parser
authorDaniel Imms <daimms@microsoft.com>
Mon, 9 Jan 2017 00:21:51 +0000 (16:21 -0800)
committerDaniel Imms <daimms@microsoft.com>
Mon, 9 Jan 2017 00:21:51 +0000 (16:21 -0800)
src/Parser.ts [new file with mode: 0644]
src/xterm.js

diff --git a/src/Parser.ts b/src/Parser.ts
new file mode 100644 (file)
index 0000000..666a915
--- /dev/null
@@ -0,0 +1,12 @@
+import { C0 } from './EscapeSequences';
+import { IInputHandler } from './Interfaces';
+
+export const normalStateHandler: {[key: string]: (handler: IInputHandler) => void} = {};
+normalStateHandler[C0.BEL] = (handler) => handler.bell();
+normalStateHandler[C0.LF] = (handler) => handler.lineFeed();
+normalStateHandler[C0.VT] = normalStateHandler[C0.LF];
+normalStateHandler[C0.FF] = normalStateHandler[C0.LF];
+normalStateHandler[C0.CR] = (handler) => handler.carriageReturn();
+normalStateHandler[C0.HT] = (handler) => handler.tab();
+normalStateHandler[C0.SO] = (handler) => handler.shiftOut();
+normalStateHandler[C0.SI] = (handler) => handler.shiftIn();
index f33f0a9ccd8103bb40e755d708d02821f907cf7b..7d70c2687424073d058d381ae5af34591e52d34d 100644 (file)
@@ -17,6 +17,7 @@ import { rightClickHandler, pasteHandler, copyHandler } from './handlers/Clipboa
 import { CircularList } from './utils/CircularList.js';
 import { C0 } from './EscapeSequences';
 import { InputHandler } from './InputHandler';
+import * as parser from './Parser';
 import * as Browser from './utils/Browser';
 import * as Keyboard from './utils/Keyboard';
 
@@ -1377,45 +1378,18 @@ Terminal.prototype.write = function(data) {
     // surrogate low - already handled above
     if (0xDC00 <= code && code <= 0xDFFF)
       continue;
+
+    if (this.state === normal) {
+      if (ch in parser.normalStateHandler) {
+        parser.normalStateHandler[ch](this.inputHandler);
+        // Skip switch statement (eventually everything will be handled this way
+        continue;
+      }
+    }
+
     switch (this.state) {
       case normal:
         switch (ch) {
-          case C0.BEL:
-            this.inputHandler.bell();
-            break;
-
-          case C0.LF:
-          case C0.VT:
-          case C0.FF:
-            this.inputHandler.lineFeed();
-            break;
-
-          // '\r'
-          case C0.CR:
-            this.inputHandler.carriageReturn();
-            break;
-
-          // '\b'
-          case C0.BS:
-            this.inputHandler.backspace();
-            break;
-
-          // '\t'
-          case C0.HT:
-            this.inputHandler.tab();
-            break;
-
-          // shift out
-          case C0.SO:
-            this.inputHandler.shiftOut();
-            break;
-
-          // shift in
-          case C0.SI:
-            this.inputHandler.shiftIn();
-            break;
-
-          // '\e'
           case C0.ESC:
             this.state = escaped;
             break;