Remove IEvent and runAndSubscribe

This commit is contained in:
Daniel Imms
2024-07-14 08:17:16 -07:00
parent 9141b525a6
commit 9c7e2ea98e
15 changed files with 126 additions and 141 deletions
+3 -3
View File
@@ -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 { IEvent, forwardEvent } from 'common/EventEmitter';
import { forwardEvent } from 'common/EventEmitter';
import { CoreMouseService } from 'common/services/CoreMouseService';
import { UnicodeService } from 'common/services/UnicodeService';
import { CharsetService } from 'common/services/CharsetService';
@@ -39,7 +39,7 @@ import { IBufferSet } from 'common/buffer/Types';
import { InputHandler } from 'common/InputHandler';
import { WriteBuffer } from 'common/input/WriteBuffer';
import { OscLinkService } from 'common/services/OscLinkService';
import { Emitter } from 'vs/base/common/event';
import { Emitter, type Event } from 'vs/base/common/event';
// Only trigger this warning a single time per session
let hasWriteSyncWarnHappened = false;
@@ -77,7 +77,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
*/
protected _onScrollApi?: Emitter<number>;
protected _onScroll = this.register(new Emitter<IScrollEvent>());
public get onScroll(): IEvent<number, void> {
public get onScroll(): Event<number> {
if (!this._onScrollApi) {
this._onScrollApi = this.register(new Emitter<number>());
this._onScroll.event(ev => {
+1 -11
View File
@@ -6,16 +6,6 @@
import { IDisposable } from 'common/Types';
import type { Emitter, Event } from 'vs/base/common/event';
export interface IEvent<T, U = void> {
(listener: (arg1: T, arg2: U) => any): IDisposable;
}
export function forwardEvent<T>(from: IEvent<T> | Event<T>, to: Emitter<T>): IDisposable {
export function forwardEvent<T>(from: Event<T>, to: Emitter<T>): IDisposable {
return from(e => to.fire(e));
}
/** @deprecated Use vs/base/common/events version */
export function runAndSubscribe<T>(event: IEvent<T>, handler: (e: T | undefined) => any): IDisposable {
handler(undefined);
return event(e => handler(e));
}
+10 -11
View File
@@ -5,7 +5,6 @@
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 } from 'common/EventEmitter';
import { clone } from 'common/Clone';
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
import { IBufferSet, IBuffer } from 'common/buffer/Types';
@@ -13,14 +12,14 @@ import { BufferSet } from 'common/buffer/BufferSet';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset, IModes, IAttributeData, IOscLinkData, IDisposable } from 'common/Types';
import { UnicodeV6 } from 'common/input/UnicodeV6';
import { IDecorationOptions, IDecoration } from '@xterm/xterm';
import { Emitter } from 'vs/base/common/event';
import { Emitter, type Event } from 'vs/base/common/event';
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 Emitter<{ cols: number, rows: number }>().event;
public onScroll: IEvent<number> = new Emitter<number>().event;
public onResize: Event<{ cols: number, rows: number }> = new Emitter<{ cols: number, rows: number }>().event;
public onScroll: Event<number> = new Emitter<number>().event;
public isUserScrolling: boolean = false;
constructor(
public cols: number,
@@ -63,7 +62,7 @@ export class MockCoreMouseService implements ICoreMouseService {
public addProtocol(name: string): void { }
public reset(): void { }
public triggerMouseEvent(event: ICoreMouseEvent): boolean { return false; }
public onProtocolChange: IEvent<CoreMouseEventType> = new Emitter<CoreMouseEventType>().event;
public onProtocolChange: Event<CoreMouseEventType> = new Emitter<CoreMouseEventType>().event;
public explainEvents(events: CoreMouseEventType): { [event: string]: boolean } {
throw new Error('Method not implemented.');
}
@@ -95,10 +94,10 @@ export class MockCoreService implements ICoreService {
sendFocus: false,
wraparound: true
};
public onData: IEvent<string> = new Emitter<string>().event;
public onUserInput: IEvent<void> = new Emitter<void>().event;
public onBinary: IEvent<string> = new Emitter<string>().event;
public onRequestScrollToBottom: IEvent<void> = new Emitter<void>().event;
public onData: Event<string> = new Emitter<string>().event;
public onUserInput: Event<void> = new Emitter<void>().event;
public onBinary: Event<string> = new Emitter<string>().event;
public onRequestScrollToBottom: Event<void> = new Emitter<void>().event;
public reset(): void { }
public triggerDataEvent(data: string, wasUserInput?: boolean): void { }
public triggerBinaryEvent(data: string): void { }
@@ -118,7 +117,7 @@ export class MockOptionsService implements IOptionsService {
public serviceBrand: any;
public readonly rawOptions: Required<ITerminalOptions> = clone(DEFAULT_OPTIONS);
public options: Required<ITerminalOptions> = this.rawOptions;
public onOptionChange: IEvent<keyof ITerminalOptions> = new Emitter<keyof ITerminalOptions>().event;
public onOptionChange: Event<keyof ITerminalOptions> = new Emitter<keyof ITerminalOptions>().event;
constructor(testOptions?: Partial<ITerminalOptions>) {
if (testOptions) {
for (const key of Object.keys(testOptions)) {
@@ -170,7 +169,7 @@ export class MockUnicodeService implements IUnicodeService {
}
public versions: string[] = [];
public activeVersion: string = '';
public onChange: IEvent<string> = new Emitter<string>().event;
public onChange: Event<string> = new Emitter<string>().event;
public wcwidth = (codepoint: number): UnicodeCharWidth => this._provider.wcwidth(codepoint);
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
let width = this.wcwidth(codepoint);
+6 -7
View File
@@ -4,13 +4,12 @@
*/
import { IDeleteEvent, IInsertEvent } from 'common/CircularList';
import { IEvent } from 'common/EventEmitter';
import { Attributes, UnderlineStyle } from 'common/buffer/Constants'; // eslint-disable-line no-unused-vars
import { IBufferSet } from 'common/buffer/Types';
import { IParams } from 'common/parser/Types';
import { ICoreMouseService, ICoreService, IOptionsService, IUnicodeService } from 'common/services/Services';
import { IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from '@xterm/xterm';
import type { Emitter } from 'vs/base/common/event';
import type { Emitter, Event } from 'vs/base/common/event';
export interface ICoreTerminal {
coreMouseService: ICoreMouseService;
@@ -69,11 +68,11 @@ export interface ICircularList<T> {
isFull: boolean;
onDeleteEmitter: Emitter<IDeleteEvent>;
onDelete: IEvent<IDeleteEvent>;
onDelete: Event<IDeleteEvent>;
onInsertEmitter: Emitter<IInsertEvent>;
onInsert: IEvent<IInsertEvent>;
onInsert: Event<IInsertEvent>;
onTrimEmitter: Emitter<number>;
onTrim: IEvent<number>;
onTrim: Event<number>;
get(index: number): T | undefined;
set(index: number, value: T): void;
@@ -259,7 +258,7 @@ export interface IMarker extends IDisposable {
readonly id: number;
readonly isDisposed: boolean;
readonly line: number;
onDispose: IEvent<void>;
onDispose: Event<void>;
}
export interface IModes {
insertMode: boolean;
@@ -447,7 +446,7 @@ export type IColorEvent = (IColorReportRequest | IColorSetRequest | IColorRestor
* Calls the parser and handles actions generated by the parser.
*/
export interface IInputHandler {
onTitleChange: IEvent<string>;
onTitleChange: Event<string>;
parse(data: string | Uint8Array, promiseResult?: boolean): void | Promise<boolean>;
print(data: Uint32Array, start: number, end: number): void;
+2 -2
View File
@@ -4,7 +4,7 @@
*/
import { IAttributeData, ICircularList, IBufferLine, ICellData, IMarker, ICharset, IDisposable } from 'common/Types';
import { IEvent } from 'common/EventEmitter';
import type { Event } from 'vs/base/common/event';
// BufferIndex denotes a position in the buffer: [rowIndex, colIndex]
export type BufferIndex = [number, number];
@@ -42,7 +42,7 @@ export interface IBufferSet extends IDisposable {
normal: IBuffer;
active: IBuffer;
onBufferActivate: IEvent<{ activeBuffer: IBuffer, inactiveBuffer: IBuffer }>;
onBufferActivate: Event<{ activeBuffer: IBuffer, inactiveBuffer: IBuffer }>;
activateNormalBuffer(): void;
activateAltBuffer(fillAttr?: IAttributeData): void;
+12 -13
View File
@@ -4,11 +4,10 @@
*/
import { IDecoration, IDecorationOptions, ILinkHandler, ILogger, IWindowsPty } from '@xterm/xterm';
import { IEvent } from 'common/EventEmitter';
import { CoreMouseEncoding, CoreMouseEventType, CursorInactiveStyle, CursorStyle, IAttributeData, ICharset, IColor, ICoreMouseEvent, ICoreMouseProtocol, IDecPrivateModes, IDisposable, IModes, IOscLinkData, IWindowOptions } from 'common/Types';
import { IBuffer, IBufferSet } from 'common/buffer/Types';
import { createDecorator } from 'common/services/ServiceRegistry';
import type { Emitter } from 'vs/base/common/event';
import type { Emitter, Event } from 'vs/base/common/event';
export const IBufferService = createDecorator<IBufferService>('BufferService');
export interface IBufferService {
@@ -19,8 +18,8 @@ export interface IBufferService {
readonly buffer: IBuffer;
readonly buffers: IBufferSet;
isUserScrolling: boolean;
onResize: IEvent<{ cols: number, rows: number }>;
onScroll: IEvent<number>;
onResize: Event<{ cols: number, rows: number }>;
onScroll: Event<number>;
scroll(eraseAttr: IAttributeData, isWrapped?: boolean): void;
scrollLines(disp: number, suppressScrollEvent?: boolean): void;
resize(cols: number, rows: number): void;
@@ -53,7 +52,7 @@ export interface ICoreMouseService {
/**
* Event to announce changes in mouse tracking.
*/
onProtocolChange: IEvent<CoreMouseEventType>;
onProtocolChange: Event<CoreMouseEventType>;
/**
* Human readable version of mouse events.
@@ -75,10 +74,10 @@ export interface ICoreService {
readonly modes: IModes;
readonly decPrivateModes: IDecPrivateModes;
readonly onData: IEvent<string>;
readonly onUserInput: IEvent<void>;
readonly onBinary: IEvent<string>;
readonly onRequestScrollToBottom: IEvent<void>;
readonly onData: Event<string>;
readonly onUserInput: Event<void>;
readonly onBinary: Event<string>;
readonly onRequestScrollToBottom: Event<void>;
reset(): void;
@@ -187,7 +186,7 @@ export interface IOptionsService {
/**
* Adds an event listener for when any option changes.
*/
readonly onOptionChange: IEvent<keyof ITerminalOptions>;
readonly onOptionChange: Event<keyof ITerminalOptions>;
/**
* Adds an event listener for when a specific option changes, this is a convenience method that is
@@ -339,7 +338,7 @@ export interface IUnicodeService {
/** Currently active version. */
activeVersion: string;
/** Event triggered, when activate version changed. */
readonly onChange: IEvent<string>;
readonly onChange: Event<string>;
/**
* Unicode version dependent
@@ -364,8 +363,8 @@ export const IDecorationService = createDecorator<IDecorationService>('Decoratio
export interface IDecorationService extends IDisposable {
serviceBrand: undefined;
readonly decorations: IterableIterator<IInternalDecoration>;
readonly onDecorationRegistered: IEvent<IInternalDecoration>;
readonly onDecorationRemoved: IEvent<IInternalDecoration>;
readonly onDecorationRegistered: Event<IInternalDecoration>;
readonly onDecorationRemoved: Event<IInternalDecoration>;
registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
reset(): void;
/**