Skip to content

Commit 543fefa

Browse files
committed
next approach
1 parent 41d1ca1 commit 543fefa

File tree

18 files changed

+106
-178
lines changed

18 files changed

+106
-178
lines changed

.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"src/browser/tsconfig.json",
1212
"src/common/tsconfig.json",
1313
"src/headless/tsconfig.json",
14-
"src/shared/tsconfig.json",
1514
"src/vs/tsconfig.json",
1615
"test/benchmark/tsconfig.json",
1716
"test/playwright/tsconfig.json",

addons/addon-progress/src/ProgressAddon.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
* @license MIT
44
*/
55

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

9-
// to use impl parts:
10-
11-
// in 3rd party addons
12-
// import { EmitterAddon } from '@xterm/xterm';
13-
14-
// in xtermjs repo addons
15-
import { EmitterAddon } from 'shared/shared';
16-
179

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

4234

43-
export class ProgressAddon extends EmitterAddon implements ITerminalAddon, IProgressApi {
35+
export class ProgressAddon implements ITerminalAddon, IProgressApi {
4436
private _seqHandler: IDisposable | undefined;
4537
private _st: ProgressType = ProgressType.REMOVE;
4638
private _pr = 0;
4739
private _onChange: IEmitter<IProgressState>;
4840
public onChange: IEvent<IProgressState>;
4941

50-
constructor(protected readonly _emitterCtor: EmitterCtorType) {
51-
super(_emitterCtor);
52-
this._onChange = new this._emitterCtor<IProgressState>();
42+
constructor(sharedExports: ISharedExports) {
43+
this._onChange = new sharedExports.Emitter<IProgressState>();
5344
this.onChange = this._onChange.event;
5445
}
5546

addons/addon-progress/src/tsconfig.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
"vs/*": [
2323
"../../../src/vs/*"
2424
],
25-
"shared/*": [
26-
"../../../src/shared/*"
27-
],
2825
"@xterm/addon-progress": [
2926
"../typings/addon-progress.d.ts"
3027
]
@@ -40,9 +37,6 @@
4037
},
4138
{
4239
"path": "../../../src/vs"
43-
},
44-
{
45-
"path": "../../../src/shared"
4640
}
4741
]
4842
}

