Skip to content

Commit

Permalink
Merge pull request #4847 from tisilent/add-addon-public-api
Browse files Browse the repository at this point in the history
Have addons implement their API at compile time
  • Loading branch information
Tyriar committed Nov 2, 2023
2 parents 19bdcab + 4beb7d0 commit e8da737
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 33 deletions.
5 changes: 3 additions & 2 deletions addons/addon-attach/src/AttachAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* Implements the attach method, that attaches the terminal to a WebSocket stream.
*/

import { Terminal, IDisposable, ITerminalAddon } from '@xterm/xterm';
import type { Terminal, IDisposable, ITerminalAddon } from '@xterm/xterm';
import type { AttachAddon as IAttachApi } from '@xterm/addon-attach';

interface IAttachOptions {
bidirectional?: boolean;
}

export class AttachAddon implements ITerminalAddon {
export class AttachAddon implements ITerminalAddon , IAttachApi {
private _socket: WebSocket;
private _bidirectional: boolean;
private _disposables: IDisposable[] = [];
Expand Down
7 changes: 6 additions & 1 deletion addons/addon-attach/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
"strict": true,
"types": [
"../../../node_modules/@types/mocha"
]
],
"paths": {
"@xterm/addon-attach": [
"../typings/addon-attach.d.ts"
]
}
},
"include": [
"./**/*",
Expand Down
9 changes: 7 additions & 2 deletions addons/addon-canvas/src/CanvasAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
* @license MIT
*/

import type { ITerminalAddon, Terminal } from '@xterm/xterm';
import type { CanvasAddon as ICanvasApi } from '@xterm/addon-canvas';
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
import { ITerminal } from 'browser/Types';
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { setTraceLogger } from 'common/services/LogService';
import { IBufferService, IDecorationService, ILogService } from 'common/services/Services';
import { ITerminalAddon, Terminal } from '@xterm/xterm';
import { CanvasRenderer } from './CanvasRenderer';

export class CanvasAddon extends Disposable implements ITerminalAddon {
export class CanvasAddon extends Disposable implements ITerminalAddon , ICanvasApi {
private _terminal?: Terminal;
private _renderer?: CanvasRenderer;

Expand Down Expand Up @@ -65,4 +66,8 @@ export class CanvasAddon extends Disposable implements ITerminalAddon {
this._renderer = undefined;
}));
}

public clearTextureAtlas(): void {
this._renderer?.clearTextureAtlas();
}
}
3 changes: 3 additions & 0 deletions addons/addon-canvas/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
],
"browser/*": [
"../../../src/browser/*"
],
"@xterm/addon-canvas": [
"../typings/addon-canvas.d.ts"
]
},
"strict": true,
Expand Down
5 changes: 3 additions & 2 deletions addons/addon-fit/src/FitAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @license MIT
*/

import { Terminal, ITerminalAddon } from '@xterm/xterm';
import type { Terminal, ITerminalAddon } from '@xterm/xterm';
import type { FitAddon as IFitApi } from '@xterm/addon-fit';
import { IRenderDimensions } from 'browser/renderer/shared/Types';

