Get type safety in DI, fix character joiner not using buffer service

This commit is contained in:
Daniel Imms
2019-07-13 22:02:13 -07:00
parent 8359605951
commit 5cc8ad802c
10 changed files with 85 additions and 20 deletions
+4 -3
View File
@@ -250,8 +250,9 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._instantiationService.setService(ICoreService, this._coreService);
this._coreService.onData(e => this._onData.fire(e));
this._dirtyRowService = this._instantiationService.createInstance(DirtyRowService);
// this._instantiationService.setService(IDirtyRowService, this._dirtyRowService);
this._instantiationService.setService(IDirtyRowService, this._dirtyRowService);
this._logService = new LogService(this.optionsService);
this._instantiationService.setService(ILogService, this._logService);
this._setupOptionsListeners();
this._setup();
@@ -684,8 +685,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
private _createRenderer(): IRenderer {
switch (this.options.rendererType) {
case 'canvas': return new Renderer(this, this._colorManager.colors, this._charSizeService); break;
case 'dom': return new DomRenderer(this, this._colorManager.colors, this._charSizeService, this.optionsService); break;
case 'canvas': return new Renderer(this._colorManager.colors, this, this._bufferService, this._charSizeService);
case 'dom': return new DomRenderer(this, this._colorManager.colors, this._charSizeService, this.optionsService);
default: throw new Error(`Unrecognized rendererType "${this.options.rendererType}"`);
}
}
+5
View File
@@ -12,6 +12,7 @@ import { BufferSet } from 'common/buffer/BufferSet';
import { IDecPrivateModes } from 'common/Types';
export class MockBufferService implements IBufferService {
_serviceBrand: any;
public get buffer(): IBuffer { return this.buffers.active; }
public buffers: IBufferSet = {} as any;
constructor(
@@ -29,6 +30,7 @@ export class MockBufferService implements IBufferService {
}
export class MockCoreService implements ICoreService {
_serviceBrand: any;
decPrivateModes: IDecPrivateModes = {} as any;
onData: IEvent<string> = new EventEmitter<string>().event;
onUserInput: IEvent<void> = new EventEmitter<void>().event;
@@ -37,6 +39,7 @@ export class MockCoreService implements ICoreService {
}
export class MockDirtyRowService implements IDirtyRowService {
_serviceBrand: any;
start: number = 0;
end: number = 0;
clearRange(): void {}
@@ -46,6 +49,7 @@ export class MockDirtyRowService implements IDirtyRowService {
}
export class MockLogService implements ILogService {
_serviceBrand: any;
debug(message: any, ...optionalParams: any[]): void {}
info(message: any, ...optionalParams: any[]): void {}
warn(message: any, ...optionalParams: any[]): void {}
@@ -53,6 +57,7 @@ export class MockLogService implements ILogService {
}
export class MockOptionsService implements IOptionsService {
_serviceBrand: any;
options: ITerminalOptions = clone(DEFAULT_OPTIONS);
onOptionChange: IEvent<string> = new EventEmitter<string>().event;
constructor(testOptions?: IPartialTerminalOptions) {
+2
View File
@@ -11,6 +11,8 @@ export const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars
export const MINIMUM_ROWS = 1;
export class BufferService implements IBufferService {
_serviceBrand: any;
public cols: number;
public rows: number;
public buffers: IBufferSet;
+2
View File
@@ -13,6 +13,8 @@ const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
});
export class CoreService implements ICoreService {
_serviceBrand: any;
public decPrivateModes: IDecPrivateModes;
private _onData = new EventEmitter<string>();
+2
View File
@@ -6,6 +6,8 @@
import { IBufferService, IDirtyRowService } from 'common/services/Services';
export class DirtyRowService implements IDirtyRowService {
_serviceBrand: any;
private _start!: number;
private _end!: number;
+2 -12
View File
@@ -12,8 +12,6 @@
import { IInstantiationService, IServiceIdentifier } from 'common/services/Services';
import { getServiceDependencies } from 'common/services/ServiceRegistry';
declare const console: any;
export class ServiceCollection {
private _entries = new Map<IServiceIdentifier<any>, any>();
@@ -70,17 +68,9 @@ export class InstantiationService implements IInstantiationService {
// check for argument mismatches, adjust static args if needed
if (args.length !== firstServiceArgPos) {
console.warn(`[createInstance] First service dependency of ${ctor.name} at position ${
firstServiceArgPos + 1} conflicts with ${args.length} static arguments`);
throw new Error(`[createInstance] First service dependency of ${ctor.name} at position ${firstServiceArgPos + 1} conflicts with ${args.length} static arguments`);
}
let delta = firstServiceArgPos - args.length;
if (delta > 0) {
args = args.concat(new Array(delta));
} else {
args = args.slice(0, firstServiceArgPos);
}
}
console.log('args', args, 'serviceArgs', serviceArgs);
// now create the instance
return <T>new ctor(...[...args, ...serviceArgs]);
}
+3 -1
View File
@@ -37,10 +37,12 @@ const optionsKeyToLogLevel: { [key: string]: LogLevel } = {
const LOG_PREFIX = 'xterm.js: ';
export class LogService implements ILogService {
_serviceBrand: any;
private _logLevel!: LogLevel;
constructor(
private readonly _optionsService: IOptionsService
@IOptionsService private readonly _optionsService: IOptionsService
) {
this._updateLogLevel();
this._optionsService.onOptionChange(key => {
+2
View File
@@ -56,6 +56,8 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({
const CONSTRUCTOR_ONLY_OPTIONS = ['cols', 'rows'];
export class OptionsService implements IOptionsService {
_serviceBrand: any;
public options: ITerminalOptions;
private _onOptionChange = new EventEmitter<string>();
+58 -1
View File
@@ -10,6 +10,8 @@ import { createDecorator } from 'common/services/ServiceRegistry';
export const IBufferService = createDecorator<IBufferService>('BufferService');
export interface IBufferService {
_serviceBrand: any;
readonly cols: number;
readonly rows: number;
readonly buffer: IBuffer;
@@ -23,6 +25,8 @@ export interface IBufferService {
export const ICoreService = createDecorator<ICoreService>('CoreService');
export interface ICoreService {
_serviceBrand: any;
readonly decPrivateModes: IDecPrivateModes;
readonly onData: IEvent<string>;
@@ -41,7 +45,10 @@ export interface ICoreService {
triggerDataEvent(data: string, wasUserInput?: boolean): void;
}
export const IDirtyRowService = createDecorator<IDirtyRowService>('DirtyRowService');
export interface IDirtyRowService {
_serviceBrand: any;
readonly start: number;
readonly end: number;
@@ -56,13 +63,61 @@ export interface IServiceIdentifier<T> {
type: T;
}
export interface IConstructorSignature0<T> {
new(...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature1<A1, T> {
new(first: A1, ...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature2<A1, A2, T> {
new(first: A1, second: A2, ...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature3<A1, A2, A3, T> {
new(first: A1, second: A2, third: A3, ...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature4<A1, A2, A3, A4, T> {
new(first: A1, second: A2, third: A3, fourth: A4, ...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature5<A1, A2, A3, A4, A5, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, ...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature6<A1, A2, A3, A4, A5, A6, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, ...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, ...services: { _serviceBrand: any; }[]): T;
}
export interface IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8, ...services: { _serviceBrand: any; }[]): T;
}
export const IInstantiationService = createDecorator<IInstantiationService>('InstantiationService');
export interface IInstantiationService {
setService<T>(id: IServiceIdentifier<T>, instance: T): void;
createInstance(ctor: any, ...rest: any[]): any;
createInstance<T>(ctor: IConstructorSignature0<T>): T;
createInstance<A1, T>(ctor: IConstructorSignature1<A1, T>, first: A1): T;
createInstance<A1, A2, T>(ctor: IConstructorSignature2<A1, A2, T>, first: A1, second: A2): T;
createInstance<A1, A2, A3, T>(ctor: IConstructorSignature3<A1, A2, A3, T>, first: A1, second: A2, third: A3): T;
createInstance<A1, A2, A3, A4, T>(ctor: IConstructorSignature4<A1, A2, A3, A4, T>, first: A1, second: A2, third: A3, fourth: A4): T;
createInstance<A1, A2, A3, A4, A5, T>(ctor: IConstructorSignature5<A1, A2, A3, A4, A5, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5): T;
createInstance<A1, A2, A3, A4, A5, A6, T>(ctor: IConstructorSignature6<A1, A2, A3, A4, A5, A6, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6): T;
createInstance<A1, A2, A3, A4, A5, A6, A7, T>(ctor: IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7): T;
createInstance<A1, A2, A3, A4, A5, A6, A7, A8, T>(ctor: IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8): T;
}
export const ILogService = createDecorator<ILogService>('LogService');
export interface ILogService {
_serviceBrand: any;
debug(message: any, ...optionalParams: any[]): void;
info(message: any, ...optionalParams: any[]): void;
warn(message: any, ...optionalParams: any[]): void;
@@ -71,6 +126,8 @@ export interface ILogService {
export const IOptionsService = createDecorator<IOptionsService>('OptionsService');
export interface IOptionsService {
_serviceBrand: any;
readonly options: ITerminalOptions;
readonly onOptionChange: IEvent<string>;
+5 -3
View File
@@ -14,6 +14,7 @@ import { CharacterJoinerRegistry } from 'browser/renderer/CharacterJoinerRegistr
import { Disposable } from 'common/Lifecycle';
import { IColorSet } from 'browser/Types';
import { ICharSizeService } from 'browser/services/Services';
import { IBufferService } from '../../out/common/services/Services';
export class Renderer extends Disposable implements IRenderer {
private _renderLayers: IRenderLayer[];
@@ -23,13 +24,14 @@ export class Renderer extends Disposable implements IRenderer {
public dimensions: IRenderDimensions;
constructor(
private _terminal: ITerminal,
private _colors: IColorSet,
private _charSizeService: ICharSizeService
private readonly _terminal: ITerminal,
readonly _bufferService: IBufferService,
private readonly _charSizeService: ICharSizeService
) {
super();
const allowTransparency = this._terminal.options.allowTransparency;
this._characterJoinerRegistry = new CharacterJoinerRegistry(_terminal);
this._characterJoinerRegistry = new CharacterJoinerRegistry(this._bufferService);
this._renderLayers = [
new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency),