Create new event with emitter object to simplify code

This commit is contained in:
Daniel Imms
2022-10-01 08:45:40 -07:00
parent 969db2bcf9
commit ed15a8e170
33 changed files with 247 additions and 307 deletions
@@ -14,7 +14,7 @@ import { IColorSet, ILinkifier2 } from 'browser/Types';
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService } from 'browser/services/Services'; import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService } from 'browser/services/Services';
import { IBufferService, IOptionsService, IDecorationService, ICoreService } from 'common/services/Services'; import { IBufferService, IOptionsService, IDecorationService, ICoreService } from 'common/services/Services';
import { removeTerminalFromCache } from './atlas/CharAtlasCache'; import { removeTerminalFromCache } from './atlas/CharAtlasCache';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { initEvent, EventEmitter, IEvent } from 'common/EventEmitter';
import { observeDevicePixelDimensions } from 'browser/renderer/DevicePixelObserver'; import { observeDevicePixelDimensions } from 'browser/renderer/DevicePixelObserver';
let nextRendererId = 1; let nextRendererId = 1;
@@ -27,8 +27,7 @@ export class CanvasRenderer extends Disposable implements IRenderer {
public dimensions: IRenderDimensions; public dimensions: IRenderDimensions;
private readonly _onRequestRedraw = new EventEmitter<IRequestRedrawEvent>(); public readonly onRequestRedraw = initEvent<IRequestRedrawEvent>();
public readonly onRequestRedraw = this._onRequestRedraw.event;
constructor( constructor(
private _colors: IColorSet, private _colors: IColorSet,
@@ -48,7 +47,7 @@ export class CanvasRenderer extends Disposable implements IRenderer {
new TextRenderLayer(this._screenElement, 0, this._colors, allowTransparency, this._id, this._bufferService, this._optionsService, characterJoinerService, decorationService, this._coreBrowserService), new TextRenderLayer(this._screenElement, 0, this._colors, allowTransparency, this._id, this._bufferService, this._optionsService, characterJoinerService, decorationService, this._coreBrowserService),
new SelectionRenderLayer(this._screenElement, 1, this._colors, this._id, this._bufferService, this._coreBrowserService, decorationService, this._optionsService), new SelectionRenderLayer(this._screenElement, 1, this._colors, this._id, this._bufferService, this._coreBrowserService, decorationService, this._optionsService),
new LinkRenderLayer(this._screenElement, 2, this._colors, this._id, linkifier2, this._bufferService, this._optionsService, decorationService, this._coreBrowserService), new LinkRenderLayer(this._screenElement, 2, this._colors, this._id, linkifier2, this._bufferService, this._optionsService, decorationService, this._coreBrowserService),
new CursorRenderLayer(this._screenElement, 3, this._colors, this._id, this._onRequestRedraw, this._bufferService, this._optionsService, coreService, this._coreBrowserService, decorationService) new CursorRenderLayer(this._screenElement, 3, this._colors, this._id, this.onRequestRedraw, this._bufferService, this._optionsService, coreService, this._coreBrowserService, decorationService)
]; ];
this.dimensions = { this.dimensions = {
scaledCharWidth: 0, scaledCharWidth: 0,
@@ -128,7 +127,7 @@ export class CanvasRenderer extends Disposable implements IRenderer {
this._runOperation(l => l.onSelectionChanged(start, end, columnSelectMode)); this._runOperation(l => l.onSelectionChanged(start, end, columnSelectMode));
// Selection foreground requires a full re-render // Selection foreground requires a full re-render
if (this._colors.selectionForeground) { if (this._colors.selectionForeground) {
this._onRequestRedraw.fire({ start: 0, end: this._bufferService.rows - 1 }); this.onRequestRedraw.fire({ start: 0, end: this._bufferService.rows - 1 });
} }
} }
@@ -201,6 +200,6 @@ export class CanvasRenderer extends Disposable implements IRenderer {
} }
private _requestRedrawViewport(): void { private _requestRedrawViewport(): void {
this._onRequestRedraw.fire({ start: 0, end: this._bufferService.rows - 1 }); this.onRequestRedraw.fire({ start: 0, end: this._bufferService.rows - 1 });
} }
} }
+5 -6
View File
@@ -4,7 +4,7 @@
*/ */
import { Terminal, IDisposable, ITerminalAddon, IBufferRange, IDecoration } from 'xterm'; import { Terminal, IDisposable, ITerminalAddon, IBufferRange, IDecoration } from 'xterm';
import { EventEmitter } from 'common/EventEmitter'; import { initEvent } from 'common/EventEmitter';
export interface ISearchOptions { export interface ISearchOptions {
regex?: boolean; regex?: boolean;
@@ -72,8 +72,7 @@ export class SearchAddon implements ITerminalAddon {
private _resultIndex: number | undefined; private _resultIndex: number | undefined;
private readonly _onDidChangeResults = new EventEmitter<{ resultIndex: number, resultCount: number } | undefined>(); public readonly onDidChangeResults = initEvent<{ resultIndex: number, resultCount: number } | undefined>();
public readonly onDidChangeResults = this._onDidChangeResults.event;
public activate(terminal: Terminal): void { public activate(terminal: Terminal): void {
this._terminal = terminal; this._terminal = terminal;
@@ -89,7 +88,7 @@ export class SearchAddon implements ITerminalAddon {
this._highlightTimeout = setTimeout(() => { this._highlightTimeout = setTimeout(() => {
this.findPrevious(this._cachedSearchTerm!, { ...this._lastSearchOptions, incremental: true, noScroll: true }); this.findPrevious(this._cachedSearchTerm!, { ...this._lastSearchOptions, incremental: true, noScroll: true });
this._resultIndex = this._searchResults ? this._searchResults.size - 1 : -1; this._resultIndex = this._searchResults ? this._searchResults.size - 1 : -1;
this._onDidChangeResults.fire({ resultIndex: this._resultIndex, resultCount: this._searchResults?.size ?? -1 }); this.onDidChangeResults.fire({ resultIndex: this._resultIndex, resultCount: this._searchResults?.size ?? -1 });
}, 200); }, 200);
} }
} }
@@ -325,9 +324,9 @@ export class SearchAddon implements ITerminalAddon {
private _fireResults(term: string, found: boolean, searchOptions?: ISearchOptions): boolean { private _fireResults(term: string, found: boolean, searchOptions?: ISearchOptions): boolean {
if (searchOptions?.decorations) { if (searchOptions?.decorations) {
if (this._resultIndex !== undefined && this._searchResults?.size !== undefined) { if (this._resultIndex !== undefined && this._searchResults?.size !== undefined) {
this._onDidChangeResults.fire({ resultIndex: this._resultIndex, resultCount: this._searchResults.size }); this.onDidChangeResults.fire({ resultIndex: this._resultIndex, resultCount: this._searchResults.size });
} else { } else {
this._onDidChangeResults.fire(undefined); this.onDidChangeResults.fire(undefined);
} }
} }
this._cachedSearchTerm = term; this._cachedSearchTerm = term;
+5 -7
View File
@@ -7,7 +7,7 @@ import { Terminal, ITerminalAddon, IEvent } from 'xterm';
import { WebglRenderer } from './WebglRenderer'; import { WebglRenderer } from './WebglRenderer';
import { ICharacterJoinerService, ICoreBrowserService, IRenderService } from 'browser/services/Services'; import { ICharacterJoinerService, ICoreBrowserService, IRenderService } from 'browser/services/Services';
import { IColorSet } from 'browser/Types'; import { IColorSet } from 'browser/Types';
import { EventEmitter, forwardEvent } from 'common/EventEmitter'; import { EventEmitter, forwardEvent, initEvent } from 'common/EventEmitter';
import { isSafari } from 'common/Platform'; import { isSafari } from 'common/Platform';
import { ICoreService, IDecorationService } from 'common/services/Services'; import { ICoreService, IDecorationService } from 'common/services/Services';
@@ -15,10 +15,8 @@ export class WebglAddon implements ITerminalAddon {
private _terminal?: Terminal; private _terminal?: Terminal;
private _renderer?: WebglRenderer; private _renderer?: WebglRenderer;
private readonly _onChangeTextureAtlas = new EventEmitter<HTMLElement>(); public readonly onChangeTextureAtlas = initEvent<HTMLElement>();
public readonly onChangeTextureAtlas = this._onChangeTextureAtlas.event; public readonly onContextLoss = initEvent<void>();
private readonly _onContextLoss = new EventEmitter<void>();
public readonly onContextLoss = this._onContextLoss.event;
constructor( constructor(
private _preserveDrawingBuffer?: boolean private _preserveDrawingBuffer?: boolean
@@ -39,8 +37,8 @@ export class WebglAddon implements ITerminalAddon {
const decorationService: IDecorationService = (terminal as any)._core._decorationService; const decorationService: IDecorationService = (terminal as any)._core._decorationService;
const colors: IColorSet = (terminal as any)._core._colorManager.colors; const colors: IColorSet = (terminal as any)._core._colorManager.colors;
this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, coreBrowserService, coreService, decorationService, this._preserveDrawingBuffer); this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, coreBrowserService, coreService, decorationService, this._preserveDrawingBuffer);
forwardEvent(this._renderer.onContextLoss, this._onContextLoss); forwardEvent(this._renderer.onContextLoss, this.onContextLoss);
forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas); forwardEvent(this._renderer.onChangeTextureAtlas, this.onChangeTextureAtlas);
renderService.setRenderer(this._renderer); renderService.setRenderer(this._renderer);
} }
+8 -11
View File
@@ -18,7 +18,7 @@ import { IRenderLayer } from './renderLayer/Types';
import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/Types'; import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/Types';
import { observeDevicePixelDimensions } from 'browser/renderer/DevicePixelObserver'; import { observeDevicePixelDimensions } from 'browser/renderer/DevicePixelObserver';
import { ITerminal, IColorSet } from 'browser/Types'; import { ITerminal, IColorSet } from 'browser/Types';
import { EventEmitter } from 'common/EventEmitter'; import { EventEmitter, initEvent } from 'common/EventEmitter';
import { CellData } from 'common/buffer/CellData'; import { CellData } from 'common/buffer/CellData';
import { addDisposableDomListener } from 'browser/Lifecycle'; import { addDisposableDomListener } from 'browser/Lifecycle';
import { ICharacterJoinerService, ICoreBrowserService } from 'browser/services/Services'; import { ICharacterJoinerService, ICoreBrowserService } from 'browser/services/Services';
@@ -53,12 +53,9 @@ export class WebglRenderer extends Disposable implements IRenderer {
private _isAttached: boolean; private _isAttached: boolean;
private _contextRestorationTimeout: number | undefined; private _contextRestorationTimeout: number | undefined;
private readonly _onChangeTextureAtlas = new EventEmitter<HTMLCanvasElement>(); public readonly onChangeTextureAtlas = initEvent<HTMLCanvasElement>();
public readonly onChangeTextureAtlas = this._onChangeTextureAtlas.event; public readonly onRequestRedraw = initEvent<IRequestRedrawEvent>();
private readonly _onRequestRedraw = new EventEmitter<IRequestRedrawEvent>(); public readonly onContextLoss = initEvent<void>();
public readonly onRequestRedraw = this._onRequestRedraw.event;
private readonly _onContextLoss = new EventEmitter<void>();
public readonly onContextLoss = this._onContextLoss.event;
constructor( constructor(
private _terminal: Terminal, private _terminal: Terminal,
@@ -75,7 +72,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
this._renderLayers = [ this._renderLayers = [
new LinkRenderLayer(this._core.screenElement!, 2, this._colors, this._core, this._coreBrowserService), new LinkRenderLayer(this._core.screenElement!, 2, this._colors, this._core, this._coreBrowserService),
new CursorRenderLayer(_terminal, this._core.screenElement!, 3, this._colors, this._onRequestRedraw, this._coreBrowserService, coreService) new CursorRenderLayer(_terminal, this._core.screenElement!, 3, this._colors, this.onRequestRedraw, this._coreBrowserService, coreService)
]; ];
this.dimensions = { this.dimensions = {
scaledCharWidth: 0, scaledCharWidth: 0,
@@ -115,7 +112,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
this._contextRestorationTimeout = setTimeout(() => { this._contextRestorationTimeout = setTimeout(() => {
this._contextRestorationTimeout = undefined; this._contextRestorationTimeout = undefined;
console.warn('webgl context not restored; firing onContextLoss'); console.warn('webgl context not restored; firing onContextLoss');
this._onContextLoss.fire(e); this.onContextLoss.fire(e);
}, 3000 /* ms */); }, 3000 /* ms */);
})); }));
this.register(addDisposableDomListener(this._canvas, 'webglcontextrestored', (e) => { this.register(addDisposableDomListener(this._canvas, 'webglcontextrestored', (e) => {
@@ -283,7 +280,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
throw new Error('The webgl renderer only works with the webgl char atlas'); throw new Error('The webgl renderer only works with the webgl char atlas');
} }
if (this._charAtlas !== atlas) { if (this._charAtlas !== atlas) {
this._onChangeTextureAtlas.fire(atlas.cacheCanvas); this.onChangeTextureAtlas.fire(atlas.cacheCanvas);
} }
this._charAtlas = atlas; this._charAtlas = atlas;
this._charAtlas.warmUp(); this._charAtlas.warmUp();
@@ -676,7 +673,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
} }
private _requestRedrawViewport(): void { private _requestRedrawViewport(): void {
this._onRequestRedraw.fire({ start: 0, end: this._terminal.rows - 1 }); this.onRequestRedraw.fire({ start: 0, end: this._terminal.rows - 1 });
} }
} }
+4 -6
View File
@@ -7,7 +7,7 @@ import { ILinkifier2, ILinkProvider, IBufferCellPosition, ILink, ILinkifierEvent
import { IDisposable } from 'common/Types'; import { IDisposable } from 'common/Types';
import { IMouseService, IRenderService } from './services/Services'; import { IMouseService, IRenderService } from './services/Services';
import { IBufferService } from 'common/services/Services'; import { IBufferService } from 'common/services/Services';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
import { Disposable, getDisposeArrayDisposable, disposeArray } from 'common/Lifecycle'; import { Disposable, getDisposeArrayDisposable, disposeArray } from 'common/Lifecycle';
import { addDisposableDomListener } from 'browser/Lifecycle'; import { addDisposableDomListener } from 'browser/Lifecycle';
@@ -26,10 +26,8 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
private _activeProviderReplies: Map<Number, ILinkWithState[] | undefined> | undefined; private _activeProviderReplies: Map<Number, ILinkWithState[] | undefined> | undefined;
private _activeLine: number = -1; private _activeLine: number = -1;
private readonly _onShowLinkUnderline = this.register(new EventEmitter<ILinkifierEvent>()); public readonly onShowLinkUnderline = this.register(initEvent<ILinkifierEvent>());
public readonly onShowLinkUnderline = this._onShowLinkUnderline.event; public readonly onHideLinkUnderline = this.register(initEvent<ILinkifierEvent>());
private readonly _onHideLinkUnderline = this.register(new EventEmitter<ILinkifierEvent>());
public readonly onHideLinkUnderline = this._onHideLinkUnderline.event;
constructor( constructor(
@IBufferService private readonly _bufferService: IBufferService @IBufferService private readonly _bufferService: IBufferService
@@ -343,7 +341,7 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
const range = link.range; const range = link.range;
const scrollOffset = this._bufferService.buffer.ydisp; const scrollOffset = this._bufferService.buffer.ydisp;
const event = this._createLinkUnderlineEvent(range.start.x - 1, range.start.y - scrollOffset - 1, range.end.x, range.end.y - scrollOffset - 1, undefined); const event = this._createLinkUnderlineEvent(range.start.x - 1, range.start.y - scrollOffset - 1, range.end.x, range.end.y - scrollOffset - 1, undefined);
const emitter = showEvent ? this._onShowLinkUnderline : this._onHideLinkUnderline; const emitter = showEvent ? this.onShowLinkUnderline : this.onHideLinkUnderline;
emitter.fire(event); emitter.fire(event);
} }
+22 -33
View File
@@ -37,7 +37,7 @@ import { ITheme, IMarker, IDisposable, ILinkProvider, IDecorationOptions, IDecor
import { DomRenderer } from 'browser/renderer/dom/DomRenderer'; import { DomRenderer } from 'browser/renderer/dom/DomRenderer';
import { KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, ScrollSource, IColorEvent, ColorIndex, ColorRequestType } from 'common/Types'; import { KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, ScrollSource, IColorEvent, ColorIndex, ColorRequestType } from 'common/Types';
import { evaluateKeyboardEvent } from 'common/input/Keyboard'; import { evaluateKeyboardEvent } from 'common/input/Keyboard';
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent, forwardEvent, initEvent } from 'common/EventEmitter';
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine'; import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { ColorManager } from 'browser/ColorManager'; import { ColorManager } from 'browser/ColorManager';
import { RenderService } from 'browser/services/RenderService'; import { RenderService } from 'browser/services/RenderService';
@@ -122,27 +122,16 @@ export class Terminal extends CoreTerminal implements ITerminal {
private _colorManager: ColorManager | undefined; private _colorManager: ColorManager | undefined;
private _theme: ITheme | undefined; private _theme: ITheme | undefined;
private readonly _onCursorMove = new EventEmitter<void>(); public readonly onCursorMove = initEvent<void>();
public readonly onCursorMove = this._onCursorMove.event; public readonly onKey = initEvent<{ key: string, domEvent: KeyboardEvent }>();
private readonly _onKey = new EventEmitter<{ key: string, domEvent: KeyboardEvent }>(); public readonly onRender = initEvent<{ start: number, end: number }>();
public readonly onKey = this._onKey.event; public readonly onSelectionChange = initEvent<void>();
private readonly _onRender = new EventEmitter<{ start: number, end: number }>(); public readonly onTitleChange = initEvent<string>();
public readonly onRender = this._onRender.event; public readonly onBell = initEvent<void>();
private readonly _onSelectionChange = new EventEmitter<void>(); public readonly onFocus = initEvent<void>();
public readonly onSelectionChange = this._onSelectionChange.event; public readonly onBlur = initEvent<void>();
private readonly _onTitleChange = new EventEmitter<string>(); public readonly onA11yChar = initEvent<string>();
public readonly onTitleChange = this._onTitleChange.event; public readonly onA11yTab = initEvent<number>();
private readonly _onBell = new EventEmitter<void>();
public readonly onBell = this._onBell.event;
private readonly _onFocus = new EventEmitter<void>();
public readonly onFocus = this._onFocus.event;
private readonly _onBlur = new EventEmitter<void>();
public readonly onBlur = this._onBlur.event;
private readonly _onA11yCharEmitter = new EventEmitter<string>();
public readonly onA11yChar = this._onA11yCharEmitter.event;
private readonly _onA11yTabEmitter = new EventEmitter<number>();
public readonly onA11yTab = this._onA11yTabEmitter.event;
/** /**
* Creates a new `Terminal` object. * Creates a new `Terminal` object.
@@ -169,16 +158,16 @@ export class Terminal extends CoreTerminal implements ITerminal {
this._instantiationService.setService(IDecorationService, this._decorationService); this._instantiationService.setService(IDecorationService, this._decorationService);
// Setup InputHandler listeners // Setup InputHandler listeners
this.register(this._inputHandler.onRequestBell(() => this._onBell.fire())); this.register(this._inputHandler.onRequestBell(() => this.onBell.fire()));
this.register(this._inputHandler.onRequestRefreshRows((start, end) => this.refresh(start, end))); this.register(this._inputHandler.onRequestRefreshRows((start, end) => this.refresh(start, end)));
this.register(this._inputHandler.onRequestSendFocus(() => this._reportFocus())); this.register(this._inputHandler.onRequestSendFocus(() => this._reportFocus()));
this.register(this._inputHandler.onRequestReset(() => this.reset())); this.register(this._inputHandler.onRequestReset(() => this.reset()));
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type))); this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
this.register(this._inputHandler.onColor((event) => this._handleColorEvent(event))); this.register(this._inputHandler.onColor((event) => this._handleColorEvent(event)));
this.register(forwardEvent(this._inputHandler.onCursorMove, this._onCursorMove)); this.register(forwardEvent(this._inputHandler.onCursorMove, this.onCursorMove));
this.register(forwardEvent(this._inputHandler.onTitleChange, this._onTitleChange)); this.register(forwardEvent(this._inputHandler.onTitleChange, this.onTitleChange));
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter)); this.register(forwardEvent(this._inputHandler.onA11yChar, this.onA11yChar));
this.register(forwardEvent(this._inputHandler.onA11yTab, this._onA11yTabEmitter)); this.register(forwardEvent(this._inputHandler.onA11yTab, this.onA11yTab));
// Setup listeners // Setup listeners
this.register(this._bufferService.onResize(e => this._afterResize(e.cols, e.rows))); this.register(this._bufferService.onResize(e => this._afterResize(e.cols, e.rows)));
@@ -326,7 +315,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
this.updateCursorStyle(ev); this.updateCursorStyle(ev);
this.element!.classList.add('focus'); this.element!.classList.add('focus');
this._showCursor(); this._showCursor();
this._onFocus.fire(); this.onFocus.fire();
} }
/** /**
@@ -349,7 +338,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
this.coreService.triggerDataEvent(C0.ESC + '[O'); this.coreService.triggerDataEvent(C0.ESC + '[O');
} }
this.element!.classList.remove('focus'); this.element!.classList.remove('focus');
this._onBlur.fire(); this.onBlur.fire();
} }
private _syncTextArea(): void { private _syncTextArea(): void {
@@ -512,7 +501,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
const renderer = this._createRenderer(); const renderer = this._createRenderer();
this._renderService = this.register(this._instantiationService.createInstance(RenderService, renderer, this.rows, this.screenElement)); this._renderService = this.register(this._instantiationService.createInstance(RenderService, renderer, this.rows, this.screenElement));
this._instantiationService.setService(IRenderService, this._renderService); this._instantiationService.setService(IRenderService, this._renderService);
this.register(this._renderService.onRenderedViewportChange(e => this._onRender.fire(e))); this.register(this._renderService.onRenderedViewportChange(e => this.onRender.fire(e)));
this.onResize(e => this._renderService!.resize(e.cols, e.rows)); this.onResize(e => this._renderService!.resize(e.cols, e.rows));
this._compositionView = document.createElement('div'); this._compositionView = document.createElement('div');
@@ -552,7 +541,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
)); ));
this._instantiationService.setService(ISelectionService, this._selectionService); this._instantiationService.setService(ISelectionService, this._selectionService);
this.register(this._selectionService.onRequestScrollLines(e => this.scrollLines(e.amount, e.suppressScrollEvent))); this.register(this._selectionService.onRequestScrollLines(e => this.scrollLines(e.amount, e.suppressScrollEvent)));
this.register(this._selectionService.onSelectionChange(() => this._onSelectionChange.fire())); this.register(this._selectionService.onSelectionChange(() => this.onSelectionChange.fire()));
this.register(this._selectionService.onRequestRedraw(e => this._renderService!.onSelectionChanged(e.start, e.end, e.columnSelectMode))); this.register(this._selectionService.onRequestRedraw(e => this._renderService!.onSelectionChanged(e.start, e.end, e.columnSelectMode)));
this.register(this._selectionService.onLinuxMouseSelection(text => { this.register(this._selectionService.onLinuxMouseSelection(text => {
// If there's a new selection, put it into the textarea, focus and select it // If there's a new selection, put it into the textarea, focus and select it
@@ -1101,7 +1090,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
this.textarea!.value = ''; this.textarea!.value = '';
} }
this._onKey.fire({ key: result.key, domEvent: event }); this.onKey.fire({ key: result.key, domEvent: event });
this._showCursor(); this._showCursor();
this.coreService.triggerDataEvent(result.key, true); this.coreService.triggerDataEvent(result.key, true);
@@ -1184,7 +1173,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
key = String.fromCharCode(key); key = String.fromCharCode(key);
this._onKey.fire({ key, domEvent: ev }); this.onKey.fire({ key, domEvent: ev });
this._showCursor(); this._showCursor();
this.coreService.triggerDataEvent(key, true); this.coreService.triggerDataEvent(key, true);
+10 -10
View File
@@ -4,7 +4,7 @@
*/ */
import { IDisposable, IMarker, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm'; import { IDisposable, IMarker, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm';
import { IEvent, EventEmitter } from 'common/EventEmitter'; import { IEvent, EventEmitter, initEvent } from 'common/EventEmitter';
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IMouseService, IRenderService, ISelectionService } from 'browser/services/Services'; import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IMouseService, IRenderService, ISelectionService } from 'browser/services/Services';
import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/Types'; import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/Types';
import { IColorSet, ITerminal, ILinkifier2, IBrowser, IViewport, IColorManager, ICompositionHelper, CharacterJoinerHandler, IBufferRange } from 'browser/Types'; import { IColorSet, ITerminal, ILinkifier2, IBrowser, IViewport, IColorManager, ICompositionHelper, CharacterJoinerHandler, IBufferRange } from 'browser/Types';
@@ -352,7 +352,7 @@ export class MockCoreBrowserService implements ICoreBrowserService {
export class MockCharSizeService implements ICharSizeService { export class MockCharSizeService implements ICharSizeService {
public serviceBrand: undefined; public serviceBrand: undefined;
public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; } public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
public onCharSizeChange: IEvent<void> = new EventEmitter<void>().event; public onCharSizeChange: IEvent<void> = initEvent<void>();
constructor(public width: number, public height: number) {} constructor(public width: number, public height: number) {}
public measure(): void {} public measure(): void {}
} }
@@ -370,10 +370,10 @@ export class MockMouseService implements IMouseService {
export class MockRenderService implements IRenderService { export class MockRenderService implements IRenderService {
public serviceBrand: undefined; public serviceBrand: undefined;
public onDimensionsChange: IEvent<IRenderDimensions> = new EventEmitter<IRenderDimensions>().event; public onDimensionsChange: IEvent<IRenderDimensions> = initEvent<IRenderDimensions>();
public onRenderedViewportChange: IEvent<{ start: number, end: number }, void> = new EventEmitter<{ start: number, end: number }>().event; public onRenderedViewportChange: IEvent<{ start: number, end: number }, void> = initEvent<{ start: number, end: number }>();
public onRender: IEvent<{ start: number, end: number }, void> = new EventEmitter<{ start: number, end: number }>().event; public onRender: IEvent<{ start: number, end: number }, void> = initEvent<{ start: number, end: number }>();
public onRefreshRequest: IEvent<{ start: number, end: number}, void> = new EventEmitter<{ start: number, end: number }>().event; public onRefreshRequest: IEvent<{ start: number, end: number}, void> = initEvent<{ start: number, end: number }>();
public dimensions: IRenderDimensions = { public dimensions: IRenderDimensions = {
scaledCharWidth: 0, scaledCharWidth: 0,
scaledCharHeight: 0, scaledCharHeight: 0,
@@ -457,10 +457,10 @@ export class MockSelectionService implements ISelectionService {
public hasSelection: boolean = false; public hasSelection: boolean = false;
public selectionStart: [number, number] | undefined; public selectionStart: [number, number] | undefined;
public selectionEnd: [number, number] | undefined; public selectionEnd: [number, number] | undefined;
public onLinuxMouseSelection = new EventEmitter<string>().event; public onLinuxMouseSelection = initEvent<string>();
public onRequestRedraw = new EventEmitter<ISelectionRedrawRequestEvent>().event; public onRequestRedraw = initEvent<ISelectionRedrawRequestEvent>();
public onRequestScrollLines = new EventEmitter<ISelectionRequestScrollLinesEvent>().event; public onRequestScrollLines = initEvent<ISelectionRequestScrollLinesEvent>();
public onSelectionChange = new EventEmitter<void>().event; public onSelectionChange = initEvent<void>();
public disable(): void { public disable(): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@@ -95,7 +95,7 @@ export class BufferDecorationRenderer extends Disposable {
// outside of viewport // outside of viewport
if (decoration.element) { if (decoration.element) {
decoration.element.style.display = 'none'; decoration.element.style.display = 'none';
decoration.onRenderEmitter.fire(decoration.element); decoration.onRender.fire(decoration.element);
} }
} else { } else {
let element = this._decorationElements.get(decoration); let element = this._decorationElements.get(decoration);
@@ -108,7 +108,7 @@ export class BufferDecorationRenderer extends Disposable {
} }
element.style.top = `${line * this._renderService.dimensions.actualCellHeight}px`; element.style.top = `${line * this._renderService.dimensions.actualCellHeight}px`;
element.style.display = this._altBufferIsActive ? 'none' : 'block'; element.style.display = this._altBufferIsActive ? 'none' : 'block';
decoration.onRenderEmitter.fire(element); decoration.onRender.fire(element);
} }
} }
+2 -2
View File
@@ -10,7 +10,7 @@ import { Disposable } from 'common/Lifecycle';
import { IColorSet, ILinkifierEvent, ILinkifier2 } from 'browser/Types'; import { IColorSet, ILinkifierEvent, ILinkifier2 } from 'browser/Types';
import { ICharSizeService, ICoreBrowserService } from 'browser/services/Services'; import { ICharSizeService, ICoreBrowserService } from 'browser/services/Services';
import { IOptionsService, IBufferService, IInstantiationService } from 'common/services/Services'; import { IOptionsService, IBufferService, IInstantiationService } from 'common/services/Services';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
import { color } from 'common/Color'; import { color } from 'common/Color';
import { removeElementFromParent } from 'browser/Dom'; import { removeElementFromParent } from 'browser/Dom';
@@ -40,7 +40,7 @@ export class DomRenderer extends Disposable implements IRenderer {
public dimensions: IRenderDimensions; public dimensions: IRenderDimensions;
public readonly onRequestRedraw = new EventEmitter<IRequestRedrawEvent>().event; public readonly onRequestRedraw = initEvent<IRequestRedrawEvent>();
constructor( constructor(
private _colors: IColorSet, private _colors: IColorSet,
+3 -4
View File
@@ -4,7 +4,7 @@
*/ */
import { IOptionsService } from 'common/services/Services'; import { IOptionsService } from 'common/services/Services';
import { IEvent, EventEmitter } from 'common/EventEmitter'; import { IEvent, EventEmitter, initEvent } from 'common/EventEmitter';
import { ICharSizeService } from 'browser/services/Services'; import { ICharSizeService } from 'browser/services/Services';
export class CharSizeService implements ICharSizeService { export class CharSizeService implements ICharSizeService {
@@ -16,8 +16,7 @@ export class CharSizeService implements ICharSizeService {
public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; } public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
private readonly _onCharSizeChange = new EventEmitter<void>(); public readonly onCharSizeChange = initEvent<void>();
public readonly onCharSizeChange = this._onCharSizeChange.event;
constructor( constructor(
document: Document, document: Document,
@@ -32,7 +31,7 @@ export class CharSizeService implements ICharSizeService {
if (result.width !== this.width || result.height !== this.height) { if (result.width !== this.width || result.height !== this.height) {
this.width = result.width; this.width = result.width;
this.height = result.height; this.height = result.height;
this._onCharSizeChange.fire(); this.onCharSizeChange.fire();
} }
} }
} }
+8 -12
View File
@@ -5,7 +5,7 @@
import { IRenderer, IRenderDimensions } from 'browser/renderer/Types'; import { IRenderer, IRenderDimensions } from 'browser/renderer/Types';
import { RenderDebouncer } from 'browser/RenderDebouncer'; import { RenderDebouncer } from 'browser/RenderDebouncer';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
import { Disposable } from 'common/Lifecycle'; import { Disposable } from 'common/Lifecycle';
import { ScreenDprMonitor } from 'browser/ScreenDprMonitor'; import { ScreenDprMonitor } from 'browser/ScreenDprMonitor';
import { addDisposableDomListener } from 'browser/Lifecycle'; import { addDisposableDomListener } from 'browser/Lifecycle';
@@ -39,14 +39,10 @@ export class RenderService extends Disposable implements IRenderService {
columnSelectMode: false columnSelectMode: false
}; };
private readonly _onDimensionsChange = new EventEmitter<IRenderDimensions>(); public readonly onDimensionsChange = initEvent<IRenderDimensions>();
public readonly onDimensionsChange = this._onDimensionsChange.event; public readonly onRenderedViewportChange = initEvent<{ start: number, end: number }>();
private readonly _onRenderedViewportChange = new EventEmitter<{ start: number, end: number }>(); public readonly onRender = initEvent<{ start: number, end: number }>();
public readonly onRenderedViewportChange = this._onRenderedViewportChange.event; public readonly onRefreshRequest = initEvent<{ start: number, end: number }>();
private readonly _onRender = new EventEmitter<{ start: number, end: number }>();
public readonly onRender = this._onRender.event;
private readonly _onRefreshRequest = new EventEmitter<{ start: number, end: number }>();
public readonly onRefreshRequest = this._onRefreshRequest.event;
public get dimensions(): IRenderDimensions { return this._renderer.dimensions; } public get dimensions(): IRenderDimensions { return this._renderer.dimensions; }
@@ -135,9 +131,9 @@ export class RenderService extends Disposable implements IRenderService {
// Fire render event only if it was not a redraw // Fire render event only if it was not a redraw
if (!this._isNextRenderRedrawOnly) { if (!this._isNextRenderRedrawOnly) {
this._onRenderedViewportChange.fire({ start, end }); this.onRenderedViewportChange.fire({ start, end });
} }
this._onRender.fire({ start, end }); this.onRender.fire({ start, end });
this._isNextRenderRedrawOnly = true; this._isNextRenderRedrawOnly = true;
} }
@@ -157,7 +153,7 @@ export class RenderService extends Disposable implements IRenderService {
if (this._renderer.dimensions.canvasWidth === this._canvasWidth && this._renderer.dimensions.canvasHeight === this._canvasHeight) { if (this._renderer.dimensions.canvasWidth === this._canvasWidth && this._renderer.dimensions.canvasHeight === this._canvasHeight) {
return; return;
} }
this._onDimensionsChange.fire(this._renderer.dimensions); this.onDimensionsChange.fire(this._renderer.dimensions);
} }
public dispose(): void { public dispose(): void {
+12 -16
View File
@@ -9,7 +9,7 @@ import { IBufferLine, IDisposable } from 'common/Types';
import * as Browser from 'common/Platform'; import * as Browser from 'common/Platform';
import { SelectionModel } from 'browser/selection/SelectionModel'; import { SelectionModel } from 'browser/selection/SelectionModel';
import { CellData } from 'common/buffer/CellData'; import { CellData } from 'common/buffer/CellData';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
import { IMouseService, ISelectionService, IRenderService, ICoreBrowserService } from 'browser/services/Services'; import { IMouseService, ISelectionService, IRenderService, ICoreBrowserService } from 'browser/services/Services';
import { IBufferRange, ILinkifier2 } from 'browser/Types'; import { IBufferRange, ILinkifier2 } from 'browser/Types';
import { IBufferService, IOptionsService, ICoreService } from 'common/services/Services'; import { IBufferService, IOptionsService, ICoreService } from 'common/services/Services';
@@ -111,14 +111,10 @@ export class SelectionService extends Disposable implements ISelectionService {
private _oldSelectionStart: [number, number] | undefined = undefined; private _oldSelectionStart: [number, number] | undefined = undefined;
private _oldSelectionEnd: [number, number] | undefined = undefined; private _oldSelectionEnd: [number, number] | undefined = undefined;
private readonly _onLinuxMouseSelection = this.register(new EventEmitter<string>()); public readonly onLinuxMouseSelection = this.register(initEvent<string>());
public readonly onLinuxMouseSelection = this._onLinuxMouseSelection.event; public readonly onRequestRedraw = this.register(initEvent<ISelectionRedrawRequestEvent>());
private readonly _onRedrawRequest = this.register(new EventEmitter<ISelectionRedrawRequestEvent>()); public readonly onSelectionChange = this.register(initEvent<void>());
public readonly onRequestRedraw = this._onRedrawRequest.event; public readonly onRequestScrollLines = this.register(initEvent<ISelectionRequestScrollLinesEvent>());
private readonly _onSelectionChange = this.register(new EventEmitter<void>());
public readonly onSelectionChange = this._onSelectionChange.event;
private readonly _onRequestScrollLines = this.register(new EventEmitter<ISelectionRequestScrollLinesEvent>());
public readonly onRequestScrollLines = this._onRequestScrollLines.event;
constructor( constructor(
private readonly _element: HTMLElement, private readonly _element: HTMLElement,
@@ -260,7 +256,7 @@ export class SelectionService extends Disposable implements ISelectionService {
this._model.clearSelection(); this._model.clearSelection();
this._removeMouseDownListeners(); this._removeMouseDownListeners();
this.refresh(); this.refresh();
this._onSelectionChange.fire(); this.onSelectionChange.fire();
} }
/** /**
@@ -279,7 +275,7 @@ export class SelectionService extends Disposable implements ISelectionService {
if (Browser.isLinux && isLinuxMouseSelection) { if (Browser.isLinux && isLinuxMouseSelection) {
const selectionText = this.selectionText; const selectionText = this.selectionText;
if (selectionText.length) { if (selectionText.length) {
this._onLinuxMouseSelection.fire(this.selectionText); this.onLinuxMouseSelection.fire(this.selectionText);
} }
} }
} }
@@ -290,7 +286,7 @@ export class SelectionService extends Disposable implements ISelectionService {
*/ */
private _refresh(): void { private _refresh(): void {
this._refreshAnimationFrame = undefined; this._refreshAnimationFrame = undefined;
this._onRedrawRequest.fire({ this.onRequestRedraw.fire({
start: this._model.finalSelectionStart, start: this._model.finalSelectionStart,
end: this._model.finalSelectionEnd, end: this._model.finalSelectionEnd,
columnSelectMode: this._activeSelectionMode === SelectionMode.COLUMN columnSelectMode: this._activeSelectionMode === SelectionMode.COLUMN
@@ -358,7 +354,7 @@ export class SelectionService extends Disposable implements ISelectionService {
public selectAll(): void { public selectAll(): void {
this._model.isSelectAllActive = true; this._model.isSelectAllActive = true;
this.refresh(); this.refresh();
this._onSelectionChange.fire(); this.onSelectionChange.fire();
} }
public selectLines(start: number, end: number): void { public selectLines(start: number, end: number): void {
@@ -368,7 +364,7 @@ export class SelectionService extends Disposable implements ISelectionService {
this._model.selectionStart = [0, start]; this._model.selectionStart = [0, start];
this._model.selectionEnd = [this._bufferService.cols, end]; this._model.selectionEnd = [this._bufferService.cols, end];
this.refresh(); this.refresh();
this._onSelectionChange.fire(); this.onSelectionChange.fire();
} }
/** /**
@@ -665,7 +661,7 @@ export class SelectionService extends Disposable implements ISelectionService {
return; return;
} }
if (this._dragScrollAmount) { if (this._dragScrollAmount) {
this._onRequestScrollLines.fire({ amount: this._dragScrollAmount, suppressScrollEvent: false }); this.onRequestScrollLines.fire({ amount: this._dragScrollAmount, suppressScrollEvent: false });
// Re-evaluate selection // Re-evaluate selection
// If the cursor was above or below the viewport, make sure it's at the // If the cursor was above or below the viewport, make sure it's at the
// start or end of the viewport respectively. This should only happen when // start or end of the viewport respectively. This should only happen when
@@ -743,7 +739,7 @@ export class SelectionService extends Disposable implements ISelectionService {
this._oldSelectionStart = start; this._oldSelectionStart = start;
this._oldSelectionEnd = end; this._oldSelectionEnd = end;
this._oldHasSelection = hasSelection; this._oldHasSelection = hasSelection;
this._onSelectionChange.fire(); this.onSelectionChange.fire();
} }
private _onBufferActivate(e: {activeBuffer: IBuffer, inactiveBuffer: IBuffer}): void { private _onBufferActivate(e: {activeBuffer: IBuffer, inactiveBuffer: IBuffer}): void {
+11 -14
View File
@@ -4,7 +4,7 @@
*/ */
import { ICircularList } from 'common/Types'; import { ICircularList } from 'common/Types';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { initEvent } from 'common/EventEmitter';
export interface IInsertEvent { export interface IInsertEvent {
index: number; index: number;
@@ -25,12 +25,9 @@ export class CircularList<T> implements ICircularList<T> {
private _startIndex: number; private _startIndex: number;
private _length: number; private _length: number;
public readonly onDeleteEmitter = new EventEmitter<IDeleteEvent>(); public readonly onDelete = initEvent<IDeleteEvent>();
public readonly onDelete = this.onDeleteEmitter.event; public readonly onInsert = initEvent<IInsertEvent>();
public readonly onInsertEmitter = new EventEmitter<IInsertEvent>(); public readonly onTrim = initEvent<number>();
public readonly onInsert = this.onInsertEmitter.event;
public readonly onTrimEmitter = new EventEmitter<number>();
public readonly onTrim = this.onTrimEmitter.event;
constructor( constructor(
private _maxLength: number private _maxLength: number
@@ -107,7 +104,7 @@ export class CircularList<T> implements ICircularList<T> {
this._array[this._getCyclicIndex(this._length)] = value; this._array[this._getCyclicIndex(this._length)] = value;
if (this._length === this._maxLength) { if (this._length === this._maxLength) {
this._startIndex = ++this._startIndex % this._maxLength; this._startIndex = ++this._startIndex % this._maxLength;
this.onTrimEmitter.fire(1); this.onTrim.fire(1);
} else { } else {
this._length++; this._length++;
} }
@@ -123,7 +120,7 @@ export class CircularList<T> implements ICircularList<T> {
throw new Error('Can only recycle when the buffer is full'); throw new Error('Can only recycle when the buffer is full');
} }
this._startIndex = ++this._startIndex % this._maxLength; this._startIndex = ++this._startIndex % this._maxLength;
this.onTrimEmitter.fire(1); this.onTrim.fire(1);
return this._array[this._getCyclicIndex(this._length - 1)]!; return this._array[this._getCyclicIndex(this._length - 1)]!;
} }
@@ -158,7 +155,7 @@ export class CircularList<T> implements ICircularList<T> {
this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)]; this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
} }
this._length -= deleteCount; this._length -= deleteCount;
this.onDeleteEmitter.fire({ index: start, amount: deleteCount }); this.onDelete.fire({ index: start, amount: deleteCount });
} }
// Add items // Add items
@@ -169,7 +166,7 @@ export class CircularList<T> implements ICircularList<T> {
this._array[this._getCyclicIndex(start + i)] = items[i]; this._array[this._getCyclicIndex(start + i)] = items[i];
} }
if (items.length) { if (items.length) {
this.onInsertEmitter.fire({ index: start, amount: items.length }); this.onInsert.fire({ index: start, amount: items.length });
} }
// Adjust length as needed // Adjust length as needed
@@ -177,7 +174,7 @@ export class CircularList<T> implements ICircularList<T> {
const countToTrim = (this._length + items.length) - this._maxLength; const countToTrim = (this._length + items.length) - this._maxLength;
this._startIndex += countToTrim; this._startIndex += countToTrim;
this._length = this._maxLength; this._length = this._maxLength;
this.onTrimEmitter.fire(countToTrim); this.onTrim.fire(countToTrim);
} else { } else {
this._length += items.length; this._length += items.length;
} }
@@ -193,7 +190,7 @@ export class CircularList<T> implements ICircularList<T> {
} }
this._startIndex += count; this._startIndex += count;
this._length -= count; this._length -= count;
this.onTrimEmitter.fire(count); this.onTrim.fire(count);
} }
public shiftElements(start: number, count: number, offset: number): void { public shiftElements(start: number, count: number, offset: number): void {
@@ -217,7 +214,7 @@ export class CircularList<T> implements ICircularList<T> {
while (this._length > this._maxLength) { while (this._length > this._maxLength) {
this._length--; this._length--;
this._startIndex++; this._startIndex++;
this.onTrimEmitter.fire(1); this.onTrim.fire(1);
} }
} }
} else { } else {
+11 -16
View File
@@ -29,7 +29,7 @@ import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/Buffe
import { OptionsService } from 'common/services/OptionsService'; import { OptionsService } from 'common/services/OptionsService';
import { IDisposable, IAttributeData, ICoreTerminal, IScrollEvent, ScrollSource } from 'common/Types'; import { IDisposable, IAttributeData, ICoreTerminal, IScrollEvent, ScrollSource } from 'common/Types';
import { CoreService } from 'common/services/CoreService'; import { CoreService } from 'common/services/CoreService';
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent, forwardEvent, initEvent } from 'common/EventEmitter';
import { CoreMouseService } from 'common/services/CoreMouseService'; import { CoreMouseService } from 'common/services/CoreMouseService';
import { UnicodeService } from 'common/services/UnicodeService'; import { UnicodeService } from 'common/services/UnicodeService';
import { CharsetService } from 'common/services/CharsetService'; import { CharsetService } from 'common/services/CharsetService';
@@ -59,16 +59,11 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
private _writeBuffer: WriteBuffer; private _writeBuffer: WriteBuffer;
private _windowsMode: IDisposable | undefined; private _windowsMode: IDisposable | undefined;
private readonly _onBinary = new EventEmitter<string>(); public readonly onBinary = initEvent<string>();
public readonly onBinary = this._onBinary.event; public readonly onData = initEvent<string>();
private readonly _onData = new EventEmitter<string>(); public readonly onLineFeed = initEvent<void>();
public readonly onData = this._onData.event; public readonly onResize = initEvent<{ cols: number, rows: number }>();
protected _onLineFeed = new EventEmitter<void>(); public readonly onWriteParsed = initEvent<void>();
public readonly onLineFeed = this._onLineFeed.event;
private readonly _onResize = new EventEmitter<{ cols: number, rows: number }>();
public readonly onResize = this._onResize.event;
protected readonly _onWriteParsed = new EventEmitter<void>();
public readonly onWriteParsed = this._onWriteParsed.event;
/** /**
* Internally we track the source of the scroll but this is meaningless outside the library so * Internally we track the source of the scroll but this is meaningless outside the library so
@@ -122,13 +117,13 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
// Register input handler and handle/forward events // Register input handler and handle/forward events
this._inputHandler = new InputHandler(this._bufferService, this._charsetService, this.coreService, this._logService, this.optionsService, this._oscLinkService, this.coreMouseService, this.unicodeService); this._inputHandler = new InputHandler(this._bufferService, this._charsetService, this.coreService, this._logService, this.optionsService, this._oscLinkService, this.coreMouseService, this.unicodeService);
this.register(forwardEvent(this._inputHandler.onLineFeed, this._onLineFeed)); this.register(forwardEvent(this._inputHandler.onLineFeed, this.onLineFeed));
this.register(this._inputHandler); this.register(this._inputHandler);
// Setup listeners // Setup listeners
this.register(forwardEvent(this._bufferService.onResize, this._onResize)); this.register(forwardEvent(this._bufferService.onResize, this.onResize));
this.register(forwardEvent(this.coreService.onData, this._onData)); this.register(forwardEvent(this.coreService.onData, this.onData));
this.register(forwardEvent(this.coreService.onBinary, this._onBinary)); this.register(forwardEvent(this.coreService.onBinary, this.onBinary));
this.register(this.coreService.onUserInput(() => this._writeBuffer.handleUserInput())); this.register(this.coreService.onUserInput(() => this._writeBuffer.handleUserInput()));
this.register(this.optionsService.onOptionChange(key => this._updateOptions(key))); this.register(this.optionsService.onOptionChange(key => this._updateOptions(key)));
this.register(this._bufferService.onScroll(event => { this.register(this._bufferService.onScroll(event => {
@@ -142,7 +137,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
// Setup WriteBuffer // Setup WriteBuffer
this._writeBuffer = new WriteBuffer((data, promiseResult) => this._inputHandler.parse(data, promiseResult)); this._writeBuffer = new WriteBuffer((data, promiseResult) => this._inputHandler.parse(data, promiseResult));
this.register(forwardEvent(this._writeBuffer.onWriteParsed, this._onWriteParsed)); this.register(forwardEvent(this._writeBuffer.onWriteParsed, this.onWriteParsed));
} }
public dispose(): void { public dispose(): void {
+15 -1
View File
@@ -14,11 +14,13 @@ export interface IEvent<T, U = void> {
} }
export interface IEventEmitter<T, U = void> { export interface IEventEmitter<T, U = void> {
event: IEvent<T, U>;
fire(arg1: T, arg2: U): void; fire(arg1: T, arg2: U): void;
dispose(): void; dispose(): void;
} }
export interface IEventWithEmitter<T, U = void> extends IEventEmitter<T, U>, IEvent<T, U> {
}
export class EventEmitter<T, U = void> implements IEventEmitter<T, U> { export class EventEmitter<T, U = void> implements IEventEmitter<T, U> {
private _listeners: IListener<T, U>[] = []; private _listeners: IListener<T, U>[] = [];
private _event?: IEvent<T, U>; private _event?: IEvent<T, U>;
@@ -64,6 +66,18 @@ export class EventEmitter<T, U = void> implements IEventEmitter<T, U> {
} }
} }
export function initEvent<T, U = void>(): IEventWithEmitter<T, U> {
const emitter = new EventEmitter<T, U>();
const event = emitter.event;
Object.defineProperty(event, 'fire', {
value: emitter.fire.bind(emitter)
});
Object.defineProperty(event, 'dispose', {
value: emitter.dispose.bind(emitter)
});
return event as any;
}
export function forwardEvent<T>(from: IEvent<T>, to: IEventEmitter<T>): IDisposable { export function forwardEvent<T>(from: IEvent<T>, to: IEventEmitter<T>): IDisposable {
return from(e => to.fire(e)); return from(e => to.fire(e));
} }
+45 -58
View File
@@ -11,7 +11,7 @@ import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
import { Disposable } from 'common/Lifecycle'; import { Disposable } from 'common/Lifecycle';
import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32 } from 'common/input/TextDecoder'; import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32 } from 'common/input/TextDecoder';
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine'; import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
import { IParsingState, IEscapeSequenceParser, IParams, IFunctionIdentifier } from 'common/parser/Types'; import { IParsingState, IEscapeSequenceParser, IParams, IFunctionIdentifier } from 'common/parser/Types';
import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content, UnderlineStyle } from 'common/buffer/Constants'; import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content, UnderlineStyle } from 'common/buffer/Constants';
import { CellData } from 'common/buffer/CellData'; import { CellData } from 'common/buffer/CellData';
@@ -132,33 +132,20 @@ export class InputHandler extends Disposable implements IInputHandler {
private _activeBuffer: IBuffer; private _activeBuffer: IBuffer;
private readonly _onRequestBell = new EventEmitter<void>(); public readonly onRequestBell = initEvent<void>();
public readonly onRequestBell = this._onRequestBell.event; public readonly onRequestRefreshRows = initEvent<number, number>();
private readonly _onRequestRefreshRows = new EventEmitter<number, number>(); public readonly onRequestReset = initEvent<void>();
public readonly onRequestRefreshRows = this._onRequestRefreshRows.event; public readonly onRequestSendFocus = initEvent<void>();
private readonly _onRequestReset = new EventEmitter<void>(); public readonly onRequestSyncScrollBar = initEvent<void>();
public readonly onRequestReset = this._onRequestReset.event; public readonly onRequestWindowsOptionsReport = initEvent<WindowsOptionsReportType>();
private readonly _onRequestSendFocus = new EventEmitter<void>();
public readonly onRequestSendFocus = this._onRequestSendFocus.event;
private readonly _onRequestSyncScrollBar = new EventEmitter<void>();
public readonly onRequestSyncScrollBar = this._onRequestSyncScrollBar.event;
private readonly _onRequestWindowsOptionsReport = new EventEmitter<WindowsOptionsReportType>();
public readonly onRequestWindowsOptionsReport = this._onRequestWindowsOptionsReport.event;
private readonly _onA11yChar = new EventEmitter<string>(); public readonly onA11yChar = initEvent<string>();
public readonly onA11yChar = this._onA11yChar.event; public readonly onA11yTab = initEvent<number>();
private readonly _onA11yTab = new EventEmitter<number>(); public readonly onCursorMove = initEvent<void>();
public readonly onA11yTab = this._onA11yTab.event; public readonly onLineFeed = initEvent<void>();
private readonly _onCursorMove = new EventEmitter<void>(); public readonly onScroll = initEvent<number>();
public readonly onCursorMove = this._onCursorMove.event; public readonly onTitleChange = initEvent<string>();
private readonly _onLineFeed = new EventEmitter<void>(); public readonly onColor = initEvent<IColorEvent>();
public readonly onLineFeed = this._onLineFeed.event;
private readonly _onScroll = new EventEmitter<number>();
public readonly onScroll = this._onScroll.event;
private readonly _onTitleChange = new EventEmitter<string>();
public readonly onTitleChange = this._onTitleChange.event;
private readonly _onColor = new EventEmitter<IColorEvent>();
public readonly onColor = this._onColor.event;
private _parseStack: IParseStack = { private _parseStack: IParseStack = {
paused: false, paused: false,
@@ -492,11 +479,11 @@ export class InputHandler extends Disposable implements IInputHandler {
} }
if (this._activeBuffer.x !== cursorStartX || this._activeBuffer.y !== cursorStartY) { if (this._activeBuffer.x !== cursorStartX || this._activeBuffer.y !== cursorStartY) {
this._onCursorMove.fire(); this.onCursorMove.fire();
} }
// Refresh any dirty rows accumulated as part of parsing // Refresh any dirty rows accumulated as part of parsing
this._onRequestRefreshRows.fire(this._dirtyRowTracker.start, this._dirtyRowTracker.end); this.onRequestRefreshRows.fire(this._dirtyRowTracker.start, this._dirtyRowTracker.end);
} }
public print(data: Uint32Array, start: number, end: number): void { public print(data: Uint32Array, start: number, end: number): void {
@@ -535,7 +522,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} }
if (screenReaderMode) { if (screenReaderMode) {
this._onA11yChar.fire(stringFromCodePoint(code)); this.onA11yChar.fire(stringFromCodePoint(code));
} }
if (this._currentLinkId !== undefined) { if (this._currentLinkId !== undefined) {
this._oscLinkService.addLineToLink(this._currentLinkId, this._activeBuffer.ybase + this._activeBuffer.y); this._oscLinkService.addLineToLink(this._currentLinkId, this._activeBuffer.ybase + this._activeBuffer.y);
@@ -687,7 +674,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* and `ITerminalOptions.bellSound`. * and `ITerminalOptions.bellSound`.
*/ */
public bell(): boolean { public bell(): boolean {
this._onRequestBell.fire(); this.onRequestBell.fire();
return true; return true;
} }
@@ -719,7 +706,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} }
this._dirtyRowTracker.markDirty(this._activeBuffer.y); this._dirtyRowTracker.markDirty(this._activeBuffer.y);
this._onLineFeed.fire(); this.onLineFeed.fire();
return true; return true;
} }
@@ -808,7 +795,7 @@ export class InputHandler extends Disposable implements IInputHandler {
const originalX = this._activeBuffer.x; const originalX = this._activeBuffer.x;
this._activeBuffer.x = this._activeBuffer.nextStop(); this._activeBuffer.x = this._activeBuffer.nextStop();
if (this._optionsService.rawOptions.screenReaderMode) { if (this._optionsService.rawOptions.screenReaderMode) {
this._onA11yTab.fire(this._activeBuffer.x - originalX); this.onA11yTab.fire(this._activeBuffer.x - originalX);
} }
return true; return true;
} }
@@ -1218,7 +1205,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._activeBuffer.ybase = Math.max(this._activeBuffer.ybase - scrollBackSize, 0); this._activeBuffer.ybase = Math.max(this._activeBuffer.ybase - scrollBackSize, 0);
this._activeBuffer.ydisp = Math.max(this._activeBuffer.ydisp - scrollBackSize, 0); this._activeBuffer.ydisp = Math.max(this._activeBuffer.ydisp - scrollBackSize, 0);
// Force a scroll event to refresh viewport // Force a scroll event to refresh viewport
this._onScroll.fire(0); this.onScroll.fire(0);
} }
break; break;
} }
@@ -1849,7 +1836,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/ */
if (this._optionsService.rawOptions.windowOptions.setWinLines) { if (this._optionsService.rawOptions.windowOptions.setWinLines) {
this._bufferService.resize(132, this._bufferService.rows); this._bufferService.resize(132, this._bufferService.rows);
this._onRequestReset.fire(); this.onRequestReset.fire();
} }
break; break;
case 6: case 6:
@@ -1868,7 +1855,7 @@ export class InputHandler extends Disposable implements IInputHandler {
case 66: case 66:
this._logService.debug('Serial port requested application keypad.'); this._logService.debug('Serial port requested application keypad.');
this._coreService.decPrivateModes.applicationKeypad = true; this._coreService.decPrivateModes.applicationKeypad = true;
this._onRequestSyncScrollBar.fire(); this.onRequestSyncScrollBar.fire();
break; break;
case 9: // X10 Mouse case 9: // X10 Mouse
// no release, no motion, no wheel, no modifiers. // no release, no motion, no wheel, no modifiers.
@@ -1890,7 +1877,7 @@ export class InputHandler extends Disposable implements IInputHandler {
// focusin: ^[[I // focusin: ^[[I
// focusout: ^[[O // focusout: ^[[O
this._coreService.decPrivateModes.sendFocus = true; this._coreService.decPrivateModes.sendFocus = true;
this._onRequestSendFocus.fire(); this.onRequestSendFocus.fire();
break; break;
case 1005: // utf8 ext mode mouse - removed in #2507 case 1005: // utf8 ext mode mouse - removed in #2507
this._logService.debug('DECSET 1005 not supported (see #2507)'); this._logService.debug('DECSET 1005 not supported (see #2507)');
@@ -1917,8 +1904,8 @@ export class InputHandler extends Disposable implements IInputHandler {
case 1047: // alt screen buffer case 1047: // alt screen buffer
this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()); this._bufferService.buffers.activateAltBuffer(this._eraseAttrData());
this._coreService.isCursorInitialized = true; this._coreService.isCursorInitialized = true;
this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1); this.onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
this._onRequestSyncScrollBar.fire(); this.onRequestSyncScrollBar.fire();
break; break;
case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste) case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
this._coreService.decPrivateModes.bracketedPasteMode = true; this._coreService.decPrivateModes.bracketedPasteMode = true;
@@ -2087,7 +2074,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/ */
if (this._optionsService.rawOptions.windowOptions.setWinLines) { if (this._optionsService.rawOptions.windowOptions.setWinLines) {
this._bufferService.resize(80, this._bufferService.rows); this._bufferService.resize(80, this._bufferService.rows);
this._onRequestReset.fire(); this.onRequestReset.fire();
} }
break; break;
case 6: case 6:
@@ -2106,7 +2093,7 @@ export class InputHandler extends Disposable implements IInputHandler {
case 66: case 66:
this._logService.debug('Switching back to normal keypad.'); this._logService.debug('Switching back to normal keypad.');
this._coreService.decPrivateModes.applicationKeypad = false; this._coreService.decPrivateModes.applicationKeypad = false;
this._onRequestSyncScrollBar.fire(); this.onRequestSyncScrollBar.fire();
break; break;
case 9: // X10 Mouse case 9: // X10 Mouse
case 1000: // vt200 mouse case 1000: // vt200 mouse
@@ -2145,8 +2132,8 @@ export class InputHandler extends Disposable implements IInputHandler {
this.restoreCursor(); this.restoreCursor();
} }
this._coreService.isCursorInitialized = true; this._coreService.isCursorInitialized = true;
this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1); this.onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
this._onRequestSyncScrollBar.fire(); this.onRequestSyncScrollBar.fire();
break; break;
case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste) case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
this._coreService.decPrivateModes.bracketedPasteMode = false; this._coreService.decPrivateModes.bracketedPasteMode = false;
@@ -2645,7 +2632,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/ */
public softReset(params: IParams): boolean { public softReset(params: IParams): boolean {
this._coreService.isCursorHidden = false; this._coreService.isCursorHidden = false;
this._onRequestSyncScrollBar.fire(); this.onRequestSyncScrollBar.fire();
this._activeBuffer.scrollTop = 0; this._activeBuffer.scrollTop = 0;
this._activeBuffer.scrollBottom = this._bufferService.rows - 1; this._activeBuffer.scrollBottom = this._bufferService.rows - 1;
this._curAttrData = DEFAULT_ATTR_DATA.clone(); this._curAttrData = DEFAULT_ATTR_DATA.clone();
@@ -2765,11 +2752,11 @@ export class InputHandler extends Disposable implements IInputHandler {
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 (second !== 2) { if (second !== 2) {
this._onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_WIN_SIZE_PIXELS); this.onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_WIN_SIZE_PIXELS);
} }
break; break;
case 16: // GetCellSizePixels, returns CSI 6 ; height ; width t case 16: // GetCellSizePixels, returns CSI 6 ; height ; width t
this._onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_CELL_SIZE_PIXELS); this.onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_CELL_SIZE_PIXELS);
break; break;
case 18: // GetWinSizeChars, returns CSI 8 ; height ; width t case 18: // GetWinSizeChars, returns CSI 8 ; height ; width t
if (this._bufferService) { if (this._bufferService) {
@@ -2859,7 +2846,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/ */
public setTitle(data: string): boolean { public setTitle(data: string): boolean {
this._windowTitle = data; this._windowTitle = data;
this._onTitleChange.fire(data); this.onTitleChange.fire(data);
return true; return true;
} }
@@ -2901,7 +2888,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} }
} }
if (event.length) { if (event.length) {
this._onColor.fire(event); this.onColor.fire(event);
} }
return true; return true;
} }
@@ -2975,11 +2962,11 @@ export class InputHandler extends Disposable implements IInputHandler {
for (let i = 0; i < slots.length; ++i, ++offset) { for (let i = 0; i < slots.length; ++i, ++offset) {
if (offset >= this._specialColors.length) break; if (offset >= this._specialColors.length) break;
if (slots[i] === '?') { if (slots[i] === '?') {
this._onColor.fire([{ type: ColorRequestType.REPORT, index: this._specialColors[offset] }]); this.onColor.fire([{ type: ColorRequestType.REPORT, index: this._specialColors[offset] }]);
} else { } else {
const color = parseColor(slots[i]); const color = parseColor(slots[i]);
if (color) { if (color) {
this._onColor.fire([{ type: ColorRequestType.SET, index: this._specialColors[offset], color }]); this.onColor.fire([{ type: ColorRequestType.SET, index: this._specialColors[offset], color }]);
} }
} }
} }
@@ -3040,7 +3027,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/ */
public restoreIndexedColor(data: string): boolean { public restoreIndexedColor(data: string): boolean {
if (!data) { if (!data) {
this._onColor.fire([{ type: ColorRequestType.RESTORE }]); this.onColor.fire([{ type: ColorRequestType.RESTORE }]);
return true; return true;
} }
const event: IColorEvent = []; const event: IColorEvent = [];
@@ -3054,7 +3041,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} }
} }
if (event.length) { if (event.length) {
this._onColor.fire(event); this.onColor.fire(event);
} }
return true; return true;
} }
@@ -3065,7 +3052,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 110 "Restore default foreground color" "OSC 110 BEL" "Restore default foreground to themed color." * @vt: #Y OSC 110 "Restore default foreground color" "OSC 110 BEL" "Restore default foreground to themed color."
*/ */
public restoreFgColor(data: string): boolean { public restoreFgColor(data: string): boolean {
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.FOREGROUND }]); this.onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.FOREGROUND }]);
return true; return true;
} }
@@ -3075,7 +3062,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 111 "Restore default background color" "OSC 111 BEL" "Restore default background to themed color." * @vt: #Y OSC 111 "Restore default background color" "OSC 111 BEL" "Restore default background to themed color."
*/ */
public restoreBgColor(data: string): boolean { public restoreBgColor(data: string): boolean {
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.BACKGROUND }]); this.onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.BACKGROUND }]);
return true; return true;
} }
@@ -3085,7 +3072,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 112 "Restore default cursor color" "OSC 112 BEL" "Restore default cursor to themed color." * @vt: #Y OSC 112 "Restore default cursor color" "OSC 112 BEL" "Restore default cursor to themed color."
*/ */
public restoreCursorColor(data: string): boolean { public restoreCursorColor(data: string): boolean {
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.CURSOR }]); this.onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.CURSOR }]);
return true; return true;
} }
@@ -3112,7 +3099,7 @@ export class InputHandler extends Disposable implements IInputHandler {
public keypadApplicationMode(): boolean { public keypadApplicationMode(): boolean {
this._logService.debug('Serial port requested application keypad.'); this._logService.debug('Serial port requested application keypad.');
this._coreService.decPrivateModes.applicationKeypad = true; this._coreService.decPrivateModes.applicationKeypad = true;
this._onRequestSyncScrollBar.fire(); this.onRequestSyncScrollBar.fire();
return true; return true;
} }
@@ -3124,7 +3111,7 @@ export class InputHandler extends Disposable implements IInputHandler {
public keypadNumericMode(): boolean { public keypadNumericMode(): boolean {
this._logService.debug('Switching back to normal keypad.'); this._logService.debug('Switching back to normal keypad.');
this._coreService.decPrivateModes.applicationKeypad = false; this._coreService.decPrivateModes.applicationKeypad = false;
this._onRequestSyncScrollBar.fire(); this.onRequestSyncScrollBar.fire();
return true; return true;
} }
@@ -3238,7 +3225,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/ */
public fullReset(): boolean { public fullReset(): boolean {
this._parser.reset(); this._parser.reset();
this._onRequestReset.fire(); this.onRequestReset.fire();
return true; return true;
} }
+11 -11
View File
@@ -4,7 +4,7 @@
*/ */
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, ICoreMouseService, ICharsetService, IUnicodeService, IUnicodeVersionProvider, LogLevelEnum, IDecorationService, IInternalDecoration, IOscLinkService } from 'common/services/Services'; import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, ICoreMouseService, ICharsetService, IUnicodeService, IUnicodeVersionProvider, LogLevelEnum, IDecorationService, IInternalDecoration, IOscLinkService } from 'common/services/Services';
import { IEvent, EventEmitter } from 'common/EventEmitter'; import { IEvent, EventEmitter, initEvent } from 'common/EventEmitter';
import { clone } from 'common/Clone'; import { clone } from 'common/Clone';
import { DEFAULT_OPTIONS } from 'common/services/OptionsService'; import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
import { IBufferSet, IBuffer } from 'common/buffer/Types'; import { IBufferSet, IBuffer } from 'common/buffer/Types';
@@ -17,8 +17,8 @@ export class MockBufferService implements IBufferService {
public serviceBrand: any; public 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;
public onResize: IEvent<{ cols: number, rows: number }> = new EventEmitter<{ cols: number, rows: number }>().event; public onResize: IEvent<{ cols: number, rows: number }> = initEvent<{ cols: number, rows: number }>();
public onScroll: IEvent<number> = new EventEmitter<number>().event; public onScroll: IEvent<number> = initEvent<number>();
public isUserScrolling: boolean = false; public isUserScrolling: boolean = false;
constructor( constructor(
public cols: number, public cols: number,
@@ -60,7 +60,7 @@ export class MockCoreMouseService implements ICoreMouseService {
public addProtocol(name: string): void { } public addProtocol(name: string): void { }
public reset(): void { } public reset(): void { }
public triggerMouseEvent(event: ICoreMouseEvent): boolean { return false; } public triggerMouseEvent(event: ICoreMouseEvent): boolean { return false; }
public onProtocolChange: IEvent<CoreMouseEventType> = new EventEmitter<CoreMouseEventType>().event; public onProtocolChange: IEvent<CoreMouseEventType> = initEvent<CoreMouseEventType>();
public explainEvents(events: CoreMouseEventType): { [event: string]: boolean } { public explainEvents(events: CoreMouseEventType): { [event: string]: boolean } {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@@ -92,9 +92,9 @@ export class MockCoreService implements ICoreService {
sendFocus: false, sendFocus: false,
wraparound: true wraparound: true
}; };
public onData: IEvent<string> = new EventEmitter<string>().event; public onData: IEvent<string> = initEvent<string>();
public onUserInput: IEvent<void> = new EventEmitter<void>().event; public onUserInput: IEvent<void> = initEvent<void>();
public onBinary: IEvent<string> = new EventEmitter<string>().event; public onBinary: IEvent<string> = initEvent<string>();
public reset(): void { } public reset(): void { }
public triggerDataEvent(data: string, wasUserInput?: boolean): void { } public triggerDataEvent(data: string, wasUserInput?: boolean): void { }
public triggerBinaryEvent(data: string): void { } public triggerBinaryEvent(data: string): void { }
@@ -113,7 +113,7 @@ export class MockOptionsService implements IOptionsService {
public serviceBrand: any; public serviceBrand: any;
public readonly rawOptions: Required<ITerminalOptions> = clone(DEFAULT_OPTIONS); public readonly rawOptions: Required<ITerminalOptions> = clone(DEFAULT_OPTIONS);
public options: Required<ITerminalOptions> = this.rawOptions; public options: Required<ITerminalOptions> = this.rawOptions;
public onOptionChange: IEvent<string> = new EventEmitter<string>().event; public onOptionChange: IEvent<string> = initEvent<string>();
constructor(testOptions?: Partial<ITerminalOptions>) { constructor(testOptions?: Partial<ITerminalOptions>) {
if (testOptions) { if (testOptions) {
for (const key of Object.keys(testOptions)) { for (const key of Object.keys(testOptions)) {
@@ -149,7 +149,7 @@ export class MockUnicodeService implements IUnicodeService {
} }
public versions: string[] = []; public versions: string[] = [];
public activeVersion: string = ''; public activeVersion: string = '';
public onChange: IEvent<string> = new EventEmitter<string>().event; public onChange: IEvent<string> = initEvent<string>();
public wcwidth = (codepoint: number): number => this._provider.wcwidth(codepoint); public wcwidth = (codepoint: number): number => this._provider.wcwidth(codepoint);
public getStringCellWidth(s: string): number { public getStringCellWidth(s: string): number {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
@@ -159,8 +159,8 @@ export class MockUnicodeService implements IUnicodeService {
export class MockDecorationService implements IDecorationService { export class MockDecorationService implements IDecorationService {
public serviceBrand: any; public serviceBrand: any;
public get decorations(): IterableIterator<IInternalDecoration> { return [].values(); } public get decorations(): IterableIterator<IInternalDecoration> { return [].values(); }
public onDecorationRegistered = new EventEmitter<IInternalDecoration>().event; public onDecorationRegistered = initEvent<IInternalDecoration>();
public onDecorationRemoved = new EventEmitter<IInternalDecoration>().event; public onDecorationRemoved = initEvent<IInternalDecoration>();
public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined { return undefined; } public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined { return undefined; }
public reset(): void { } public reset(): void { }
public forEachDecorationAtCell(x: number, line: number, layer: 'bottom' | 'top' | undefined, callback: (decoration: IInternalDecoration) => void): void { } public forEachDecorationAtCell(x: number, line: number, layer: 'bottom' | 'top' | undefined, callback: (decoration: IInternalDecoration) => void): void { }
+4 -7
View File
@@ -4,7 +4,7 @@
*/ */
import { IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from 'xterm'; import { IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from 'xterm';
import { IEvent, IEventEmitter } from 'common/EventEmitter'; import { IEvent, IEventEmitter, IEventWithEmitter } from 'common/EventEmitter';
import { IDeleteEvent, IInsertEvent } from 'common/CircularList'; import { IDeleteEvent, IInsertEvent } from 'common/CircularList';
import { IParams } from 'common/parser/Types'; import { IParams } from 'common/parser/Types';
import { ICoreMouseService, ICoreService, IOptionsService, IUnicodeService } from 'common/services/Services'; import { ICoreMouseService, ICoreService, IOptionsService, IUnicodeService } from 'common/services/Services';
@@ -71,12 +71,9 @@ export interface ICircularList<T> {
maxLength: number; maxLength: number;
isFull: boolean; isFull: boolean;
onDeleteEmitter: IEventEmitter<IDeleteEvent>; onDelete: IEventWithEmitter<IDeleteEvent>;
onDelete: IEvent<IDeleteEvent>; onInsert: IEventWithEmitter<IInsertEvent>;
onInsertEmitter: IEventEmitter<IInsertEvent>; onTrim: IEventWithEmitter<number>;
onInsert: IEvent<IInsertEvent>;
onTrimEmitter: IEventEmitter<number>;
onTrim: IEvent<number>;
get(index: number): T | undefined; get(index: number): T | undefined;
set(index: number, value: T): void; set(index: number, value: T): void;
+3 -3
View File
@@ -1071,7 +1071,7 @@ describe('Buffer', () => {
buffer.fillViewportRows(); buffer.fillViewportRows();
const marker = buffer.addMarker(buffer.lines.length - 1); const marker = buffer.addMarker(buffer.lines.length - 1);
assert.equal(marker.line, buffer.lines.length - 1); assert.equal(marker.line, buffer.lines.length - 1);
buffer.lines.onTrimEmitter.fire(1); buffer.lines.onTrim.fire(1);
assert.equal(marker.line, buffer.lines.length - 2); assert.equal(marker.line, buffer.lines.length - 2);
}); });
it('should dispose of a marker if it is trimmed off the buffer', () => { it('should dispose of a marker if it is trimmed off the buffer', () => {
@@ -1081,7 +1081,7 @@ describe('Buffer', () => {
const marker = buffer.addMarker(0); const marker = buffer.addMarker(0);
assert.equal(marker.isDisposed, false); assert.equal(marker.isDisposed, false);
assert.equal(buffer.markers.length, 1); assert.equal(buffer.markers.length, 1);
buffer.lines.onTrimEmitter.fire(1); buffer.lines.onTrim.fire(1);
assert.equal(marker.isDisposed, true); assert.equal(marker.isDisposed, true);
assert.equal(buffer.markers.length, 0); assert.equal(buffer.markers.length, 0);
}); });
@@ -1094,7 +1094,7 @@ describe('Buffer', () => {
marker.onDispose(() => eventStack.push('disposed')); marker.onDispose(() => eventStack.push('disposed'));
assert.equal(marker.isDisposed, false); assert.equal(marker.isDisposed, false);
assert.equal(buffer.markers.length, 1); assert.equal(buffer.markers.length, 1);
buffer.lines.onTrimEmitter.fire(1); buffer.lines.onTrim.fire(1);
assert.equal(marker.isDisposed, true); assert.equal(marker.isDisposed, true);
assert.equal(buffer.markers.length, 0); assert.equal(buffer.markers.length, 0);
assert.deepEqual(eventStack, ['disposed']); assert.deepEqual(eventStack, ['disposed']);
+2 -2
View File
@@ -463,12 +463,12 @@ export class Buffer implements IBuffer {
let insertCountEmitted = 0; let insertCountEmitted = 0;
for (let i = insertEvents.length - 1; i >= 0; i--) { for (let i = insertEvents.length - 1; i >= 0; i--) {
insertEvents[i].index += insertCountEmitted; insertEvents[i].index += insertCountEmitted;
this.lines.onInsertEmitter.fire(insertEvents[i]); this.lines.onInsert.fire(insertEvents[i]);
insertCountEmitted += insertEvents[i].amount; insertCountEmitted += insertEvents[i].amount;
} }
const amountToTrim = Math.max(0, originalLinesLength + countToInsert - this.lines.maxLength); const amountToTrim = Math.max(0, originalLinesLength + countToInsert - this.lines.maxLength);
if (amountToTrim > 0) { if (amountToTrim > 0) {
this.lines.onTrimEmitter.fire(amountToTrim); this.lines.onTrim.fire(amountToTrim);
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show More