MCPcopy
hub / github.com/xtermjs/xterm.js / initAddons

Function initAddons

demo/client.ts:616–717  ·  view source on GitHub ↗
(term: Terminal)

Source from the content-addressed store, hash-verified

614}
615
616function initAddons(term: Terminal): void {
617 const fragment = document.createDocumentFragment();
618 Object.keys(addons).forEach((name: AddonType) => {
619 const addon = addons[name];
620 const checkbox = document.createElement('input') as HTMLInputElement;
621 checkbox.type = 'checkbox';
622 checkbox.checked = !!addon.instance;
623 if (!addon.canChange) {
624 checkbox.disabled = true;
625 }
626 if (name === 'unicode11' && checkbox.checked) {
627 term.unicode.activeVersion = '11';
628 }
629 if (name === 'unicodeGraphemes' && checkbox.checked) {
630 term.unicode.activeVersion = '15-graphemes';
631 }
632 if (name === 'search' && checkbox.checked) {
633 addons[name].instance.onDidChangeResults(e => updateFindResults(e));
634 }
635 addDomListener(checkbox, 'change', () => {
636 if (name === 'image') {
637 if (checkbox.checked) {
638 const ctorOptionsJson = document.querySelector<HTMLTextAreaElement>('#image-options').value;
639 addon.instance = ctorOptionsJson
640 ? new addons[name].ctor(JSON.parse(ctorOptionsJson))
641 : new addons[name].ctor();
642 term.loadAddon(addon.instance);
643 } else {
644 addon.instance!.dispose();
645 addon.instance = undefined;
646 }
647 return;
648 }
649 function postInitWebgl(): void {
650 setTimeout(() => {
651 setTextureAtlas(addons.webgl.instance.textureAtlas);
652 addons.webgl.instance.onChangeTextureAtlas(e => setTextureAtlas(e));
653 addons.webgl.instance.onAddTextureAtlasCanvas(e => appendTextureAtlas(e));
654 }, 500);
655 }
656 function preDisposeWebgl(): void {
657 if (addons.webgl.instance.textureAtlas) {
658 addons.webgl.instance.textureAtlas.remove();
659 }
660 }
661 if (checkbox.checked) {
662 // HACK: Manually remove addons that cannot be changes
663 addon.instance = new (addon as IDemoAddon<Exclude<AddonType, 'attach'>>).ctor();
664 try {
665 term.loadAddon(addon.instance);
666 if (name === 'webgl') {
667 postInitWebgl();
668 } else if (name === 'unicode11') {
669 term.unicode.activeVersion = '11';
670 } else if (name === 'unicodeGraphemes') {
671 term.unicode.activeVersion = '15-graphemes';
672 } else if (name === 'search') {
673 addons[name].instance.onDidChangeResults(e => updateFindResults(e));

Callers 2

runRealTerminalFunction · 0.85
runFakeTerminalFunction · 0.85

Calls 12

updateFindResultsFunction · 0.85
addDomListenerFunction · 0.85
postInitWebglFunction · 0.85
preDisposeWebglFunction · 0.85
appendChildMethod · 0.80
forEachMethod · 0.65
parseMethod · 0.65
disposeMethod · 0.65
keysMethod · 0.45
onDidChangeResultsMethod · 0.45
loadAddonMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected