Create InputHandler which performs C0 actions

Part of #459
This commit is contained in:
Daniel Imms
2017-01-08 16:11:35 -08:00
parent 1685cf2d8f
commit 04b1ebf1a7
3 changed files with 73 additions and 16 deletions
+50
View File
@@ -0,0 +1,50 @@
import { IInputHandler, ITerminal } from './Interfaces';
export class InputHandler implements IInputHandler {
// TODO: We want to type _terminal when it's pulled into TS
constructor(private _terminal: any) { }
public bell(): void {
if (!this._terminal.visualBell) {
return;
}
this._terminal.element.style.borderColor = 'white';
setTimeout(() => this._terminal.element.style.borderColor = '', 10);
if (this._terminal.popOnBell) {
this._terminal.focus();
}
}
public lineFeed(): void {
if (this._terminal.convertEol) {
this._terminal.x = 0;
}
this._terminal.y++;
if (this._terminal.y > this._terminal.scrollBottom) {
this._terminal.y--;
this._terminal.scroll();
}
}
public carriageReturn(): void {
this._terminal.x = 0;
}
public backspace(): void {
if (this._terminal.x > 0) {
this._terminal.x--;
}
}
public tab(): void {
this._terminal.x = this._terminal.nextStop();
}
public shiftOut(): void {
this._terminal.setgLevel(1);
}
public shiftIn(): void {
this._terminal.setgLevel(0);
}
}
+13
View File
@@ -32,3 +32,16 @@ export interface ITerminal {
scrollDisp(disp: number, suppressScrollEvent: boolean);
cancel(ev: Event, force?: boolean);
}
/**
* Handles actions generated by the parser.
*/
export interface IInputHandler {
bell(): void;
lineFeed(): void;
carriageReturn(): void;
backspace(): void;
tab(): void;
shiftOut(): void;
shiftIn(): void;
}
+10 -16
View File
@@ -16,6 +16,7 @@ import { Viewport } from './Viewport.js';
import { rightClickHandler, pasteHandler, copyHandler } from './handlers/Clipboard.js';
import { CircularList } from './utils/CircularList.js';
import { C0 } from './EscapeSequences';
import { InputHandler } from './InputHandler';
import * as Browser from './utils/Browser';
import * as Keyboard from './utils/Keyboard';
@@ -203,6 +204,8 @@ function Terminal(options) {
this.prefix = '';
this.postfix = '';
this.inputHandler = new InputHandler(this);
// leftover surrogate high from previous write invocation
this.surrogate_high = '';
@@ -1378,47 +1381,38 @@ Terminal.prototype.write = function(data) {
case normal:
switch (ch) {
case C0.BEL:
this.bell();
this.inputHandler.bell();
break;
case C0.LF:
case C0.VT:
case C0.FF:
if (this.convertEol) {
this.x = 0;
}
this.y++;
if (this.y > this.scrollBottom) {
this.y--;
this.scroll();
}
this.inputHandler.lineFeed();
break;
// '\r'
case C0.CR:
this.x = 0;
this.inputHandler.carriageReturn();
break;
// '\b'
case C0.BS:
if (this.x > 0) {
this.x--;
}
this.inputHandler.backspace();
break;
// '\t'
case C0.HT:
this.x = this.nextStop();
this.inputHandler.tab();
break;
// shift out
case C0.SO:
this.setgLevel(1);
this.inputHandler.shiftOut();
break;
// shift in
case C0.SI:
this.setgLevel(0);
this.inputHandler.shiftIn();
break;
// '\e'