committed by
GitHub
15 changed files with 964 additions and 328 deletions
@ -1,5 +1,5 @@ |
|||
caches.keys().then((cacheNames) => { |
|||
cacheNames.forEach((cacheName) => { |
|||
caches.keys().then(cacheNames => { |
|||
cacheNames.forEach(cacheName => { |
|||
caches.delete(cacheName); |
|||
}); |
|||
}); |
|||
|
@ -1,5 +0,0 @@ |
|||
import { Terminal } from 'xterm'; |
|||
|
|||
export class Term extends Terminal { |
|||
resizeTerm(): void {} |
|||
} |
@ -1,29 +1,36 @@ |
|||
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 { Terminal } from 'xterm'; |
|||
import { FitAddon } from 'xterm-addon-fit'; |
|||
import { WebLinksAddon } from 'xterm-addon-web-links'; |
|||
import { configureTerm, shouldFitTerm } from './term/confiruragtion.js'; |
|||
import { terminal as termElement } from '../shared/elements.js'; |
|||
|
|||
export class Term extends Terminal { |
|||
socket: typeof Socket; |
|||
fitAddon: FitAddon; |
|||
constructor(socket: typeof Socket) { |
|||
super(); |
|||
this.socket = socket; |
|||
this.fitAddon = new FitAddon(); |
|||
this.loadAddon(this.fitAddon); |
|||
this.loadAddon(new WebLinksAddon()); |
|||
} |
|||
|
|||
resizeTerm(): void { |
|||
this.refresh(0, this.rows - 1); |
|||
if (shouldFitTerm()) this.fitAddon.fit(); |
|||
this.socket.emit('resize', { cols: this.cols, rows: this.rows }); |
|||
} |
|||
} |
|||
|
|||
export function terminal(socket: typeof Socket): Term | undefined { |
|||
const term = new Terminal() as Term; |
|||
const term = new Term(socket) as Term; |
|||
if (_.isNull(termElement)) return undefined; |
|||
const webLinksAddon = new WebLinksAddon(); |
|||
term.loadAddon(webLinksAddon); |
|||
const fitAddon = new FitAddon(); |
|||
term.loadAddon(fitAddon); |
|||
term.open(termElement); |
|||
term.resizeTerm = () => { |
|||
term.refresh(0, term.rows - 1); |
|||
if (shouldFitTerm()) fitAddon.fit(); |
|||
socket.emit('resize', { cols: term.cols, rows: term.rows }); |
|||
}; |
|||
configureTerm(term); |
|||
window.onresize = term.resizeTerm; |
|||
(window as any).wetty_term = term; |
|||
|
|||
return term; |
|||
} |
|||
|
File diff suppressed because it is too large
Loading…
Reference in new issue