addons/addon-progress/test/ProgressAddon.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test.describe('ProgressAddon', () => {
2323
window.progressStack = [];
2424
window.term.reset();
2525
window.progressAddon?.dispose();
26-
window.progressAddon = new ProgressAddon(emitterCtor);
26+
window.progressAddon = new ProgressAddon(sharedExports);
2727
window.term.loadAddon(window.progressAddon);
2828
window.progressAddon.onChange(progress => window.progressStack.push(progress));
2929
`);

addons/addon-progress/typings/addon-progress.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
* @license MIT
44
*/
55

6-
import { Terminal, ITerminalAddon, IDisposable, IEvent, EmitterCtorType } from '@xterm/xterm';
7-
import { EmitterAddon } from 'shared/shared';
6+
import { Terminal, ITerminalAddon, IDisposable, IEvent, ISharedExports } from '@xterm/xterm';
7+
88

99
declare module '@xterm/addon-progress' {
1010
/**
1111
* An xterm.js addon that provides an interface for ConEmu's progress
1212
* sequence.
1313
*/
14-
export class ProgressAddon extends EmitterAddon implements ITerminalAddon, IDisposable {
14+
export class ProgressAddon implements ITerminalAddon, IDisposable {
1515

1616
/**
1717
* Creates a new progress addon
1818
*/
19-
constructor(_emitterCtor: EmitterCtorType);
19+
constructor(sharedExports: ISharedExports);
2020

2121
/**
2222
* Activates the addon

addons/addon-progress/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = {
2828
common: path.resolve('../../out/common'),
2929
browser: path.resolve('../../out/browser'),
3030
vs: path.resolve('../../out/vs'),
31-
shared: path.resolve('../../out/shared')
3231
}
3332
},
3433
output: {

bin/esbuild.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ if (config.addon) {
176176
'src/browser/**/*.ts',
177177
'src/common/**/*.ts',
178178
'src/headless/**/*.ts',
179-
'src/shared/**/*.ts',
180179
'src/vs/base/**/*.ts',
181180
'src/vs/patches/**/*.ts'
182181
],

demo/client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if ('WebAssembly' in window) {
1616
ImageAddon = imageAddon.ImageAddon;
1717
}
1818

19-
import { Terminal, ITerminalOptions, type IDisposable, type ITheme, emitterCtor } from '@xterm/xterm';
19+
import { Terminal, ITerminalOptions, type IDisposable, type ITheme, sharedExports, ISharedExports } from '@xterm/xterm';
2020
import { AttachAddon } from '@xterm/addon-attach';
2121
import { ClipboardAddon } from '@xterm/addon-clipboard';
2222
import { FitAddon } from '@xterm/addon-fit';
@@ -32,6 +32,7 @@ import { UnicodeGraphemesAddon } from '@xterm/addon-unicode-graphemes';
3232
export interface IWindowWithTerminal extends Window {
3333
term: typeof Terminal;
3434
Terminal: typeof Terminal;
35+
sharedExports: ISharedExports;
3536
AttachAddon?: typeof AttachAddon; // eslint-disable-line @typescript-eslint/naming-convention
3637
ClipboardAddon?: typeof ClipboardAddon; // eslint-disable-line @typescript-eslint/naming-convention
3738
FitAddon?: typeof FitAddon; // eslint-disable-line @typescript-eslint/naming-convention
@@ -44,8 +45,6 @@ export interface IWindowWithTerminal extends Window {
4445
Unicode11Addon?: typeof Unicode11Addon; // eslint-disable-line @typescript-eslint/naming-convention
4546
UnicodeGraphemesAddon?: typeof UnicodeGraphemesAddon; // eslint-disable-line @typescript-eslint/naming-convention
4647
LigaturesAddon?: typeof LigaturesAddon; // eslint-disable-line @typescript-eslint/naming-convention
47-
48-
emitterCtor?: typeof emitterCtor;
4948
}
5049
declare let window: IWindowWithTerminal;
5150

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

217216
if (document.location.pathname === '/test') {
218217
window.Terminal = Terminal;
218+
window.sharedExports = sharedExports;
219219
window.AttachAddon = AttachAddon;
220220
window.ClipboardAddon = ClipboardAddon;
221221
window.FitAddon = FitAddon;
@@ -228,8 +228,6 @@ if (document.location.pathname === '/test') {
228228
window.LigaturesAddon = LigaturesAddon;
229229
window.WebLinksAddon = WebLinksAddon;
230230
window.WebglAddon = WebglAddon;
231-
232-
window.emitterCtor = emitterCtor;
233231
} else {
234232
createTerminal();
235233
document.getElementById('dispose').addEventListener('click', disposeRecreateButtonHandler);
@@ -283,7 +281,8 @@ function createTerminal(): void {
283281
addons.serialize.instance = new SerializeAddon();
284282
addons.fit.instance = new FitAddon();
285283
addons.image.instance = new ImageAddon();
286-
addons.progress.instance = new ProgressAddon(emitterCtor);
284+
//addons.progress.instance = new ProgressAddon(Terminal as unknown as IXtermSharedImports);
285+
addons.progress.instance = new ProgressAddon(sharedExports);
287286
addons.unicodeGraphemes.instance = new UnicodeGraphemesAddon();
288287
addons.clipboard.instance = new ClipboardAddon();
289288
try { // try to start with webgl renderer (might throw on older safari/webkit)
@@ -664,6 +663,7 @@ function initAddons(term: Terminal): void {
664663
}
665664
if (checkbox.checked) {
666665
// HACK: Manually remove addons that cannot be changes
666+
// FIXME: re-enable this once done with the sharedExports
667667
//addon.instance = new (addon as IDemoAddon<Exclude<AddonType, 'attach'>>).ctor();
668668
try {
669669
term.loadAddon(addon.instance);

src/browser/public/Terminal.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@
66
import * as Strings from 'browser/LocalizableStrings';
77
import { CoreBrowserTerminal as TerminalCore } from 'browser/CoreBrowserTerminal';
88
import { IBufferRange, ITerminal } from 'browser/Types';
9-
import { Disposable } from 'vs/base/common/lifecycle';
9+
import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
1010
import { ITerminalOptions } from 'common/Types';
1111
import { AddonManager } from 'common/public/AddonManager';
1212
import { BufferNamespaceApi } from 'common/public/BufferNamespaceApi';
1313
import { ParserApi } from 'common/public/ParserApi';
1414
import { UnicodeApi } from 'common/public/UnicodeApi';
15-
import { IBufferNamespace as IBufferNamespaceApi, IDecoration, IDecorationOptions, IDisposable, ILinkProvider, ILocalizableStrings, IMarker, IModes, IParser, ITerminalAddon, Terminal as ITerminalApi, ITerminalInitOnlyOptions, IUnicodeHandling } from '@xterm/xterm';
16-
import { type Event } from 'vs/base/common/event';
15+
import { IBufferNamespace as IBufferNamespaceApi, IDecoration, IDecorationOptions, IDisposable, ILinkProvider, ILocalizableStrings, IMarker, IModes, IParser, ITerminalAddon, Terminal as ITerminalApi, ITerminalInitOnlyOptions, IUnicodeHandling, ISharedExports } from '@xterm/xterm';
16+
import { type Event, Emitter } from 'vs/base/common/event';
17+
18+
19+
/**
20+
* EXPERIMENTAL:
21+
* Expose certain building blocks on the module to be used at runtime in addons.
22+
*/
23+
export const sharedExports: ISharedExports = {
24+
DisposableStore,
25+
Emitter,
26+
toDisposable
27+
};
28+
1729

1830
/**
1931
* The set of options that only have an effect when set in the Terminal constructor.
@@ -272,17 +284,3 @@ export class Terminal extends Disposable implements ITerminalApi {
272284
}
273285
}
274286
}
275-
276-
277-
/**
278-
* Expose often needed vs/* parts in addons.
279-
* Exposed statically on the xterm package,
280-
* so they can be used on addon ctors already.
281-
*/
282-
export {
283-
DisposableAddon,
284-
EmitterAddon,
285-
DisposableEmitterAddon
286-
} from 'shared/shared';
287-
export { DisposableStore as disposableStoreCtor, toDisposable } from 'vs/base/common/lifecycle';
288-
export { Emitter as emitterCtor } from 'vs/base/common/event';

src/browser/tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"baseUrl": "..",
1414
"paths": {
1515
"common/*": [ "./common/*" ],
16-
"vs/*": [ "./vs/*" ],
17-
"shared/*": [ "./shared/*" ],
16+
"vs/*": [ "./vs/*" ]
1817
}
1918
},
2019
"include": [
@@ -23,7 +22,6 @@
2322
],
2423
"references": [
2524
{ "path": "../common" },
26-
{ "path": "../vs" },
27-
{ "path": "../shared" },
25+
{ "path": "../vs" }
2826
]
2927
}

0 commit comments

Comments
 (0)