Handle C0 codes via handler map in Parser

This commit is contained in:
Daniel Imms
2017-01-08 16:21:51 -08:00
parent 04b1ebf1a7
commit 659fb90c1c
2 changed files with 22 additions and 36 deletions
+12
View File
@@ -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();
+10 -36
View 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;