mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Migrate rest of EventEmitter to base/ Emitter
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
import { CursorBlinkStateManager } from 'browser/renderer/shared/CursorBlinkStateManager';
|
||||
import { IRenderDimensions, IRequestRedrawEvent } from 'browser/renderer/shared/Types';
|
||||
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
|
||||
import { IEventEmitter } from 'common/EventEmitter';
|
||||
import { MutableDisposable } from 'common/Lifecycle';
|
||||
import { isFirefox } from 'common/Platform';
|
||||
import { ICellData } from 'common/Types';
|
||||
@@ -14,6 +13,7 @@ import { CellData } from 'common/buffer/CellData';
|
||||
import { IBufferService, ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
|
||||
import { Terminal } from '@xterm/xterm';
|
||||
import { BaseRenderLayer } from './BaseRenderLayer';
|
||||
import type { Emitter } from 'vs/base/common/event';
|
||||
|
||||
interface ICursorState {
|
||||
x: number;
|
||||
@@ -33,7 +33,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
||||
terminal: Terminal,
|
||||
container: HTMLElement,
|
||||
zIndex: number,
|
||||
private readonly _onRequestRedraw: IEventEmitter<IRequestRedrawEvent>,
|
||||
private readonly _onRequestRedraw: Emitter<IRequestRedrawEvent>,
|
||||
bufferService: IBufferService,
|
||||
optionsService: IOptionsService,
|
||||
private readonly _coreService: ICoreService,
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
|
||||
import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
|
||||
import { EventEmitter } from 'common/EventEmitter';
|
||||
import { Disposable, toDisposable, disposeArray, MutableDisposable, getDisposeArrayDisposable } from 'common/Lifecycle';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
|
||||
export interface ISearchOptions {
|
||||
regex?: boolean;
|
||||
@@ -80,7 +80,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
|
||||
private _linesCacheTimeoutId = 0;
|
||||
private _linesCacheDisposables = new MutableDisposable();
|
||||
|
||||
private readonly _onDidChangeResults = this.register(new EventEmitter<{ resultIndex: number, resultCount: number }>());
|
||||
private readonly _onDidChangeResults = this.register(new Emitter<{ resultIndex: number, resultCount: number }>());
|
||||
public readonly onDidChangeResults = this._onDidChangeResults.event;
|
||||
|
||||
constructor(options?: Partial<ISearchAddonOptions>) {
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
"common/*": [
|
||||
"../../../src/common/*"
|
||||
],
|
||||
"vs/*": [
|
||||
"../../../src/vs/*"
|
||||
],
|
||||
"@xterm/addon-search" : [
|
||||
"../typings/addon-search.d.ts"
|
||||
]
|
||||
@@ -30,6 +33,9 @@
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../src/common"
|
||||
},
|
||||
{
|
||||
"path": "../../../src/vs"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ import { ICharSizeService, ICharacterJoinerService, ICoreBrowserService, ILinkPr
|
||||
import { ThemeService } from 'browser/services/ThemeService';
|
||||
import { channels, color } from 'common/Color';
|
||||
import { CoreTerminal } from 'common/CoreTerminal';
|
||||
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
|
||||
import { IEvent, forwardEvent } from 'common/EventEmitter';
|
||||
import { MutableDisposable, toDisposable } from 'common/Lifecycle';
|
||||
import * as Browser from 'common/Platform';
|
||||
import { ColorRequestType, CoreMouseAction, CoreMouseButton, CoreMouseEventType, IColorEvent, ITerminalOptions, KeyboardResultType, SpecialColorIndex } from 'common/Types';
|
||||
@@ -124,9 +124,9 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
|
||||
|
||||
private readonly _onCursorMove = this.register(new Emitter<void>());
|
||||
public readonly onCursorMove = this._onCursorMove.event;
|
||||
private readonly _onKey = this.register(new EventEmitter<{ key: string, domEvent: KeyboardEvent }>());
|
||||
private readonly _onKey = this.register(new Emitter<{ key: string, domEvent: KeyboardEvent }>());
|
||||
public readonly onKey = this._onKey.event;
|
||||
private readonly _onRender = this.register(new EventEmitter<{ start: number, end: number }>());
|
||||
private readonly _onRender = this.register(new Emitter<{ start: number, end: number }>());
|
||||
public readonly onRender = this._onRender.event;
|
||||
private readonly _onSelectionChange = this.register(new Emitter<void>());
|
||||
public readonly onSelectionChange = this._onSelectionChange.event;
|
||||
@@ -161,7 +161,7 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
|
||||
|
||||
// Setup InputHandler listeners
|
||||
this.register(this._inputHandler.onRequestBell(() => this._onBell.fire()));
|
||||
this.register(this._inputHandler.onRequestRefreshRows((start, end) => this.refresh(start, end)));
|
||||
this.register(this._inputHandler.onRequestRefreshRows((e) => this.refresh(e.start, e.end)));
|
||||
this.register(this._inputHandler.onRequestSendFocus(() => this._reportFocus()));
|
||||
this.register(this._inputHandler.onRequestReset(() => this.reset()));
|
||||
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { IDisposable, IMarker, ILinkProvider, IDecorationOptions, IDecoration } from '@xterm/xterm';
|
||||
import { IEvent, EventEmitter } from 'common/EventEmitter';
|
||||
import { IEvent } from 'common/EventEmitter';
|
||||
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IMouseService, IRenderService, ISelectionService, IThemeService } from 'browser/services/Services';
|
||||
import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/shared/Types';
|
||||
import { IColorSet, ITerminal, ILinkifier2, IBrowser, IViewport, ICompositionHelper, CharacterJoinerHandler, IBufferRange, ReadonlyColorSet, IBufferElementProvider } from 'browser/Types';
|
||||
@@ -303,7 +303,7 @@ export class MockRenderer implements IRenderer {
|
||||
}
|
||||
|
||||
export class MockViewport implements IViewport {
|
||||
private readonly _onRequestScrollLines = new EventEmitter<{ amount: number, suppressScrollEvent: boolean }>();
|
||||
private readonly _onRequestScrollLines = new Emitter<{ amount: number, suppressScrollEvent: boolean }>();
|
||||
public readonly onRequestScrollLines = this._onRequestScrollLines.event;
|
||||
public dispose(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
@@ -358,7 +358,7 @@ export class MockCompositionHelper implements ICompositionHelper {
|
||||
|
||||
export class MockCoreBrowserService implements ICoreBrowserService {
|
||||
public onDprChange = new Emitter<number>().event;
|
||||
public onWindowChange = new EventEmitter<Window & typeof globalThis, void>().event;
|
||||
public onWindowChange = new Emitter<Window & typeof globalThis>().event;
|
||||
public serviceBrand: undefined;
|
||||
public isFocused: boolean = true;
|
||||
public get window(): Window & typeof globalThis {
|
||||
@@ -392,9 +392,9 @@ export class MockMouseService implements IMouseService {
|
||||
export class MockRenderService implements IRenderService {
|
||||
public serviceBrand: undefined;
|
||||
public onDimensionsChange: IEvent<IRenderDimensions> = new Emitter<IRenderDimensions>().event;
|
||||
public onRenderedViewportChange: IEvent<{ start: number, end: number }, void> = new EventEmitter<{ start: number, end: number }>().event;
|
||||
public onRender: IEvent<{ start: number, end: number }, void> = new EventEmitter<{ start: number, end: number }>().event;
|
||||
public onRefreshRequest: IEvent<{ start: number, end: number}, void> = new EventEmitter<{ start: number, end: number }>().event;
|
||||
public onRenderedViewportChange: IEvent<{ start: number, end: number }, void> = new Emitter<{ start: number, end: number }>().event;
|
||||
public onRender: IEvent<{ start: number, end: number }, void> = new Emitter<{ start: number, end: number }>().event;
|
||||
public onRefreshRequest: IEvent<{ start: number, end: number}, void> = new Emitter<{ start: number, end: number }>().event;
|
||||
public dimensions: IRenderDimensions = createRenderDimensions();
|
||||
public refreshRows(start: number, end: number): void {
|
||||
throw new Error('Method not implemented.');
|
||||
|
||||
@@ -7,7 +7,6 @@ import { RenderDebouncer } from 'browser/RenderDebouncer';
|
||||
import { IRenderDebouncerWithCallback } from 'browser/Types';
|
||||
import { IRenderDimensions, IRenderer } from 'browser/renderer/shared/Types';
|
||||
import { ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
|
||||
import { EventEmitter } from 'common/EventEmitter';
|
||||
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
|
||||
import { DebouncedIdleTask } from 'common/TaskQueue';
|
||||
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
|
||||
@@ -41,11 +40,11 @@ export class RenderService extends Disposable implements IRenderService {
|
||||
|
||||
private readonly _onDimensionsChange = this.register(new Emitter<IRenderDimensions>());
|
||||
public readonly onDimensionsChange = this._onDimensionsChange.event;
|
||||
private readonly _onRenderedViewportChange = this.register(new EventEmitter<{ start: number, end: number }>());
|
||||
private readonly _onRenderedViewportChange = this.register(new Emitter<{ start: number, end: number }>());
|
||||
public readonly onRenderedViewportChange = this._onRenderedViewportChange.event;
|
||||
private readonly _onRender = this.register(new EventEmitter<{ start: number, end: number }>());
|
||||
private readonly _onRender = this.register(new Emitter<{ start: number, end: number }>());
|
||||
public readonly onRender = this._onRender.event;
|
||||
private readonly _onRefreshRequest = this.register(new EventEmitter<{ start: number, end: number }>());
|
||||
private readonly _onRefreshRequest = this.register(new Emitter<{ start: number, end: number }>());
|
||||
public readonly onRefreshRequest = this._onRefreshRequest.event;
|
||||
|
||||
public get dimensions(): IRenderDimensions { return this._renderer.value!.dimensions; }
|
||||
|
||||
@@ -29,7 +29,7 @@ import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/Buffe
|
||||
import { OptionsService } from 'common/services/OptionsService';
|
||||
import { IDisposable, IAttributeData, ICoreTerminal, IScrollEvent } from 'common/Types';
|
||||
import { CoreService } from 'common/services/CoreService';
|
||||
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
|
||||
import { IEvent, forwardEvent } from 'common/EventEmitter';
|
||||
import { CoreMouseService } from 'common/services/CoreMouseService';
|
||||
import { UnicodeService } from 'common/services/UnicodeService';
|
||||
import { CharsetService } from 'common/services/CharsetService';
|
||||
@@ -75,11 +75,11 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
|
||||
* Internally we track the source of the scroll but this is meaningless outside the library so
|
||||
* it's filtered out.
|
||||
*/
|
||||
protected _onScrollApi?: EventEmitter<number, void>;
|
||||
protected _onScroll = this.register(new EventEmitter<IScrollEvent, void>());
|
||||
protected _onScrollApi?: Emitter<number>;
|
||||
protected _onScroll = this.register(new Emitter<IScrollEvent>());
|
||||
public get onScroll(): IEvent<number, void> {
|
||||
if (!this._onScrollApi) {
|
||||
this._onScrollApi = this.register(new EventEmitter<number, void>());
|
||||
this._onScrollApi = this.register(new Emitter<number>());
|
||||
this._onScroll.event(ev => {
|
||||
this._onScrollApi?.fire(ev.position);
|
||||
});
|
||||
|
||||
@@ -6,64 +6,10 @@
|
||||
import { IDisposable } from 'common/Types';
|
||||
import type { Emitter, Event } from 'vs/base/common/event';
|
||||
|
||||
interface IListener<T, U = void> {
|
||||
(arg1: T, arg2: U): void;
|
||||
}
|
||||
|
||||
export interface IEvent<T, U = void> {
|
||||
(listener: (arg1: T, arg2: U) => any): IDisposable;
|
||||
}
|
||||
|
||||
export interface IEventEmitter<T, U = void> {
|
||||
event: IEvent<T, U>;
|
||||
fire(arg1: T, arg2: U): void;
|
||||
dispose(): void;
|
||||
}
|
||||
/** @deprecated Use vs/base/common/events version */
|
||||
export class EventEmitter<T, U = void> implements IEventEmitter<T, U> {
|
||||
private _listeners: Set<IListener<T, U>> = new Set();
|
||||
private _event?: IEvent<T, U>;
|
||||
private _disposed: boolean = false;
|
||||
|
||||
public get event(): IEvent<T, U> {
|
||||
if (!this._event) {
|
||||
this._event = (listener: (arg1: T, arg2: U) => any) => {
|
||||
this._listeners.add(listener);
|
||||
const disposable = {
|
||||
dispose: () => {
|
||||
if (!this._disposed) {
|
||||
this._listeners.delete(listener);
|
||||
}
|
||||
}
|
||||
};
|
||||
return disposable;
|
||||
};
|
||||
}
|
||||
return this._event;
|
||||
}
|
||||
|
||||
public fire(arg1: T, arg2: U): void {
|
||||
const queue: IListener<T, U>[] = [];
|
||||
for (const l of this._listeners.values()) {
|
||||
queue.push(l);
|
||||
}
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
queue[i].call(undefined, arg1, arg2);
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.clearListeners();
|
||||
this._disposed = true;
|
||||
}
|
||||
|
||||
public clearListeners(): void {
|
||||
if (this._listeners) {
|
||||
this._listeners.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function forwardEvent<T>(from: IEvent<T> | Event<T>, to: Emitter<T>): IDisposable {
|
||||
return from(e => to.fire(e));
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32 } from 'common/input/TextDecoder';
|
||||
import { BufferLine, DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||
import { EventEmitter } from 'common/EventEmitter';
|
||||
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 { CellData } from 'common/buffer/CellData';
|
||||
@@ -135,7 +134,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
|
||||
private readonly _onRequestBell = this.register(new Emitter<void>());
|
||||
public readonly onRequestBell = this._onRequestBell.event;
|
||||
private readonly _onRequestRefreshRows = this.register(new EventEmitter<number, number>());
|
||||
private readonly _onRequestRefreshRows = this.register(new Emitter<{ start: number, end: number }>());
|
||||
public readonly onRequestRefreshRows = this._onRequestRefreshRows.event;
|
||||
private readonly _onRequestReset = this.register(new Emitter<void>());
|
||||
public readonly onRequestReset = this._onRequestReset.event;
|
||||
@@ -501,7 +500,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
const viewportEnd = this._dirtyRowTracker.end + (this._bufferService.buffer.ybase - this._bufferService.buffer.ydisp);
|
||||
const viewportStart = this._dirtyRowTracker.start + (this._bufferService.buffer.ybase - this._bufferService.buffer.ydisp);
|
||||
if (viewportStart < this._bufferService.rows) {
|
||||
this._onRequestRefreshRows.fire(Math.min(viewportStart, this._bufferService.rows - 1), Math.min(viewportEnd, this._bufferService.rows - 1));
|
||||
this._onRequestRefreshRows.fire({
|
||||
start: Math.min(viewportStart, this._bufferService.rows - 1),
|
||||
end: Math.min(viewportEnd, this._bufferService.rows - 1)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1944,7 +1946,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
case 1047: // alt screen buffer
|
||||
this._bufferService.buffers.activateAltBuffer(this._eraseAttrData());
|
||||
this._coreService.isCursorInitialized = true;
|
||||
this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
|
||||
this._onRequestRefreshRows.fire({
|
||||
start: 0,
|
||||
end: this._bufferService.rows - 1
|
||||
});
|
||||
this._onRequestSyncScrollBar.fire();
|
||||
break;
|
||||
case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
|
||||
@@ -2172,7 +2177,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this.restoreCursor();
|
||||
}
|
||||
this._coreService.isCursorInitialized = true;
|
||||
this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
|
||||
this._onRequestRefreshRows.fire({
|
||||
start: 0,
|
||||
end: this._bufferService.rows - 1
|
||||
});
|
||||
this._onRequestSyncScrollBar.fire();
|
||||
break;
|
||||
case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, ICoreMouseService, ICharsetService, UnicodeCharProperties, UnicodeCharWidth, IUnicodeService, IUnicodeVersionProvider, LogLevelEnum, IDecorationService, IInternalDecoration, IOscLinkService } from 'common/services/Services';
|
||||
import { UnicodeService } from 'common/services/UnicodeService';
|
||||
import { IEvent, EventEmitter } from 'common/EventEmitter';
|
||||
import { IEvent } from 'common/EventEmitter';
|
||||
import { clone } from 'common/Clone';
|
||||
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
||||
import { IBufferSet, IBuffer } from 'common/buffer/Types';
|
||||
@@ -19,7 +19,7 @@ export class MockBufferService implements IBufferService {
|
||||
public serviceBrand: any;
|
||||
public get buffer(): IBuffer { return this.buffers.active; }
|
||||
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 }> = new Emitter<{ cols: number, rows: number }>().event;
|
||||
public onScroll: IEvent<number> = new Emitter<number>().event;
|
||||
public isUserScrolling: boolean = false;
|
||||
constructor(
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'common/EventEmitter';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
import { IAttributeData } from 'common/Types';
|
||||
import { Buffer } from 'common/buffer/Buffer';
|
||||
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
||||
import { IBufferService, IOptionsService } from 'common/services/Services';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
|
||||
/**
|
||||
* The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
|
||||
@@ -19,7 +19,7 @@ export class BufferSet extends Disposable implements IBufferSet {
|
||||
private _alt!: Buffer;
|
||||
private _activeBuffer!: Buffer;
|
||||
|
||||
private readonly _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
|
||||
private readonly _onBufferActivate = this.register(new Emitter<{ activeBuffer: IBuffer, inactiveBuffer: IBuffer }>());
|
||||
public readonly onBufferActivate = this._onBufferActivate.event;
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'common/EventEmitter';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
import { IAttributeData, IBufferLine } from 'common/Types';
|
||||
import { BufferSet } from 'common/buffer/BufferSet';
|
||||
@@ -23,7 +22,7 @@ export class BufferService extends Disposable implements IBufferService {
|
||||
/** Whether the user is scrolling (locks the scroll position) */
|
||||
public isUserScrolling: boolean = false;
|
||||
|
||||
private readonly _onResize = this.register(new EventEmitter<{ cols: number, rows: number }>());
|
||||
private readonly _onResize = this.register(new Emitter<{ cols: number, rows: number }>());
|
||||
public readonly onResize = this._onResize.event;
|
||||
private readonly _onScroll = this.register(new Emitter<number>());
|
||||
public readonly onScroll = this._onScroll.event;
|
||||
|
||||
@@ -7,11 +7,10 @@ import { Browser, JSHandle, Page } from '@playwright/test';
|
||||
import { deepStrictEqual, strictEqual } from 'assert';
|
||||
import type { IRenderDimensions } from 'browser/renderer/shared/Types';
|
||||
import type { IRenderService } from 'browser/services/Services';
|
||||
import type { ICoreTerminal, IMarker } from 'common/Types';
|
||||
import type { ICoreTerminal, IDisposable, IMarker } from 'common/Types';
|
||||
import * as playwright from '@playwright/test';
|
||||
import { PageFunction } from 'playwright-core/types/structs';
|
||||
import { IBuffer, IBufferCell, IBufferLine, IBufferNamespace, IBufferRange, IDecoration, IDecorationOptions, IModes, ITerminalInitOnlyOptions, ITerminalOptions, Terminal } from '@xterm/xterm';
|
||||
import { EventEmitter } from '../../out/common/EventEmitter';
|
||||
|
||||
export interface ITestContext {
|
||||
browser: Browser;
|
||||
@@ -35,6 +34,56 @@ export async function createTestContext(browser: Browser): Promise<ITestContext>
|
||||
};
|
||||
}
|
||||
|
||||
interface IListener<T, U = void> {
|
||||
(arg1: T, arg2: U): void;
|
||||
}
|
||||
export interface IEvent<T, U = void> {
|
||||
(listener: (arg1: T, arg2: U) => any): IDisposable;
|
||||
}
|
||||
class EventEmitter<T, U = void> {
|
||||
private _listeners: Set<IListener<T, U>> = new Set();
|
||||
private _event?: IEvent<T, U>;
|
||||
private _disposed: boolean = false;
|
||||
|
||||
public get event(): IEvent<T, U> {
|
||||
if (!this._event) {
|
||||
this._event = (listener: (arg1: T, arg2: U) => any) => {
|
||||
this._listeners.add(listener);
|
||||
const disposable = {
|
||||
dispose: () => {
|
||||
if (!this._disposed) {
|
||||
this._listeners.delete(listener);
|
||||
}
|
||||
}
|
||||
};
|
||||
return disposable;
|
||||
};
|
||||
}
|
||||
return this._event;
|
||||
}
|
||||
|
||||
public fire(arg1: T, arg2: U): void {
|
||||
const queue: IListener<T, U>[] = [];
|
||||
for (const l of this._listeners.values()) {
|
||||
queue.push(l);
|
||||
}
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
queue[i].call(undefined, arg1, arg2);
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.clearListeners();
|
||||
this._disposed = true;
|
||||
}
|
||||
|
||||
public clearListeners(): void {
|
||||
if (this._listeners) {
|
||||
this._listeners.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type EnsureAsync<T> = T extends PromiseLike<any> ? T : Promise<T>;
|
||||
type EnsureAsyncProperties<T> = {
|
||||
[Key in keyof T]: EnsureAsync<T[Key]>
|
||||
@@ -107,22 +156,32 @@ export class TerminalProxy implements ITerminalProxyCustomMethods, PlaywrightApi
|
||||
* Initialize the proxy for a new terminal object.
|
||||
*/
|
||||
public async initTerm(): Promise<void> {
|
||||
for (const emitter of [
|
||||
this._onBell,
|
||||
this._onBinary,
|
||||
this._onCursorMove,
|
||||
this._onData,
|
||||
this._onKey,
|
||||
this._onLineFeed,
|
||||
this._onRender,
|
||||
this._onResize,
|
||||
this._onScroll,
|
||||
this._onSelectionChange,
|
||||
this._onTitleChange,
|
||||
this._onWriteParsed
|
||||
]) {
|
||||
emitter.clearListeners();
|
||||
}
|
||||
this._onBell.dispose();
|
||||
this._onBinary.dispose();
|
||||
this._onCursorMove.dispose();
|
||||
this._onData.dispose();
|
||||
this._onKey.dispose();
|
||||
this._onLineFeed.dispose();
|
||||
this._onRender.dispose();
|
||||
this._onResize.dispose();
|
||||
this._onScroll.dispose();
|
||||
this._onSelectionChange.dispose();
|
||||
this._onTitleChange.dispose();
|
||||
this._onWriteParsed.dispose();
|
||||
|
||||
this._onBell = new EventEmitter();
|
||||
this._onBinary = new EventEmitter();
|
||||
this._onCursorMove = new EventEmitter();
|
||||
this._onData = new EventEmitter();
|
||||
this._onKey = new EventEmitter();
|
||||
this._onLineFeed = new EventEmitter();
|
||||
this._onRender = new EventEmitter();
|
||||
this._onResize = new EventEmitter();
|
||||
this._onScroll = new EventEmitter();
|
||||
this._onSelectionChange = new EventEmitter();
|
||||
this._onTitleChange = new EventEmitter();
|
||||
this._onWriteParsed = new EventEmitter();
|
||||
|
||||
await this.evaluate(([term]) => term.onBell((window as any).onBell));
|
||||
await this.evaluate(([term]) => term.onBinary((window as any).onBinary));
|
||||
await this.evaluate(([term]) => term.onCursorMove((window as any).onCursorMove));
|
||||
@@ -139,29 +198,29 @@ export class TerminalProxy implements ITerminalProxyCustomMethods, PlaywrightApi
|
||||
|
||||
// #region Events
|
||||
private _onBell = new EventEmitter<void>();
|
||||
public readonly onBell = this._onBell.event;
|
||||
public get onBell(): IEvent<void> { return this._onBell.event; }
|
||||
private _onBinary = new EventEmitter<string>();
|
||||
public readonly onBinary = this._onBinary.event;
|
||||
public get onBinary(): IEvent<string> { return this._onBinary.event; }
|
||||
private _onCursorMove = new EventEmitter<void>();
|
||||
public readonly onCursorMove = this._onCursorMove.event;
|
||||
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
|
||||
private _onData = new EventEmitter<string>();
|
||||
public readonly onData = this._onData.event;
|
||||
public get onData(): IEvent<string> { return this._onData.event; }
|
||||
private _onKey = new EventEmitter<{ key: string, domEvent: KeyboardEvent }>();
|
||||
public readonly onKey = this._onKey.event;
|
||||
public get onKey(): IEvent<{ key: string, domEvent: KeyboardEvent }> { return this._onKey.event; }
|
||||
private _onLineFeed = new EventEmitter<void>();
|
||||
public readonly onLineFeed = this._onLineFeed.event;
|
||||
public get onLineFeed(): IEvent<void> { return this._onLineFeed.event; }
|
||||
private _onRender = new EventEmitter<{ start: number, end: number }>();
|
||||
public readonly onRender = this._onRender.event;
|
||||
public get onRender(): IEvent<{ start: number, end: number }> { return this._onRender.event; }
|
||||
private _onResize = new EventEmitter<{ cols: number, rows: number }>();
|
||||
public readonly onResize = this._onResize.event;
|
||||
public get onResize(): IEvent<{ cols: number, rows: number }> { return this._onResize.event; }
|
||||
private _onScroll = new EventEmitter<number>();
|
||||
public readonly onScroll = this._onScroll.event;
|
||||
public get onScroll(): IEvent<number> { return this._onScroll.event; }
|
||||
private _onSelectionChange = new EventEmitter<void>();
|
||||
public readonly onSelectionChange = this._onSelectionChange.event;
|
||||
public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }
|
||||
private _onTitleChange = new EventEmitter<string>();
|
||||
public readonly onTitleChange = this._onTitleChange.event;
|
||||
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
|
||||
private _onWriteParsed = new EventEmitter<void>();
|
||||
public readonly onWriteParsed = this._onWriteParsed.event;
|
||||
public get onWriteParsed(): IEvent<void> { return this._onWriteParsed.event; }
|
||||
// #endregion
|
||||
|
||||
// #region Simple properties
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
],
|
||||
"common/*": [
|
||||
"../../src/common/*"
|
||||
],
|
||||
"vs/*": [
|
||||
"../../src/vs/*"
|
||||
]
|
||||
},
|
||||
"target": "ESNext",
|
||||
@@ -38,6 +41,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../../src/common"
|
||||
},
|
||||
{
|
||||
"path": "../../src/vs"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user