large refactor, broken

This commit is contained in:
meganrogge
2022-03-14 15:11:20 -04:00
parent 3b279e4a4d
commit ced06629d4
9 changed files with 431 additions and 373 deletions
+81
View File
@@ -0,0 +1,81 @@
/**
* Copyright (c) 2022 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { EventEmitter } from 'common/EventEmitter';
import { Disposable } from 'common/Lifecycle';
import { IBufferService, IInstantiationService, IDecorationService } from 'common/services/Services';
import { IDecorationOptions, IDecoration, IMarker, IDisposable, IEvent } from 'xterm';
export class DecorationService extends Disposable implements IDecorationService {
private _animationFrame: number | undefined;
private _onDecorationRegistered = this.register(new EventEmitter<IDecorationOptions>());
public get onDecorationRegistered(): IEvent<IDecorationOptions> { return this._onDecorationRegistered.event; }
private _onDecorationRemoved = this.register(new EventEmitter<IDecoration>());
public get onDecorationRemoved(): IEvent<IDecoration> { return this._onDecorationRemoved.event; }
private _decorations: IDecoration[] = [];
constructor() {
super();
}
public registerDecoration(options: IDecorationOptions): IDecoration | undefined {
if (options.marker.isDisposed) {
return undefined;
}
const decoration = new Decoration(options);
if (decoration) {
decoration.onDispose(() => {
if (decoration) {
this._decorations.splice(this._decorations.indexOf(decoration), 1);
}
});
this._decorations.push(decoration);
this._onDecorationRegistered.fire(options);
decoration.onRender(d => {
decoration.setElement(d);
});
}
return decoration;
}
public dispose(): void {
for (const decoration of this._decorations) {
this._onDecorationRemoved.fire(decoration);
decoration.dispose();
}
this._decorations = [];
}
private _queueRefresh(): void {
if (this._animationFrame !== undefined) {
return;
}
this._animationFrame = window.requestAnimationFrame(() => {
// this._refresh();
this._animationFrame = undefined;
});
}
}
class Decoration implements IDecoration {
public marker: IMarker;
private _onRender = new EventEmitter<HTMLElement>();
public get onRender(): IEvent<HTMLElement> { return this._onRender.event; }
private _onDispose = new EventEmitter<void>();
public get onDispose(): IEvent<void> { return this._onDispose.event; }
public element: HTMLElement | undefined;
public isDisposed: boolean = false;
public dispose(): void {
throw new Error('Method not implemented.');
}
constructor(decorationOptions?: IDecorationOptions) {
this.marker = decorationOptions?.marker!;
this.element = undefined;
}
public setElement(element: HTMLElement): void {
this.element = element;
}
}
+8 -1
View File
@@ -5,8 +5,9 @@
import { IEvent } from 'common/EventEmitter';
import { IBuffer, IBufferSet } from 'common/buffer/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions, IModes, IAttributeData, ScrollSource } from 'common/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions, IModes, IAttributeData, ScrollSource, IDisposable } from 'common/Types';
import { createDecorator } from 'common/services/ServiceRegistry';
import { IDecorationOptions, IDecoration } from 'xterm';
export const IBufferService = createDecorator<IBufferService>('BufferService');
export interface IBufferService {
@@ -245,6 +246,7 @@ export interface ITerminalOptions {
windowsMode: boolean;
windowOptions: IWindowOptions;
wordSeparator: string;
overviewRulerWidth?: number;
[key: string]: any;
cancelEvents: boolean;
@@ -298,3 +300,8 @@ export interface IUnicodeVersionProvider {
readonly version: string;
wcwidth(ucs: number): 0 | 1 | 2;
}
export interface IDecorationService extends IDisposable {
readonly onDecorationRegistered: IEvent<IDecorationOptions>;
readonly onDecorationRemoved: IEvent<IDecoration>;
registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
}