From 659fb90c1c5d05ea286355e800365eb0b4176021 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 8 Jan 2017 16:21:51 -0800 Subject: [PATCH] Handle C0 codes via handler map in Parser --- src/Parser.ts | 12 ++++++++++++ src/xterm.js | 46 ++++++++++------------------------------------ 2 files changed, 22 insertions(+), 36 deletions(-) create mode 100644 src/Parser.ts diff --git a/src/Parser.ts b/src/Parser.ts new file mode 100644 index 00000000..666a9151 --- /dev/null +++ b/src/Parser.ts @@ -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(); diff --git a/src/xterm.js b/src/xterm.js index f33f0a9c..7d70c268 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -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;