Skip to content

Commit

Permalink
next approach
Browse files Browse the repository at this point in the history
  • Loading branch information
jerch committed Jan 11, 2025
1 parent 41d1ca1 commit 543fefa
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 178 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"src/browser/tsconfig.json",
"src/common/tsconfig.json",
"src/headless/tsconfig.json",
"src/shared/tsconfig.json",
"src/vs/tsconfig.json",
"test/benchmark/tsconfig.json",
"test/playwright/tsconfig.json",
Expand Down
17 changes: 4 additions & 13 deletions addons/addon-progress/src/ProgressAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
* @license MIT
*/

import { Terminal, ITerminalAddon, IDisposable, EmitterCtorType, IEmitter, IEvent } from '@xterm/xterm';
import { Terminal, ITerminalAddon, IDisposable, IEmitter, IEvent, ISharedExports } from '@xterm/xterm';
import type { ProgressAddon as IProgressApi, IProgressState } from '@xterm/addon-progress';

// to use impl parts:

// in 3rd party addons
// import { EmitterAddon } from '@xterm/xterm';

// in xtermjs repo addons
import { EmitterAddon } from 'shared/shared';


const enum ProgressType {
REMOVE = 0,
Expand All @@ -40,16 +32,15 @@ function toInt(s: string): number {
}


export class ProgressAddon extends EmitterAddon implements ITerminalAddon, IProgressApi {
export class ProgressAddon implements ITerminalAddon, IProgressApi {
private _seqHandler: IDisposable | undefined;
private _st: ProgressType = ProgressType.REMOVE;
private _pr = 0;
private _onChange: IEmitter<IProgressState>;
public onChange: IEvent<IProgressState>;

constructor(protected readonly _emitterCtor: EmitterCtorType) {
super(_emitterCtor);
this._onChange = new this._emitterCtor<IProgressState>();
constructor(sharedExports: ISharedExports) {
this._onChange = new sharedExports.Emitter<IProgressState>();
this.onChange = this._onChange.event;
}

Expand Down
6 changes: 0 additions & 6 deletions addons/addon-progress/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"vs/*": [
"../../../src/vs/*"
],
"shared/*": [
"../../../src/shared/*"
],
"@xterm/addon-progress": [
"../typings/addon-progress.d.ts"
]
Expand All @@ -40,9 +37,6 @@
},
{
"path": "../../../src/vs"
},
{
"path": "../../../src/shared"
}
]
}
2 changes: 1 addition & 1 deletion addons/addon-progress/test/ProgressAddon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.describe('ProgressAddon', () => {
window.progressStack = [];
window.term.reset();
window.progressAddon?.dispose();
window.progressAddon = new ProgressAddon(emitterCtor);
window.progressAddon = new ProgressAddon(sharedExports);
window.term.loadAddon(window.progressAddon);
window.progressAddon.onChange(progress => window.progressStack.push(progress));
`);
Expand Down
8 changes: 4 additions & 4 deletions addons/addon-progress/typings/addon-progress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
* @license MIT
*/

import { Terminal, ITerminalAddon, IDisposable, IEvent, EmitterCtorType } from '@xterm/xterm';
import { EmitterAddon } from 'shared/shared';
import { Terminal, ITerminalAddon, IDisposable, IEvent, ISharedExports } from '@xterm/xterm';


declare module '@xterm/addon-progress' {
/**
* An xterm.js addon that provides an interface for ConEmu's progress
* sequence.
*/
export class ProgressAddon extends EmitterAddon implements ITerminalAddon, IDisposable {
export class ProgressAddon implements ITerminalAddon, IDisposable {

/**
* Creates a new progress addon
*/
constructor(_emitterCtor: EmitterCtorType);
constructor(sharedExports: ISharedExports);

/**
* Activates the addon
Expand Down
1 change: 0 additions & 1 deletion addons/addon-progress/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = {
common: path.resolve('../../out/common'),
browser: path.resolve('../../out/browser'),
vs: path.resolve('../../out/vs'),
shared: path.resolve('../../out/shared')
}
},
output: {
Expand Down
1 change: 0 additions & 1 deletion bin/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ if (config.addon) {
'src/browser/**/*.ts',
'src/common/**/*.ts',
'src/headless/**/*.ts',
'src/shared/**/*.ts',
'src/vs/base/**/*.ts',
'src/vs/patches/**/*.ts'
],
Expand Down
12 changes: 6 additions & 6 deletions demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ('WebAssembly' in window) {
ImageAddon = imageAddon.ImageAddon;
}

import { Terminal, ITerminalOptions, type IDisposable, type ITheme, emitterCtor } from '@xterm/xterm';
import { Terminal, ITerminalOptions, type IDisposable, type ITheme, sharedExports, ISharedExports } from '@xterm/xterm';
import { AttachAddon } from '@xterm/addon-attach';
import { ClipboardAddon } from '@xterm/addon-clipboard';
import { FitAddon } from '@xterm/addon-fit';
Expand All @@ -32,6 +32,7 @@ import { UnicodeGraphemesAddon } from '@xterm/addon-unicode-graphemes';
export interface IWindowWithTerminal extends Window {
term: typeof Terminal;
Terminal: typeof Terminal;
sharedExports: ISharedExports;
AttachAddon?: typeof AttachAddon; // eslint-disable-line @typescript-eslint/naming-convention
ClipboardAddon?: typeof ClipboardAddon; // eslint-disable-line @typescript-eslint/naming-convention
FitAddon?: typeof FitAddon; // eslint-disable-line @typescript-eslint/naming-convention
Expand All @@ -44,8 +45,6 @@ export interface IWindowWithTerminal extends Window {
Unicode11Addon?: typeof Unicode11Addon; // eslint-disable-line @typescript-eslint/naming-convention
UnicodeGraphemesAddon?: typeof UnicodeGraphemesAddon; // eslint-disable-line @typescript-eslint/naming-convention
LigaturesAddon?: typeof LigaturesAddon; // eslint-disable-line @typescript-eslint/naming-convention

emitterCtor?: typeof emitterCtor;
}
declare let window: IWindowWithTerminal;

Expand Down Expand Up @@ -216,6 +215,7 @@ const createNewWindowButtonHandler: () => void = () => {

if (document.location.pathname === '/test') {
window.Terminal = Terminal;
window.sharedExports = sharedExports;
window.AttachAddon = AttachAddon;
window.ClipboardAddon = ClipboardAddon;
window.FitAddon = FitAddon;
Expand All @@ -228,8 +228,6 @@ if (document.location.pathname === '/test') {
window.LigaturesAddon = LigaturesAddon;
window.WebLinksAddon = WebLinksAddon;
window.WebglAddon = WebglAddon;

window.emitterCtor = emitterCtor;
} else {
createTerminal();
document.getElementById('dispose').addEventListener('click', disposeRecreateButtonHandler);
Expand Down Expand Up @@ -283,7 +281,8 @@ function createTerminal(): void {
addons.serialize.instance = new SerializeAddon();
addons.fit.instance = new FitAddon();
addons.image.instance = new ImageAddon();
addons.progress.instance = new ProgressAddon(emitterCtor);
//addons.progress.instance = new ProgressAddon(Terminal as unknown as IXtermSharedImports);
addons.progress.instance = new ProgressAddon(sharedExports);
addons.unicodeGraphemes.instance = new UnicodeGraphemesAddon();
addons.clipboard.instance = new ClipboardAddon();
try { // try to start with webgl renderer (might throw on older safari/webkit)
Expand Down Expand Up @@ -664,6 +663,7 @@ function initAddons(term: Terminal): void {
}
if (checkbox.checked) {
// HACK: Manually remove addons that cannot be changes
// FIXME: re-enable this once done with the sharedExports
//addon.instance = new (addon as IDemoAddon<Exclude<AddonType, 'attach'>>).ctor();
try {
term.loadAddon(addon.instance);
Expand Down
32 changes: 15 additions & 17 deletions src/browser/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@
import * as Strings from 'browser/LocalizableStrings';
import { CoreBrowserTerminal as TerminalCore } from 'browser/CoreBrowserTerminal';
import { IBufferRange, ITerminal } from 'browser/Types';
import { Disposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { ITerminalOptions } from 'common/Types';
import { AddonManager } from 'common/public/AddonManager';
import { BufferNamespaceApi } from 'common/public/BufferNamespaceApi';
import { ParserApi } from 'common/public/ParserApi';
import { UnicodeApi } from 'common/public/UnicodeApi';
import { IBufferNamespace as IBufferNamespaceApi, IDecoration, IDecorationOptions, IDisposable, ILinkProvider, ILocalizableStrings, IMarker, IModes, IParser, ITerminalAddon, Terminal as ITerminalApi, ITerminalInitOnlyOptions, IUnicodeHandling } from '@xterm/xterm';
import { type Event } from 'vs/base/common/event';
import { IBufferNamespace as IBufferNamespaceApi, IDecoration, IDecorationOptions, IDisposable, ILinkProvider, ILocalizableStrings, IMarker, IModes, IParser, ITerminalAddon, Terminal as ITerminalApi, ITerminalInitOnlyOptions, IUnicodeHandling, ISharedExports } from '@xterm/xterm';
import { type Event, Emitter } from 'vs/base/common/event';


/**
* EXPERIMENTAL:
* Expose certain building blocks on the module to be used at runtime in addons.
*/
export const sharedExports: ISharedExports = {
DisposableStore,
Emitter,
toDisposable
};


/**
* The set of options that only have an effect when set in the Terminal constructor.
Expand Down Expand Up @@ -272,17 +284,3 @@ export class Terminal extends Disposable implements ITerminalApi {
}
}
}


/**
* Expose often needed vs/* parts in addons.
* Exposed statically on the xterm package,
* so they can be used on addon ctors already.
*/
export {
DisposableAddon,
EmitterAddon,
DisposableEmitterAddon
} from 'shared/shared';
export { DisposableStore as disposableStoreCtor, toDisposable } from 'vs/base/common/lifecycle';
export { Emitter as emitterCtor } from 'vs/base/common/event';
6 changes: 2 additions & 4 deletions src/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"baseUrl": "..",
"paths": {
"common/*": [ "./common/*" ],
"vs/*": [ "./vs/*" ],
"shared/*": [ "./shared/*" ],
"vs/*": [ "./vs/*" ]
}
},
"include": [
Expand All @@ -23,7 +22,6 @@
],
"references": [
{ "path": "../common" },
{ "path": "../vs" },
{ "path": "../shared" },
{ "path": "../vs" }
]
}
19 changes: 19 additions & 0 deletions src/common/shared/AddonDisposable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2024 The xterm.js authors. All rights reserved.
* @license MIT
*/

import { IDisposable, IDisposableStore, ISharedExports } from '@xterm/xterm';


export class AddonDisposable implements IDisposable {
protected readonly _store: IDisposableStore;

constructor(sharedExports: ISharedExports) {
this._store = new sharedExports.DisposableStore();
}

public dispose(): void {
this._store.dispose();
}
}
19 changes: 16 additions & 3 deletions src/headless/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@
import { BufferNamespaceApi } from 'common/public/BufferNamespaceApi';
import { ParserApi } from 'common/public/ParserApi';
import { UnicodeApi } from 'common/public/UnicodeApi';
import { IBufferNamespace as IBufferNamespaceApi, IMarker, IModes, IParser, ITerminalAddon, ITerminalInitOnlyOptions, IUnicodeHandling, Terminal as ITerminalApi } from '@xterm/headless';
import { IBufferNamespace as IBufferNamespaceApi, IMarker, IModes, IParser, ITerminalAddon, ITerminalInitOnlyOptions, IUnicodeHandling, Terminal as ITerminalApi, ISharedExports } from '@xterm/headless';
import { Terminal as TerminalCore } from 'headless/Terminal';
import { AddonManager } from 'common/public/AddonManager';
import { ITerminalOptions } from 'common/Types';
import { Disposable } from 'vs/base/common/lifecycle';
import type { Event } from 'vs/base/common/event';
import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { type Event, Emitter } from 'vs/base/common/event';


/**
* EXPERIMENTAL:
* Expose certain building blocks on the module to be used at runtime in addons.
*/
export const sharedExports: ISharedExports = {
DisposableStore,
Emitter,
toDisposable
};


/**
* The set of options that only have an effect when set in the Terminal constructor.
*/
Expand Down
Empty file removed src/shared/shared.test.ts
Empty file.
42 changes: 0 additions & 42 deletions src/shared/shared.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/shared/tsconfig.json

This file was deleted.

27 changes: 27 additions & 0 deletions typings/xterm-headless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1358,4 +1358,31 @@ declare module '@xterm/headless' {
*/
readonly wraparoundMode: boolean;
}

/**
* EXPERIMENTAL:
* Module exposure of certain building blocks to be used at runtime in addons.
*/
export interface ISharedExports {

Check warning on line 1366 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
readonly DisposableStore: new() => IDisposableStore;

Check warning on line 1367 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
readonly Emitter: new<T>() => IEmitter<T>;

Check warning on line 1368 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
readonly toDisposable: (fn: () => void) => IDisposable;

Check warning on line 1369 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
}

Check warning on line 1370 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4

Check warning on line 1371 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
export const sharedExports: ISharedExports;

Check warning on line 1372 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4

Check warning on line 1373 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
// FIXME: @Tyriar - plz have a look at the following interfaces and

Check warning on line 1374 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
// to what degree those should be exposed or get stripped down

Check warning on line 1375 in typings/xterm-headless.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
export interface IEmitter<T> extends IDisposable {
event: IEvent<T>;
fire(event: T): void;
hasListeners(): boolean;
}
export interface IDisposableStore extends IDisposable {
isDisposed: boolean;
clear(): void;
add<T extends IDisposable>(o: T): T;
delete<T extends IDisposable>(o: T): void;
deleteAndLeak<T extends IDisposable>(o: T): void;
}
}
Loading

0 comments on commit 543fefa

Please sign in to comment.