Add xtermjs Canvas (#1756)

This commit is contained in:
Charles 2025-09-28 15:17:02 -04:00 committed by GitHub
parent 81178f81b4
commit ec5fd3262a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 2 deletions

View File

@ -17,6 +17,7 @@
"vite": "6.2.6" "vite": "6.2.6"
}, },
"dependencies": { "dependencies": {
"@xterm/addon-canvas": "^0.7.0",
"@xterm/addon-fit": "^0.10.0", "@xterm/addon-fit": "^0.10.0",
"@xterm/addon-search": "^0.15.0", "@xterm/addon-search": "^0.15.0",
"@xterm/addon-web-links": "^0.11.0", "@xterm/addon-web-links": "^0.11.0",

View File

@ -3,9 +3,11 @@ import { FitAddon } from '@xterm/addon-fit';
import { WebLinksAddon } from '@xterm/addon-web-links'; import { WebLinksAddon } from '@xterm/addon-web-links';
import { SearchAddon } from '@xterm/addon-search'; import { SearchAddon } from '@xterm/addon-search';
import { SearchBarAddon } from 'xterm-addon-search-bar'; import { SearchBarAddon } from 'xterm-addon-search-bar';
import { CanvasAddon } from '@xterm/addon-canvas';
window.Xterm = { window.Xterm = {
Terminal, Terminal,
CanvasAddon,
FitAddon, FitAddon,
WebLinksAddon, WebLinksAddon,
SearchAddon, SearchAddon,

View File

@ -76,17 +76,19 @@
theme: theme theme: theme
}; };
const { Terminal, FitAddon, WebLinksAddon, SearchAddon, SearchBarAddon } = window.Xterm; const { Terminal, FitAddon, WebLinksAddon, SearchAddon, SearchBarAddon, CanvasAddon } = window.Xterm;
const terminal = new Terminal(options); const terminal = new Terminal(options);
const fitAddon = new FitAddon(); const fitAddon = new FitAddon();
const webLinksAddon = new WebLinksAddon(); const webLinksAddon = new WebLinksAddon();
const searchAddon = new SearchAddon(); const searchAddon = new SearchAddon();
const searchAddonBar = new SearchBarAddon({ searchAddon }); const searchAddonBar = new SearchBarAddon({ searchAddon });
const canvasAddon = new CanvasAddon();
terminal.loadAddon(fitAddon); terminal.loadAddon(fitAddon);
terminal.loadAddon(webLinksAddon); terminal.loadAddon(webLinksAddon);
terminal.loadAddon(searchAddon); terminal.loadAddon(searchAddon);
terminal.loadAddon(searchAddonBar); terminal.loadAddon(searchAddonBar);
terminal.loadAddon(canvasAddon);
terminal.open(document.getElementById('terminal')); terminal.open(document.getElementById('terminal'));
@ -102,7 +104,7 @@
terminal.attachCustomKeyEventHandler((event) => { terminal.attachCustomKeyEventHandler((event) => {
if ((event.ctrlKey || event.metaKey) && event.key === 'c') { if ((event.ctrlKey || event.metaKey) && event.key === 'c') {
navigator.clipboard.writeText(terminal.getSelection()) navigator.clipboard.writeText(terminal.getSelection());
return false; return false;
} else if ((event.ctrlKey || event.metaKey) && event.key === 'f') { } else if ((event.ctrlKey || event.metaKey) && event.key === 'f') {
event.preventDefault(); event.preventDefault();

View File

@ -415,6 +415,11 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8"
integrity sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ== integrity sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==
"@xterm/addon-canvas@^0.7.0":
version "0.7.0"
resolved "https://registry.yarnpkg.com/@xterm/addon-canvas/-/addon-canvas-0.7.0.tgz#d3a3835f3634e0106e108661315ae14da23e8dd7"
integrity sha512-LF5LYcfvefJuJ7QotNRdRSPc9YASAVDeoT5uyXS/nZshZXjYplGXRECBGiznwvhNL2I8bq1Lf5MzRwstsYQ2Iw==
"@xterm/addon-fit@^0.10.0": "@xterm/addon-fit@^0.10.0":
version "0.10.0" version "0.10.0"
resolved "https://registry.yarnpkg.com/@xterm/addon-fit/-/addon-fit-0.10.0.tgz#bebf87fadd74e3af30fdcdeef47030e2592c6f55" resolved "https://registry.yarnpkg.com/@xterm/addon-fit/-/addon-fit-0.10.0.tgz#bebf87fadd74e3af30fdcdeef47030e2592c6f55"