Pull render service off instantiation service safely

This commit is contained in:
Daniel Imms
2020-02-04 07:01:25 -08:00
parent 489d8110c9
commit 3d2d35f5b6
5 changed files with 20 additions and 13 deletions
+9 -9
View File
@@ -44,7 +44,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 TestInputHandler(terminal, bufferService, new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new TestInputHandler(terminal, bufferService, new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
inputHandler.curAttrData.fg = 3; inputHandler.curAttrData.fg = 3;
// Save cursor position // Save cursor position
inputHandler.saveCursor(); inputHandler.saveCursor();
@@ -64,7 +64,7 @@ describe('InputHandler', () => {
describe('setCursorStyle', () => { describe('setCursorStyle', () => {
it('should call Terminal.setOption with correct params', () => { it('should call Terminal.setOption with correct params', () => {
const optionsService = new MockOptionsService(); const optionsService = new MockOptionsService();
const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService, new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService, new MockCoreMouseService(), new MockUnicodeService(), {} as any);
inputHandler.setCursorStyle(Params.fromArray([0])); inputHandler.setCursorStyle(Params.fromArray([0]));
assert.equal(optionsService.options['cursorStyle'], 'block'); assert.equal(optionsService.options['cursorStyle'], 'block');
@@ -105,7 +105,7 @@ describe('InputHandler', () => {
it('should toggle Terminal.bracketedPasteMode', () => { it('should toggle Terminal.bracketedPasteMode', () => {
const terminal = new MockInputHandlingTerminal(); const terminal = new MockInputHandlingTerminal();
terminal.bracketedPasteMode = false; terminal.bracketedPasteMode = false;
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
// Set bracketed paste mode // Set bracketed paste mode
inputHandler.setModePrivate(Params.fromArray([2004])); inputHandler.setModePrivate(Params.fromArray([2004]));
assert.equal(terminal.bracketedPasteMode, true); assert.equal(terminal.bracketedPasteMode, true);
@@ -124,7 +124,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 MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new InputHandler(term, bufferService, new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
// 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'));
@@ -162,7 +162,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 MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new InputHandler(term, bufferService, new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
// 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'));
@@ -203,7 +203,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 MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new InputHandler(term, bufferService, new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
// 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'));
@@ -232,7 +232,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 MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new InputHandler(term, bufferService, new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
// 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'));
@@ -367,7 +367,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 MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); const inputHandler = new InputHandler(term, new MockBufferService(80, 30), new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
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);
@@ -382,7 +382,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 MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService()); handler = new InputHandler(term, bufferService, new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
}); });
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');
+4 -2
View File
@@ -18,9 +18,10 @@ 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, IWindowOptions } from 'common/Types'; import { IAttributeData, IDisposable, IWindowOptions } from 'common/Types';
import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService, ICoreMouseService, ICharsetService, IUnicodeService } from 'common/services/Services'; import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService, ICoreMouseService, ICharsetService, IUnicodeService, IInstantiationService } from 'common/services/Services';
import { OscHandler } from 'common/parser/OscParser'; import { OscHandler } from 'common/parser/OscParser';
import { DcsHandler } from 'common/parser/DcsParser'; import { DcsHandler } from 'common/parser/DcsParser';
import { IRenderService } from 'browser/services/Services';
/** /**
* Map collect to glevel. Used in `selectCharset`. * Map collect to glevel. Used in `selectCharset`.
@@ -246,6 +247,7 @@ export class InputHandler extends Disposable implements IInputHandler {
private readonly _optionsService: IOptionsService, private readonly _optionsService: IOptionsService,
private readonly _coreMouseService: ICoreMouseService, private readonly _coreMouseService: ICoreMouseService,
private readonly _unicodeService: IUnicodeService, private readonly _unicodeService: IUnicodeService,
private readonly _instantiationService: IInstantiationService,
private readonly _parser: IEscapeSequenceParser = new EscapeSequenceParser()) private readonly _parser: IEscapeSequenceParser = new EscapeSequenceParser())
{ {
super(); super();
@@ -2459,7 +2461,7 @@ export class InputHandler extends Disposable implements IInputHandler {
return; return;
} }
const second = (params.length > 1) ? params.params[1] : 0; const second = (params.length > 1) ? params.params[1] : 0;
const rs = (this._terminal as any)._renderService; // FIXME: import renderService to get rid of any type here const rs = this._instantiationService.getService(IRenderService);
switch (params.params[0]) { switch (params.params[0]) {
case 14: // GetWinSizePixels, returns CSI 4 ; height ; width t case 14: // GetWinSizePixels, returns CSI 4 ; height ; width t
if (rs && second !== 2) { if (rs && second !== 2) {
+1 -1
View File
@@ -245,7 +245,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._inputHandler.reset(); this._inputHandler.reset();
} else { } else {
// Register input handler and refire/handle events // Register input handler and refire/handle events
this._inputHandler = new InputHandler(this, this._bufferService, this._charsetService, this._coreService, this._dirtyRowService, this._logService, this.optionsService, this._coreMouseService, this.unicodeService); this._inputHandler = new InputHandler(this, this._bufferService, this._charsetService, this._coreService, this._dirtyRowService, this._logService, this.optionsService, this._coreMouseService, this.unicodeService, this._instantiationService);
this._inputHandler.onRequestBell(() => this.bell()); this._inputHandler.onRequestBell(() => this.bell());
this._inputHandler.onRequestRefreshRows((start, end) => this.refresh(start, end)); this._inputHandler.onRequestRefreshRows((start, end) => this.refresh(start, end));
this._inputHandler.onRequestReset(() => this.reset()); this._inputHandler.onRequestReset(() => this.reset());
+5 -1
View File
@@ -36,7 +36,7 @@ export class ServiceCollection {
return this._entries.has(id); return this._entries.has(id);
} }
get<T>(id: IServiceIdentifier<T>): T { get<T>(id: IServiceIdentifier<T>): T | undefined {
return this._entries.get(id); return this._entries.get(id);
} }
} }
@@ -52,6 +52,10 @@ export class InstantiationService implements IInstantiationService {
this._services.set(id, instance); this._services.set(id, instance);
} }
public getService<T>(id: IServiceIdentifier<T>): T | undefined {
return this._services.get(id);
}
public createInstance<T>(ctor: any, ...args: any[]): any { public createInstance<T>(ctor: any, ...args: any[]): any {
const serviceDependencies = getServiceDependencies(ctor).sort((a, b) => a.index - b.index); const serviceDependencies = getServiceDependencies(ctor).sort((a, b) => a.index - b.index);
+1
View File
@@ -171,6 +171,7 @@ export interface IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T> {
export const IInstantiationService = createDecorator<IInstantiationService>('InstantiationService'); export const IInstantiationService = createDecorator<IInstantiationService>('InstantiationService');
export interface IInstantiationService { export interface IInstantiationService {
setService<T>(id: IServiceIdentifier<T>, instance: T): void; setService<T>(id: IServiceIdentifier<T>, instance: T): void;
getService<T>(id: IServiceIdentifier<T>): T | undefined;
createInstance<T>(ctor: IConstructorSignature0<T>): T; createInstance<T>(ctor: IConstructorSignature0<T>): T;
createInstance<A1, T>(ctor: IConstructorSignature1<A1, T>, first: A1): T; createInstance<A1, T>(ctor: IConstructorSignature1<A1, T>, first: A1): T;