Adopt DI in browser services
This commit is contained in:
+13
-9
@@ -251,7 +251,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
||||
this._coreService.onData(e => this._onData.fire(e));
|
||||
this._dirtyRowService = this._instantiationService.createInstance(DirtyRowService);
|
||||
this._instantiationService.setService(IDirtyRowService, this._dirtyRowService);
|
||||
this._logService = new LogService(this.optionsService);
|
||||
this._logService = this._instantiationService.createInstance(LogService);
|
||||
this._instantiationService.setService(ILogService, this._logService);
|
||||
|
||||
this._setupOptionsListeners();
|
||||
@@ -585,7 +585,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
||||
this.register(addDisposableDomListener(this.textarea, 'blur', () => this._onTextAreaBlur()));
|
||||
this._helperContainer.appendChild(this.textarea);
|
||||
|
||||
this._charSizeService = new CharSizeService(this._document, this._helperContainer, this.optionsService);
|
||||
this._charSizeService = this._instantiationService.createInstance(CharSizeService, this._document, this._helperContainer);
|
||||
this._instantiationService.setService(ICharSizeService, this._charSizeService);
|
||||
|
||||
this._compositionView = document.createElement('div');
|
||||
this._compositionView.classList.add('composition-view');
|
||||
@@ -601,12 +602,15 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
||||
this._colorManager.setTheme(this._theme);
|
||||
|
||||
const renderer = this._createRenderer();
|
||||
this._renderService = new RenderService(renderer, this.rows, this.screenElement, this.optionsService, this._charSizeService);
|
||||
this._renderService = this._instantiationService.createInstance(RenderService, renderer, this.rows, this.screenElement);
|
||||
this._instantiationService.setService(IRenderService, this._renderService);
|
||||
this._renderService.onRender(e => this._onRender.fire(e));
|
||||
this.onResize(e => this._renderService.resize(e.cols, e.rows));
|
||||
|
||||
this._soundService = new SoundService(this.optionsService);
|
||||
this._mouseService = new MouseService(this._renderService, this._charSizeService);
|
||||
this._soundService = this._instantiationService.createInstance(SoundService);
|
||||
this._instantiationService.setService(ISoundService, this._soundService);
|
||||
this._mouseService = this._instantiationService.createInstance(MouseService);
|
||||
this._instantiationService.setService(IMouseService, this._mouseService);
|
||||
|
||||
this.viewport = new Viewport(
|
||||
(amount: number, suppressEvent: boolean) => this.scrollLines(amount, suppressEvent),
|
||||
@@ -625,11 +629,11 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
||||
this.register(this.onFocus(() => this._renderService.onFocus()));
|
||||
this.register(this._renderService.onDimensionsChange(() => this.viewport.syncScrollArea()));
|
||||
|
||||
this._selectionService = new SelectionService(
|
||||
this._selectionService = this._instantiationService.createInstance(SelectionService,
|
||||
(amount: number, suppressEvent: boolean) => this.scrollLines(amount, suppressEvent),
|
||||
this.element, this.screenElement, this._charSizeService, this._bufferService, this._coreService,
|
||||
this._mouseService, this.optionsService
|
||||
);
|
||||
this.element,
|
||||
this.screenElement);
|
||||
this._instantiationService.setService(ISelectionService, this._selectionService);
|
||||
this.register(this._selectionService.onSelectionChange(() => this._onSelectionChange.fire()));
|
||||
this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this._selectionService.onMouseDown(e)));
|
||||
this.register(this._selectionService.onRedrawRequest(e => this._renderService.onSelectionChanged(e.start, e.end, e.columnSelectMode)));
|
||||
|
||||
@@ -7,6 +7,7 @@ import { IEvent, EventEmitter } from 'common/EventEmitter';
|
||||
import { ICharSizeService, IMouseService } from 'browser/services/Services';
|
||||
|
||||
export class MockCharSizeService implements ICharSizeService {
|
||||
_serviceBrand: any;
|
||||
get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
|
||||
onCharSizeChange: IEvent<void> = new EventEmitter<void>().event;
|
||||
constructor(public width: number, public height: number) {}
|
||||
@@ -14,6 +15,7 @@ export class MockCharSizeService implements ICharSizeService {
|
||||
}
|
||||
|
||||
export class MockMouseService implements IMouseService {
|
||||
_serviceBrand: any;
|
||||
public getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import { IEvent, EventEmitter } from 'common/EventEmitter';
|
||||
import { ICharSizeService } from 'browser/services/Services';
|
||||
|
||||
export class CharSizeService implements ICharSizeService {
|
||||
_serviceBrand: any;
|
||||
|
||||
public width: number = 0;
|
||||
public height: number = 0;
|
||||
private _measureStrategy: IMeasureStrategy;
|
||||
@@ -18,9 +20,9 @@ export class CharSizeService implements ICharSizeService {
|
||||
public get onCharSizeChange(): IEvent<void> { return this._onCharSizeChange.event; }
|
||||
|
||||
constructor(
|
||||
document: Document,
|
||||
parentElement: HTMLElement,
|
||||
private _optionsService: IOptionsService
|
||||
readonly document: Document,
|
||||
readonly parentElement: HTMLElement,
|
||||
@IOptionsService private readonly _optionsService: IOptionsService
|
||||
) {
|
||||
this._measureStrategy = new DomMeasureStrategy(document, parentElement, this._optionsService);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ import { ICharSizeService, IRenderService, IMouseService } from './Services';
|
||||
import { getCoords, getRawByteCoords } from 'browser/input/Mouse';
|
||||
|
||||
export class MouseService implements IMouseService {
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(
|
||||
private readonly _renderService: IRenderService,
|
||||
private readonly _charSizeService: ICharSizeService
|
||||
@IRenderService private readonly _renderService: IRenderService,
|
||||
@ICharSizeService private readonly _charSizeService: ICharSizeService
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ import { IOptionsService } from 'common/services/Services';
|
||||
import { ICharSizeService, IRenderService } from 'browser/services/Services';
|
||||
|
||||
export class RenderService extends Disposable implements IRenderService {
|
||||
_serviceBrand: any;
|
||||
|
||||
private _renderDebouncer: RenderDebouncer;
|
||||
private _screenDprMonitor: ScreenDprMonitor;
|
||||
|
||||
@@ -34,9 +36,9 @@ export class RenderService extends Disposable implements IRenderService {
|
||||
constructor(
|
||||
private _renderer: IRenderer,
|
||||
private _rowCount: number,
|
||||
screenElement: HTMLElement,
|
||||
optionsService: IOptionsService,
|
||||
charSizeService: ICharSizeService
|
||||
readonly screenElement: HTMLElement,
|
||||
@IOptionsService readonly optionsService: IOptionsService,
|
||||
@ICharSizeService readonly charSizeService: ICharSizeService
|
||||
) {
|
||||
super();
|
||||
this._renderDebouncer = new RenderDebouncer((start, end) => this._renderRows(start, end));
|
||||
|
||||
@@ -67,6 +67,8 @@ export const enum SelectionMode {
|
||||
* when the selection is ready to be redrawn (on an animation frame).
|
||||
*/
|
||||
export class SelectionService implements ISelectionService {
|
||||
_serviceBrand: any;
|
||||
|
||||
protected _model: SelectionModel;
|
||||
|
||||
/**
|
||||
@@ -114,11 +116,11 @@ export class SelectionService implements ISelectionService {
|
||||
private readonly _scrollLines: (amount: number, suppressEvent: boolean) => void,
|
||||
private readonly _element: HTMLElement,
|
||||
private readonly _screenElement: HTMLElement,
|
||||
private readonly _charSizeService: ICharSizeService,
|
||||
private readonly _bufferService: IBufferService,
|
||||
private readonly _coreService: ICoreService,
|
||||
private readonly _mouseService: IMouseService,
|
||||
private readonly _optionsService: IOptionsService
|
||||
@ICharSizeService private readonly _charSizeService: ICharSizeService,
|
||||
@IBufferService private readonly _bufferService: IBufferService,
|
||||
@ICoreService private readonly _coreService: ICoreService,
|
||||
@IMouseService private readonly _mouseService: IMouseService,
|
||||
@IOptionsService private readonly _optionsService: IOptionsService
|
||||
) {
|
||||
// Init listeners
|
||||
this._mouseMoveListener = event => this._onMouseMove(<MouseEvent>event);
|
||||
|
||||
@@ -7,8 +7,12 @@ import { IEvent } from 'common/EventEmitter';
|
||||
import { IRenderDimensions, IRenderer, CharacterJoinerHandler } from 'browser/renderer/Types';
|
||||
import { IColorSet } from 'browser/Types';
|
||||
import { ISelectionRedrawRequestEvent } from 'browser/selection/Types';
|
||||
import { createDecorator } from 'common/services/ServiceRegistry';
|
||||
|
||||
export const ICharSizeService = createDecorator<ICharSizeService>('CharSizeService');
|
||||
export interface ICharSizeService {
|
||||
_serviceBrand: any;
|
||||
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
readonly hasValidSize: boolean;
|
||||
@@ -18,12 +22,18 @@ export interface ICharSizeService {
|
||||
measure(): void;
|
||||
}
|
||||
|
||||
export const IMouseService = createDecorator<IMouseService>('MouseService');
|
||||
export interface IMouseService {
|
||||
_serviceBrand: any;
|
||||
|
||||
getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined;
|
||||
getRawByteCoords(event: MouseEvent, element: HTMLElement, colCount: number, rowCount: number): { x: number, y: number } | undefined;
|
||||
}
|
||||
|
||||
export const IRenderService = createDecorator<IRenderService>('RenderService');
|
||||
export interface IRenderService {
|
||||
_serviceBrand: any;
|
||||
|
||||
onDimensionsChange: IEvent<IRenderDimensions>;
|
||||
onRender: IEvent<{ start: number, end: number }>;
|
||||
onRefreshRequest: IEvent<{ start: number, end: number }>;
|
||||
@@ -48,7 +58,10 @@ export interface IRenderService {
|
||||
deregisterCharacterJoiner(joinerId: number): boolean;
|
||||
}
|
||||
|
||||
export const ISelectionService = createDecorator<ISelectionService>('SelectionService');
|
||||
export interface ISelectionService {
|
||||
_serviceBrand: any;
|
||||
|
||||
readonly selectionText: string;
|
||||
readonly hasSelection: boolean;
|
||||
readonly selectionStart: [number, number] | undefined;
|
||||
@@ -73,6 +86,9 @@ export interface ISelectionService {
|
||||
onMouseDown(event: MouseEvent): void;
|
||||
}
|
||||
|
||||
export const ISoundService = createDecorator<ISoundService>('SoundService');
|
||||
export interface ISoundService {
|
||||
_serviceBrand: any;
|
||||
|
||||
playBellSound(): void;
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import { IOptionsService } from 'common/services/Services';
|
||||
import { ISoundService } from 'browser/services/Services';
|
||||
|
||||
export class SoundService implements ISoundService {
|
||||
_serviceBrand: any;
|
||||
|
||||
private static _audioContext: AudioContext;
|
||||
|
||||
static get audioContext(): AudioContext | null {
|
||||
@@ -22,7 +24,7 @@ export class SoundService implements ISoundService {
|
||||
}
|
||||
|
||||
constructor(
|
||||
private _optionsService: IOptionsService
|
||||
@IOptionsService private _optionsService: IOptionsService
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user