interface ITerminalDimensions {
Expand All @@ -21,7 +22,7 @@ interface ITerminalDimensions {
const MINIMUM_COLS = 2;
const MINIMUM_ROWS = 1;

export class FitAddon implements ITerminalAddon {
export class FitAddon implements ITerminalAddon , IFitApi {
private _terminal: Terminal | undefined;

public activate(terminal: Terminal): void {
Expand Down
3 changes: 3 additions & 0 deletions addons/addon-fit/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"paths": {
"browser/*": [
"../../../src/browser/*"
],
"@xterm/addon-fit": [
"../typings/addon-fit.d.ts"
]
}
},
Expand Down
6 changes: 3 additions & 3 deletions addons/addon-image/src/ImageAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* @license MIT
*/

import type { ITerminalAddon, IDisposable } from '@xterm/xterm';
import type { ImageAddon as IImageApi } from '@xterm/addon-image';
import { IIPHandler } from './IIPHandler';
import { ITerminalAddon, IDisposable } from '@xterm/xterm';
import { ImageRenderer } from './ImageRenderer';
import { ImageStorage, CELL_SIZE_DEFAULT } from './ImageStorage';
import { SixelHandler } from './SixelHandler';
import { ITerminalExt, IImageAddonOptions, IResetHandler } from './Types';


// default values of addon ctor options
const DEFAULT_OPTIONS: IImageAddonOptions = {
enableSizeReports: true,
Expand Down Expand Up @@ -48,7 +48,7 @@ const enum GaStatus {
}


export class ImageAddon implements ITerminalAddon {
export class ImageAddon implements ITerminalAddon , IImageApi {
private _opts: IImageAddonOptions;
private _defaultOpts: IImageAddonOptions;
private _storage: ImageStorage | undefined;
Expand Down
3 changes: 2 additions & 1 deletion addons/addon-image/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"baseUrl": ".",
"paths": {
"browser/*": [ "../../../src/browser/*" ],
"common/*": [ "../../../src/common/*" ]
"common/*": [ "../../../src/common/*" ],
"@xterm/addon-image": [ "../typings/addon-image.d.ts" ]
}
},
"include": [
Expand Down
5 changes: 3 additions & 2 deletions addons/addon-ligatures/src/LigaturesAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @license MIT
*/

import { Terminal } from '@xterm/xterm';
import type { Terminal } from '@xterm/xterm';
import type { LigaturesAddon as ILigaturesApi } from '@xterm/addon-ligatures';
import { enableLigatures } from '.';
import { ILigatureOptions } from './Types';

Expand All @@ -12,7 +13,7 @@ export interface ITerminalAddon {
dispose(): void;
}

export class LigaturesAddon implements ITerminalAddon {
export class LigaturesAddon implements ITerminalAddon , ILigaturesApi {
private readonly _fallbackLigatures: string[];

private _terminal: Terminal | undefined;
Expand Down
7 changes: 6 additions & 1 deletion addons/addon-ligatures/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
"preserveWatchOutput": true,
"types": [
"../../../node_modules/@types/mocha"
]
],
"paths": {
"@xterm/addon-ligatures" : [
"../typings/addon-ligatures.d.ts"
]
}
},
"include": [
"./**/*",
Expand Down
3 changes: 1 addition & 2 deletions addons/addon-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"xterm.js"
],
"scripts": {
"build": "../../node_modules/.bin/tsc -p .",
"prepackage": "npm run build",
"prepackage": "../../node_modules/.bin/tsc -p .",
"package": "../../node_modules/.bin/webpack",
"prepublishOnly": "npm run package"
},
Expand Down
5 changes: 3 additions & 2 deletions addons/addon-search/src/SearchAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @license MIT
*/

import { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
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 } from 'common/Lifecycle';

Expand Down Expand Up @@ -61,7 +62,7 @@ const NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?';
const LINES_CACHE_TIME_TO_LIVE = 15 * 1000; // 15 secs
const DEFAULT_HIGHLIGHT_LIMIT = 1000;

export class SearchAddon extends Disposable implements ITerminalAddon {
export class SearchAddon extends Disposable implements ITerminalAddon , ISearchApi {
private _terminal: Terminal | undefined;
private _cachedSearchTerm: string | undefined;
private _highlightedLines: Set<number> = new Set();
Expand Down
3 changes: 3 additions & 0 deletions addons/addon-search/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"paths": {
"common/*": [
"../../../src/common/*"
],
"@xterm/addon-search" : [
"../typings/addon-search.d.ts"
]
}
},
Expand Down
5 changes: 4 additions & 1 deletion addons/addon-serialize/benchmark/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"paths": {
"common/*": ["../../../src/common/*"],
"browser/*": ["../../../src/browser/*"],
"SerializeAddon": ["../src/SerializeAddon"]
"SerializeAddon": ["../src/SerializeAddon"],
"@xterm/addon-serialize": [
"../typings/addon-serialize.d.ts"
]
}
},
"include": ["../**/*", "../../../typings/xterm.d.ts"],
Expand Down
5 changes: 3 additions & 2 deletions addons/addon-serialize/src/SerializeAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* (EXPERIMENTAL) This Addon is still under development
*/

import type { IBuffer, IBufferCell, IBufferRange, ITerminalAddon, Terminal } from '@xterm/xterm';
import type { SerializeAddon as ISerializeApi } from '@xterm/addon-serialize';
import { DEFAULT_ANSI_COLORS } from 'browser/services/ThemeService';
import { IAttributeData, IColor } from 'common/Types';
import { IBuffer, IBufferCell, IBufferRange, ITerminalAddon, Terminal } from '@xterm/xterm';

function constrain(value: number, low: number, high: number): number {
return Math.max(low, Math.min(value, high));
Expand Down Expand Up @@ -411,7 +412,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
}
}

export class SerializeAddon implements ITerminalAddon {
export class SerializeAddon implements ITerminalAddon , ISerializeApi {
private _terminal: Terminal | undefined;

public activate(terminal: Terminal): void {
Expand Down
3 changes: 3 additions & 0 deletions addons/addon-serialize/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
],
"browser/*": [
"../../../src/browser/*"
],
"@xterm/addon-serialize": [
"../typings/addon-serialize.d.ts"
]
},
"strict": true,
Expand Down
5 changes: 4 additions & 1 deletion addons/addon-unicode-graphemes/benchmark/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"paths": {
"common/*": ["../../../src/common/*"],
"browser/*": ["../../../src/browser/*"],
"UnicodeGraphemeProvider": ["../src/UnicodeGraphemeProvider"]
"UnicodeGraphemeProvider": ["../src/UnicodeGraphemeProvider"],
"@xterm/addon-unicode-graphemes": [
"../typings/addon-unicode-graphemes.d.ts"
]
}
},
"include": ["../**/*", "../../../typings/xterm.d.ts"],
Expand Down
6 changes: 3 additions & 3 deletions addons/addon-unicode-graphemes/src/UnicodeGraphemesAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* UnicodeVersionProvider for V15 with grapeme cluster handleing.
*/

import { Terminal, ITerminalAddon, IUnicodeHandling } from '@xterm/xterm';
import type { Terminal, ITerminalAddon, IUnicodeHandling } from '@xterm/xterm';
import type { UnicodeGraphemesAddon as IUnicodeGraphemesApi } from '@xterm/addon-unicode-graphemes';
import { UnicodeGraphemeProvider } from './UnicodeGraphemeProvider';


export class UnicodeGraphemesAddon implements ITerminalAddon {
export class UnicodeGraphemesAddon implements ITerminalAddon , IUnicodeGraphemesApi {
private _provider15Graphemes?: UnicodeGraphemeProvider;
private _provider15?: UnicodeGraphemeProvider;
private _unicode?: IUnicodeHandling;
Expand Down
3 changes: 3 additions & 0 deletions addons/addon-unicode-graphemes/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"paths": {
"common/*": [
"../../../src/common/*"
],
"@xterm/addon-unicode-graphemes": [
"../typings/addon-unicode-graphemes.d.ts"
]
},
"types": [
Expand Down
6 changes: 3 additions & 3 deletions addons/addon-unicode11/src/Unicode11Addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* UnicodeVersionProvider for V11.
*/

import { Terminal, ITerminalAddon } from '@xterm/xterm';
import type { Terminal, ITerminalAddon } from '@xterm/xterm';
import type { Unicode11Addon as IUnicode11Api } from '@xterm/addon-unicode11';
import { UnicodeV11 } from './UnicodeV11';


export class Unicode11Addon implements ITerminalAddon {
export class Unicode11Addon implements ITerminalAddon , IUnicode11Api {
public activate(terminal: Terminal): void {
terminal.unicode.register(new UnicodeV11());
}
Expand Down
3 changes: 3 additions & 0 deletions addons/addon-unicode11/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"paths": {
"common/*": [
"../../../src/common/*"
],
"@xterm/addon-unicode11": [
"../typings/addon-unicode11.d.ts"
]
},
"types": [
Expand Down
5 changes: 3 additions & 2 deletions addons/addon-web-links/src/WebLinksAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @license MIT
*/

import { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';
import type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';
import type { WebLinksAddon as IWebLinksApi } from '@xterm/addon-web-links';
import { ILinkProviderOptions, WebLinkProvider } from './WebLinkProvider';

// consider everthing starting with http:// or https://
Expand Down Expand Up @@ -34,7 +35,7 @@ function handleLink(event: MouseEvent, uri: string): void {
}
}

export class WebLinksAddon implements ITerminalAddon {
export class WebLinksAddon implements ITerminalAddon , IWebLinksApi {
private _terminal: Terminal | undefined;
private _linkProvider: IDisposable | undefined;

Expand Down
7 changes: 6 additions & 1 deletion addons/addon-web-links/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
"strict": true,
"types": [
"../../../node_modules/@types/mocha"
]
],
"paths": {
"@xterm/addon-web-links": [
"../typings/addon-web-links.d.ts"
]
}
},
"include": [
"./**/*",
Expand Down
5 changes: 3 additions & 2 deletions addons/addon-webgl/src/WebglAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
* @license MIT
*/

import type { ITerminalAddon, Terminal } from '@xterm/xterm';
import type { WebglAddon as IWebglApi } from '@xterm/addon-webgl';
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
import { ITerminal } from 'browser/Types';
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { getSafariVersion, isSafari } from 'common/Platform';
import { ICoreService, IDecorationService, ILogService, IOptionsService } from 'common/services/Services';
import { ITerminalAddon, Terminal } from '@xterm/xterm';
import { WebglRenderer } from './WebglRenderer';
import { setTraceLogger } from 'common/services/LogService';

export class WebglAddon extends Disposable implements ITerminalAddon {
export class WebglAddon extends Disposable implements ITerminalAddon , IWebglApi {
private _terminal?: Terminal;
private _renderer?: WebglRenderer;

Expand Down
3 changes: 3 additions & 0 deletions addons/addon-webgl/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
],
"browser/*": [
"../../../src/browser/*"
],
"@xterm/addon-webgl": [
"../typings/addon-webgl.d.ts"
]
},
"strict": true,
Expand Down

0 comments on commit e8da737

Please sign in to comment.