Move more handlers out, addon types into shared file

This commit is contained in:
Daniel Imms
2025-12-26 04:09:24 -08:00
parent 02e9e56eef
commit b82e8f345f
3 changed files with 66 additions and 43 deletions
+3 -40
View File
@@ -37,7 +37,7 @@ import { WebglAddon } from '@xterm/addon-webgl';
import { Unicode11Addon } from '@xterm/addon-unicode11';
import { UnicodeGraphemesAddon } from '@xterm/addon-unicode-graphemes';
import { writeUnicodeTable } from './unicodeTable';
import { AddonCollection, type AddonType, type IDemoAddon } from './types';
export interface IWindowWithTerminal extends Window {
term: typeof Terminal;
@@ -69,44 +69,7 @@ let optionsWindow: OptionsWindow;
let styleWindow: StyleWindow;
let vtWindow: VtWindow;
type AddonType = 'attach' | 'clipboard' | 'fit' | 'image' | 'progress' | 'search' | 'serialize' | 'unicode11' | 'unicodeGraphemes' | 'webLinks' | 'webgl' | 'ligatures';
interface IDemoAddon<T extends AddonType> {
name: T;
canChange: boolean;
ctor: (
T extends 'attach' ? typeof AttachAddon :
T extends 'clipboard' ? typeof ClipboardAddon :
T extends 'fit' ? typeof FitAddon :
T extends 'image' ? typeof ImageAddonType :
T extends 'ligatures' ? typeof LigaturesAddon :
T extends 'progress' ? typeof ProgressAddon :
T extends 'search' ? typeof SearchAddon :
T extends 'serialize' ? typeof SerializeAddon :
T extends 'webLinks' ? typeof WebLinksAddon :
T extends 'unicode11' ? typeof Unicode11Addon :
T extends 'unicodeGraphemes' ? typeof UnicodeGraphemesAddon :
T extends 'webgl' ? typeof WebglAddon :
never
);
instance?: (
T extends 'attach' ? AttachAddon :
T extends 'clipboard' ? ClipboardAddon :
T extends 'fit' ? FitAddon :
T extends 'image' ? ImageAddonType :
T extends 'ligatures' ? LigaturesAddon :
T extends 'progress' ? ProgressAddon :
T extends 'search' ? SearchAddon :
T extends 'serialize' ? SerializeAddon :
T extends 'webLinks' ? WebLinksAddon :
T extends 'unicode11' ? Unicode11Addon :
T extends 'unicodeGraphemes' ? UnicodeGraphemesAddon :
T extends 'webgl' ? WebglAddon :
never
);
}
const addons: { [T in AddonType]: IDemoAddon<T> } = {
const addons: AddonCollection = {
attach: { name: 'attach', ctor: AttachAddon, canChange: false },
clipboard: { name: 'clipboard', ctor: ClipboardAddon, canChange: true },
fit: { name: 'fit', ctor: FitAddon, canChange: false },
@@ -257,7 +220,7 @@ if (document.location.pathname === '/test') {
const styleWindow = controlBar.registerWindow(new StyleWindow());
paddingElement = styleWindow.paddingElement;
controlBar.registerWindow(optionsWindow);
controlBar.registerWindow(new TestWindow(typedTerm));
controlBar.registerWindow(new TestWindow(typedTerm, addons));
vtWindow = new VtWindow();
controlBar.registerWindow(vtWindow);
vtWindow.initTerminal(term);
+5 -3
View File
@@ -8,14 +8,16 @@
import { writeUnicodeTable } from 'unicodeTable';
import type { IControlWindow } from '../controlBar';
import type { Terminal } from '@xterm/xterm';
import type { AddonCollection } from 'types';
export class TestWindow implements IControlWindow {
public readonly id = 'test';
public readonly label = 'Test';
private _printCjkButton: HTMLButtonElement;
constructor(private readonly _terminal: Terminal) {
constructor(
private readonly _terminal: Terminal,
private readonly _addons: AddonCollection
) {
}
public build(container: HTMLElement): void {
+58
View File
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
* @license MIT
*
* This file is the entry point for browserify.
*/
import type { ImageAddon } from '@xterm/addon-image';
import type { AttachAddon } from '@xterm/addon-attach';
import type { ClipboardAddon } from '@xterm/addon-clipboard';
import type { FitAddon } from '@xterm/addon-fit';
import type { LigaturesAddon } from '@xterm/addon-ligatures';
import type { ProgressAddon } from '@xterm/addon-progress';
import type { SearchAddon } from '@xterm/addon-search';
import type { SerializeAddon } from '@xterm/addon-serialize';
import type { UnicodeGraphemesAddon } from '@xterm/addon-unicode-graphemes';
import type { Unicode11Addon } from '@xterm/addon-unicode11';
import type { WebLinksAddon } from '@xterm/addon-web-links';
import type { WebglAddon } from '@xterm/addon-webgl';
export type AddonType = 'attach' | 'clipboard' | 'fit' | 'image' | 'progress' | 'search' | 'serialize' | 'unicode11' | 'unicodeGraphemes' | 'webLinks' | 'webgl' | 'ligatures';
export interface IDemoAddon<T extends AddonType> {
name: T;
canChange: boolean;
ctor: (
T extends 'attach' ? typeof AttachAddon :
T extends 'clipboard' ? typeof ClipboardAddon :
T extends 'fit' ? typeof FitAddon :
T extends 'image' ? typeof ImageAddon :
T extends 'ligatures' ? typeof LigaturesAddon :
T extends 'progress' ? typeof ProgressAddon :
T extends 'search' ? typeof SearchAddon :
T extends 'serialize' ? typeof SerializeAddon :
T extends 'webLinks' ? typeof WebLinksAddon :
T extends 'unicode11' ? typeof Unicode11Addon :
T extends 'unicodeGraphemes' ? typeof UnicodeGraphemesAddon :
T extends 'webgl' ? typeof WebglAddon :
never
);
instance?: (
T extends 'attach' ? AttachAddon :
T extends 'clipboard' ? ClipboardAddon :
T extends 'fit' ? FitAddon :
T extends 'image' ? ImageAddon :
T extends 'ligatures' ? LigaturesAddon :
T extends 'progress' ? ProgressAddon :
T extends 'search' ? SearchAddon :
T extends 'serialize' ? SerializeAddon :
T extends 'webLinks' ? WebLinksAddon :
T extends 'unicode11' ? Unicode11Addon :
T extends 'unicodeGraphemes' ? UnicodeGraphemesAddon :
T extends 'webgl' ? WebglAddon :
never
);
}
export type AddonCollection = { [T in AddonType]: IDemoAddon<T> };