Get type safety in DI, fix character joiner not using buffer service
This commit is contained in:
+4
-3
@@ -250,8 +250,9 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
this._instantiationService.setService(ICoreService, this._coreService);
|
this._instantiationService.setService(ICoreService, this._coreService);
|
||||||
this._coreService.onData(e => this._onData.fire(e));
|
this._coreService.onData(e => this._onData.fire(e));
|
||||||
this._dirtyRowService = this._instantiationService.createInstance(DirtyRowService);
|
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._logService = new LogService(this.optionsService);
|
||||||
|
this._instantiationService.setService(ILogService, this._logService);
|
||||||
|
|
||||||
this._setupOptionsListeners();
|
this._setupOptionsListeners();
|
||||||
this._setup();
|
this._setup();
|
||||||
@@ -684,8 +685,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
|
|
||||||
private _createRenderer(): IRenderer {
|
private _createRenderer(): IRenderer {
|
||||||
switch (this.options.rendererType) {
|
switch (this.options.rendererType) {
|
||||||
case 'canvas': return new Renderer(this, this._colorManager.colors, this._charSizeService); 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); break;
|
case 'dom': return new DomRenderer(this, this._colorManager.colors, this._charSizeService, this.optionsService);
|
||||||
default: throw new Error(`Unrecognized rendererType "${this.options.rendererType}"`);
|
default: throw new Error(`Unrecognized rendererType "${this.options.rendererType}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { BufferSet } from 'common/buffer/BufferSet';
|
|||||||
import { IDecPrivateModes } from 'common/Types';
|
import { IDecPrivateModes } from 'common/Types';
|
||||||
|
|
||||||
export class MockBufferService implements IBufferService {
|
export class MockBufferService implements IBufferService {
|
||||||
|
_serviceBrand: any;
|
||||||
public get buffer(): IBuffer { return this.buffers.active; }
|
public get buffer(): IBuffer { return this.buffers.active; }
|
||||||
public buffers: IBufferSet = {} as any;
|
public buffers: IBufferSet = {} as any;
|
||||||
constructor(
|
constructor(
|
||||||
@@ -29,6 +30,7 @@ export class MockBufferService implements IBufferService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MockCoreService implements ICoreService {
|
export class MockCoreService implements ICoreService {
|
||||||
|
_serviceBrand: any;
|
||||||
decPrivateModes: IDecPrivateModes = {} as any;
|
decPrivateModes: IDecPrivateModes = {} as any;
|
||||||
onData: IEvent<string> = new EventEmitter<string>().event;
|
onData: IEvent<string> = new EventEmitter<string>().event;
|
||||||
onUserInput: IEvent<void> = new EventEmitter<void>().event;
|
onUserInput: IEvent<void> = new EventEmitter<void>().event;
|
||||||
@@ -37,6 +39,7 @@ export class MockCoreService implements ICoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MockDirtyRowService implements IDirtyRowService {
|
export class MockDirtyRowService implements IDirtyRowService {
|
||||||
|
_serviceBrand: any;
|
||||||
start: number = 0;
|
start: number = 0;
|
||||||
end: number = 0;
|
end: number = 0;
|
||||||
clearRange(): void {}
|
clearRange(): void {}
|
||||||
@@ -46,6 +49,7 @@ export class MockDirtyRowService implements IDirtyRowService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MockLogService implements ILogService {
|
export class MockLogService implements ILogService {
|
||||||
|
_serviceBrand: any;
|
||||||
debug(message: any, ...optionalParams: any[]): void {}
|
debug(message: any, ...optionalParams: any[]): void {}
|
||||||
info(message: any, ...optionalParams: any[]): void {}
|
info(message: any, ...optionalParams: any[]): void {}
|
||||||
warn(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 {
|
export class MockOptionsService implements IOptionsService {
|
||||||
|
_serviceBrand: any;
|
||||||
options: ITerminalOptions = clone(DEFAULT_OPTIONS);
|
options: ITerminalOptions = clone(DEFAULT_OPTIONS);
|
||||||
onOptionChange: IEvent<string> = new EventEmitter<string>().event;
|
onOptionChange: IEvent<string> = new EventEmitter<string>().event;
|
||||||
constructor(testOptions?: IPartialTerminalOptions) {
|
constructor(testOptions?: IPartialTerminalOptions) {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars
|
|||||||
export const MINIMUM_ROWS = 1;
|
export const MINIMUM_ROWS = 1;
|
||||||
|
|
||||||
export class BufferService implements IBufferService {
|
export class BufferService implements IBufferService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
public cols: number;
|
public cols: number;
|
||||||
public rows: number;
|
public rows: number;
|
||||||
public buffers: IBufferSet;
|
public buffers: IBufferSet;
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export class CoreService implements ICoreService {
|
export class CoreService implements ICoreService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
public decPrivateModes: IDecPrivateModes;
|
public decPrivateModes: IDecPrivateModes;
|
||||||
|
|
||||||
private _onData = new EventEmitter<string>();
|
private _onData = new EventEmitter<string>();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
import { IBufferService, IDirtyRowService } from 'common/services/Services';
|
import { IBufferService, IDirtyRowService } from 'common/services/Services';
|
||||||
|
|
||||||
export class DirtyRowService implements IDirtyRowService {
|
export class DirtyRowService implements IDirtyRowService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
private _start!: number;
|
private _start!: number;
|
||||||
private _end!: number;
|
private _end!: number;
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
import { IInstantiationService, IServiceIdentifier } from 'common/services/Services';
|
import { IInstantiationService, IServiceIdentifier } from 'common/services/Services';
|
||||||
import { getServiceDependencies } from 'common/services/ServiceRegistry';
|
import { getServiceDependencies } from 'common/services/ServiceRegistry';
|
||||||
|
|
||||||
declare const console: any;
|
|
||||||
|
|
||||||
export class ServiceCollection {
|
export class ServiceCollection {
|
||||||
|
|
||||||
private _entries = new Map<IServiceIdentifier<any>, any>();
|
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
|
// check for argument mismatches, adjust static args if needed
|
||||||
if (args.length !== firstServiceArgPos) {
|
if (args.length !== firstServiceArgPos) {
|
||||||
console.warn(`[createInstance] First service dependency of ${ctor.name} at position ${
|
throw new Error(`[createInstance] First service dependency of ${ctor.name} at position ${firstServiceArgPos + 1} conflicts with ${args.length} static arguments`);
|
||||||
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
|
// now create the instance
|
||||||
return <T>new ctor(...[...args, ...serviceArgs]);
|
return <T>new ctor(...[...args, ...serviceArgs]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,10 +37,12 @@ const optionsKeyToLogLevel: { [key: string]: LogLevel } = {
|
|||||||
const LOG_PREFIX = 'xterm.js: ';
|
const LOG_PREFIX = 'xterm.js: ';
|
||||||
|
|
||||||
export class LogService implements ILogService {
|
export class LogService implements ILogService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
private _logLevel!: LogLevel;
|
private _logLevel!: LogLevel;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _optionsService: IOptionsService
|
@IOptionsService private readonly _optionsService: IOptionsService
|
||||||
) {
|
) {
|
||||||
this._updateLogLevel();
|
this._updateLogLevel();
|
||||||
this._optionsService.onOptionChange(key => {
|
this._optionsService.onOptionChange(key => {
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({
|
|||||||
const CONSTRUCTOR_ONLY_OPTIONS = ['cols', 'rows'];
|
const CONSTRUCTOR_ONLY_OPTIONS = ['cols', 'rows'];
|
||||||
|
|
||||||
export class OptionsService implements IOptionsService {
|
export class OptionsService implements IOptionsService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
public options: ITerminalOptions;
|
public options: ITerminalOptions;
|
||||||
|
|
||||||
private _onOptionChange = new EventEmitter<string>();
|
private _onOptionChange = new EventEmitter<string>();
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import { createDecorator } from 'common/services/ServiceRegistry';
|
|||||||
|
|
||||||
export const IBufferService = createDecorator<IBufferService>('BufferService');
|
export const IBufferService = createDecorator<IBufferService>('BufferService');
|
||||||
export interface IBufferService {
|
export interface IBufferService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
readonly cols: number;
|
readonly cols: number;
|
||||||
readonly rows: number;
|
readonly rows: number;
|
||||||
readonly buffer: IBuffer;
|
readonly buffer: IBuffer;
|
||||||
@@ -23,6 +25,8 @@ export interface IBufferService {
|
|||||||
|
|
||||||
export const ICoreService = createDecorator<ICoreService>('CoreService');
|
export const ICoreService = createDecorator<ICoreService>('CoreService');
|
||||||
export interface ICoreService {
|
export interface ICoreService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
readonly decPrivateModes: IDecPrivateModes;
|
readonly decPrivateModes: IDecPrivateModes;
|
||||||
|
|
||||||
readonly onData: IEvent<string>;
|
readonly onData: IEvent<string>;
|
||||||
@@ -41,7 +45,10 @@ export interface ICoreService {
|
|||||||
triggerDataEvent(data: string, wasUserInput?: boolean): void;
|
triggerDataEvent(data: string, wasUserInput?: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const IDirtyRowService = createDecorator<IDirtyRowService>('DirtyRowService');
|
||||||
export interface IDirtyRowService {
|
export interface IDirtyRowService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
readonly start: number;
|
readonly start: number;
|
||||||
readonly end: number;
|
readonly end: number;
|
||||||
|
|
||||||
@@ -56,13 +63,61 @@ export interface IServiceIdentifier<T> {
|
|||||||
type: 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 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;
|
||||||
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 {
|
export interface ILogService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
debug(message: any, ...optionalParams: any[]): void;
|
debug(message: any, ...optionalParams: any[]): void;
|
||||||
info(message: any, ...optionalParams: any[]): void;
|
info(message: any, ...optionalParams: any[]): void;
|
||||||
warn(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 const IOptionsService = createDecorator<IOptionsService>('OptionsService');
|
||||||
export interface IOptionsService {
|
export interface IOptionsService {
|
||||||
|
_serviceBrand: any;
|
||||||
|
|
||||||
readonly options: ITerminalOptions;
|
readonly options: ITerminalOptions;
|
||||||
|
|
||||||
readonly onOptionChange: IEvent<string>;
|
readonly onOptionChange: IEvent<string>;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { CharacterJoinerRegistry } from 'browser/renderer/CharacterJoinerRegistr
|
|||||||
import { Disposable } from 'common/Lifecycle';
|
import { Disposable } from 'common/Lifecycle';
|
||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet } from 'browser/Types';
|
||||||
import { ICharSizeService } from 'browser/services/Services';
|
import { ICharSizeService } from 'browser/services/Services';
|
||||||
|
import { IBufferService } from '../../out/common/services/Services';
|
||||||
|
|
||||||
export class Renderer extends Disposable implements IRenderer {
|
export class Renderer extends Disposable implements IRenderer {
|
||||||
private _renderLayers: IRenderLayer[];
|
private _renderLayers: IRenderLayer[];
|
||||||
@@ -23,13 +24,14 @@ export class Renderer extends Disposable implements IRenderer {
|
|||||||
public dimensions: IRenderDimensions;
|
public dimensions: IRenderDimensions;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _terminal: ITerminal,
|
|
||||||
private _colors: IColorSet,
|
private _colors: IColorSet,
|
||||||
private _charSizeService: ICharSizeService
|
private readonly _terminal: ITerminal,
|
||||||
|
readonly _bufferService: IBufferService,
|
||||||
|
private readonly _charSizeService: ICharSizeService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
const allowTransparency = this._terminal.options.allowTransparency;
|
const allowTransparency = this._terminal.options.allowTransparency;
|
||||||
this._characterJoinerRegistry = new CharacterJoinerRegistry(_terminal);
|
this._characterJoinerRegistry = new CharacterJoinerRegistry(this._bufferService);
|
||||||
|
|
||||||
this._renderLayers = [
|
this._renderLayers = [
|
||||||
new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency),
|
new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency),
|
||||||
|
|||||||
Reference in New Issue
Block a user