Remove ITerminal usage in DECRQSS

This commit is contained in:
Daniel Imms
2019-07-13 01:46:01 -07:00
parent 49fa86d6bb
commit af9c050e93
3 changed files with 27 additions and 24 deletions
+10 -10
View File
@@ -13,7 +13,7 @@ import { CellData } from 'common/buffer/CellData';
import { Attributes } from 'common/buffer/Constants'; import { Attributes } from 'common/buffer/Constants';
import { AttributeData } from 'common/buffer/AttributeData'; import { AttributeData } from 'common/buffer/AttributeData';
import { Params } from 'common/parser/Params'; import { Params } from 'common/parser/Params';
import { MockCoreService, MockBufferService } from 'common/TestUtils.test'; import { MockCoreService, MockBufferService, MockOptionsService } from 'common/TestUtils.test';
import { IBufferService } from 'common/services/Services'; import { IBufferService } from 'common/services/Services';
function getCursor(term: TestTerminal): number[] { function getCursor(term: TestTerminal): number[] {
@@ -31,7 +31,7 @@ describe('InputHandler', () => {
bufferService.buffer.x = 1; bufferService.buffer.x = 1;
bufferService.buffer.y = 2; bufferService.buffer.y = 2;
bufferService.buffer.ybase = 0; bufferService.buffer.ybase = 0;
const inputHandler = new InputHandler(terminal, bufferService, new MockCoreService()); const inputHandler = new InputHandler(terminal, bufferService, new MockCoreService(), new MockOptionsService());
// Save cursor position // Save cursor position
inputHandler.saveCursor(); inputHandler.saveCursor();
assert.equal(bufferService.buffer.x, 1); assert.equal(bufferService.buffer.x, 1);
@@ -50,7 +50,7 @@ describe('InputHandler', () => {
describe('setCursorStyle', () => { describe('setCursorStyle', () => {
it('should call Terminal.setOption with correct params', () => { it('should call Terminal.setOption with correct params', () => {
const terminal = new MockInputHandlingTerminal(); const terminal = new MockInputHandlingTerminal();
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService()); const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService(), new MockOptionsService());
const collect = ' '; const collect = ' ';
inputHandler.setCursorStyle(Params.fromArray([0]), collect); inputHandler.setCursorStyle(Params.fromArray([0]), collect);
@@ -93,7 +93,7 @@ describe('InputHandler', () => {
const terminal = new MockInputHandlingTerminal(); const terminal = new MockInputHandlingTerminal();
const collect = '?'; const collect = '?';
terminal.bracketedPasteMode = false; terminal.bracketedPasteMode = false;
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService()); const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService(), new MockOptionsService());
// Set bracketed paste mode // Set bracketed paste mode
inputHandler.setMode(Params.fromArray([2004]), collect); inputHandler.setMode(Params.fromArray([2004]), collect);
assert.equal(terminal.bracketedPasteMode, true); assert.equal(terminal.bracketedPasteMode, true);
@@ -112,7 +112,7 @@ describe('InputHandler', () => {
it('insertChars', function(): void { it('insertChars', function(): void {
const term = new Terminal(); const term = new Terminal();
const bufferService = new MockBufferService(80, 30); const bufferService = new MockBufferService(80, 30);
const inputHandler = new InputHandler(term, bufferService, new MockCoreService()); const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockOptionsService());
// insert some data in first and second line // insert some data in first and second line
inputHandler.parse(Array(bufferService.cols - 9).join('a')); inputHandler.parse(Array(bufferService.cols - 9).join('a'));
@@ -150,7 +150,7 @@ describe('InputHandler', () => {
it('deleteChars', function(): void { it('deleteChars', function(): void {
const term = new Terminal(); const term = new Terminal();
const bufferService = new MockBufferService(80, 30); const bufferService = new MockBufferService(80, 30);
const inputHandler = new InputHandler(term, bufferService, new MockCoreService()); const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockOptionsService());
// insert some data in first and second line // insert some data in first and second line
inputHandler.parse(Array(bufferService.cols - 9).join('a')); inputHandler.parse(Array(bufferService.cols - 9).join('a'));
@@ -191,7 +191,7 @@ describe('InputHandler', () => {
it('eraseInLine', function(): void { it('eraseInLine', function(): void {
const term = new Terminal(); const term = new Terminal();
const bufferService = new MockBufferService(80, 30); const bufferService = new MockBufferService(80, 30);
const inputHandler = new InputHandler(term, bufferService, new MockCoreService()); const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockOptionsService());
// fill 6 lines to test 3 different states // fill 6 lines to test 3 different states
inputHandler.parse(Array(bufferService.cols + 1).join('a')); inputHandler.parse(Array(bufferService.cols + 1).join('a'));
@@ -220,7 +220,7 @@ describe('InputHandler', () => {
it('eraseInDisplay', function(): void { it('eraseInDisplay', function(): void {
const term = new Terminal({cols: 80, rows: 7}); const term = new Terminal({cols: 80, rows: 7});
const bufferService = new MockBufferService(80, 7); const bufferService = new MockBufferService(80, 7);
const inputHandler = new InputHandler(term, bufferService, new MockCoreService()); const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockOptionsService());
// fill display with a's // fill display with a's
for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a')); for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
@@ -355,7 +355,7 @@ describe('InputHandler', () => {
describe('print', () => { describe('print', () => {
it('should not cause an infinite loop (regression test)', () => { it('should not cause an infinite loop (regression test)', () => {
const term = new Terminal(); const term = new Terminal();
const inputHandler = new InputHandler(term, new MockBufferService(80, 30), new MockCoreService()); const inputHandler = new InputHandler(term, new MockBufferService(80, 30), new MockCoreService(), new MockOptionsService());
const container = new Uint32Array(10); const container = new Uint32Array(10);
container[0] = 0x200B; container[0] = 0x200B;
inputHandler.print(container, 0, 1); inputHandler.print(container, 0, 1);
@@ -370,7 +370,7 @@ describe('InputHandler', () => {
beforeEach(() => { beforeEach(() => {
term = new Terminal(); term = new Terminal();
bufferService = new MockBufferService(80, 30); bufferService = new MockBufferService(80, 30);
handler = new InputHandler(term, bufferService, new MockCoreService()); handler = new InputHandler(term, bufferService, new MockCoreService(), new MockOptionsService());
}); });
it('should handle DECSET/DECRST 47 (alt screen buffer)', () => { it('should handle DECSET/DECRST 47 (alt screen buffer)', () => {
handler.parse('\x1b[?47h\r\n\x1b[31mJUNK\x1b[?47lTEST'); handler.parse('\x1b[?47h\r\n\x1b[31mJUNK\x1b[?47lTEST');
+16 -13
View File
@@ -19,7 +19,7 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content
import { CellData } from 'common/buffer/CellData'; import { CellData } from 'common/buffer/CellData';
import { AttributeData } from 'common/buffer/AttributeData'; import { AttributeData } from 'common/buffer/AttributeData';
import { IAttributeData, IDisposable } from 'common/Types'; import { IAttributeData, IDisposable } from 'common/Types';
import { ICoreService, IBufferService } from 'common/services/Services'; import { ICoreService, IBufferService, IOptionsService } from 'common/services/Services';
import { ISelectionService } from 'browser/services/Services'; import { ISelectionService } from 'browser/services/Services';
/** /**
@@ -42,8 +42,9 @@ class DECRQSS implements IDcsHandler {
private _data: Uint32Array = new Uint32Array(0); private _data: Uint32Array = new Uint32Array(0);
constructor( constructor(
private _terminal: any, private _bufferService: IBufferService,
private _bufferService: IBufferService private _coreService: ICoreService,
private _optionsService: IOptionsService
) { } ) { }
hook(collect: string, params: IParams, flag: number): void { hook(collect: string, params: IParams, flag: number): void {
@@ -60,25 +61,26 @@ class DECRQSS implements IDcsHandler {
switch (data) { switch (data) {
// valid: DCS 1 $ r Pt ST (xterm) // valid: DCS 1 $ r Pt ST (xterm)
case '"q': // DECSCA case '"q': // DECSCA
return this._terminal.handler(`${C0.ESC}P1$r0"q${C0.ESC}\\`); return this._coreService.triggerDataEvent(`${C0.ESC}P1$r0"q${C0.ESC}\\`);
case '"p': // DECSCL case '"p': // DECSCL
return this._terminal.handler(`${C0.ESC}P1$r61"p${C0.ESC}\\`); return this._coreService.triggerDataEvent(`${C0.ESC}P1$r61"p${C0.ESC}\\`);
case 'r': // DECSTBM case 'r': // DECSTBM
const pt = '' + (this._bufferService.buffer.scrollTop + 1) + const pt = '' + (this._bufferService.buffer.scrollTop + 1) +
';' + (this._bufferService.buffer.scrollBottom + 1) + 'r'; ';' + (this._bufferService.buffer.scrollBottom + 1) + 'r';
return this._terminal.handler(`${C0.ESC}P1$r${pt}${C0.ESC}\\`); return this._coreService.triggerDataEvent(`${C0.ESC}P1$r${pt}${C0.ESC}\\`);
case 'm': // SGR case 'm': // SGR
// TODO: report real settings instead of 0m // TODO: report real settings instead of 0m
return this._terminal.handler(`${C0.ESC}P1$r0m${C0.ESC}\\`); return this._coreService.triggerDataEvent(`${C0.ESC}P1$r0m${C0.ESC}\\`);
case ' q': // DECSCUSR case ' q': // DECSCUSR
const STYLES: {[key: string]: number} = {'block': 2, 'underline': 4, 'bar': 6}; const STYLES: {[key: string]: number} = {'block': 2, 'underline': 4, 'bar': 6};
let style = STYLES[this._terminal.getOption('cursorStyle')]; let style = STYLES[this._optionsService.options.cursorStyle];
style -= this._terminal.getOption('cursorBlink'); style -= this._optionsService.options.cursorBlink ? 1 : 0;
return this._terminal.handler(`${C0.ESC}P1$r${style} q${C0.ESC}\\`); return this._coreService.triggerDataEvent(`${C0.ESC}P1$r${style} q${C0.ESC}\\`);
default: default:
// invalid: DCS 0 $ r Pt ST (xterm) // invalid: DCS 0 $ r Pt ST (xterm)
this._terminal.error('Unknown DCS $q %s', data); // TODO: Move this into a log service
this._terminal.handler(`${C0.ESC}P0$r${C0.ESC}\\`); console.error('Unknown DCS $q %s', data);
this._coreService.triggerDataEvent(`${C0.ESC}P0$r${C0.ESC}\\`);
} }
} }
} }
@@ -129,6 +131,7 @@ export class InputHandler extends Disposable implements IInputHandler {
protected _terminal: IInputHandlingTerminal, protected _terminal: IInputHandlingTerminal,
private _bufferService: IBufferService, private _bufferService: IBufferService,
private _coreService: ICoreService, private _coreService: ICoreService,
private _optionsService: IOptionsService,
private _parser: IEscapeSequenceParser = new EscapeSequenceParser()) private _parser: IEscapeSequenceParser = new EscapeSequenceParser())
{ {
super(); super();
@@ -297,7 +300,7 @@ export class InputHandler extends Disposable implements IInputHandler {
/** /**
* DCS handler * DCS handler
*/ */
this._parser.setDcsHandler('$q', new DECRQSS(this._terminal, this._bufferService)); this._parser.setDcsHandler('$q', new DECRQSS(this._bufferService, this._coreService, this._optionsService));
} }
public dispose(): void { public dispose(): void {
+1 -1
View File
@@ -297,7 +297,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._userScrolling = false; this._userScrolling = false;
// Register input handler and refire/handle events // Register input handler and refire/handle events
this._inputHandler = new InputHandler(this, this._bufferService, this._coreService); this._inputHandler = new InputHandler(this, this._bufferService, this._coreService, this.optionsService);
this._inputHandler.onCursorMove(() => this._onCursorMove.fire()); this._inputHandler.onCursorMove(() => this._onCursorMove.fire());
this._inputHandler.onLineFeed(() => this._onLineFeed.fire()); this._inputHandler.onLineFeed(() => this._onLineFeed.fire());
this.register(this._inputHandler); this.register(this._inputHandler);