You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
880 B
27 lines
880 B
import type { Socket } from 'socket.io-client';
|
|
import _ from 'lodash';
|
|
import { WebLinksAddon } from 'xterm-addon-web-links';
|
|
import { FitAddon } from 'xterm-addon-fit';
|
|
import { Terminal } from 'xterm';
|
|
|
|
import type { Term } from './shared/type';
|
|
import { configureTerm } from './term/confiruragtion.js';
|
|
import { terminal as termElement } from '../shared/elements.js';
|
|
|
|
export function terminal(socket: typeof Socket): Term | undefined {
|
|
const term = new Terminal() as Term;
|
|
if (_.isNull(termElement)) return;
|
|
const webLinksAddon = new WebLinksAddon();
|
|
term.loadAddon(webLinksAddon);
|
|
const fitAddon = new FitAddon();
|
|
term.loadAddon(fitAddon);
|
|
term.open(termElement);
|
|
term.resizeTerm = () => {
|
|
fitAddon.fit();
|
|
socket.emit('resize', { cols: term.cols, rows: term.rows });
|
|
};
|
|
configureTerm(term);
|
|
window.onresize = term.resizeTerm;
|
|
|
|
return term;
|
|
}
|
|
|