-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeployment.ts
More file actions
63 lines (51 loc) · 1.55 KB
/
deployment.ts
File metadata and controls
63 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Shell } from '@jupyterlite/cockle'
import { FitAddon } from '@xterm/addon-fit'
import { Terminal } from '@xterm/xterm'
import { IDeployment } from './defs'
export class Deployment {
constructor(options: IDeployment.IOptions) {
this._targetDiv = options.targetDiv;
const termOptions = {
rows: 50,
theme: {
foreground: "ivory",
background: "#111111",
cursor: "silver"
},
}
this._term = new Terminal(termOptions)
this._fitAddon = new FitAddon()
this._term.loadAddon(this._fitAddon)
const { baseUrl, browsingContextId, shellManager } = options;
this._shell = new Shell({
browsingContextId,
baseUrl,
wasmBaseUrl: baseUrl,
shellManager,
outputCallback: this.outputCallback.bind(this),
})
}
async start(): Promise<void> {
this._term!.onResize(async (arg: any) => await this.onResize(arg))
this._term!.onData(async (data: string) => await this.onData(data))
const resizeObserver = new ResizeObserver((entries) => {
this._fitAddon!.fit()
})
this._term!.open(this._targetDiv)
await this._shell.start()
resizeObserver.observe(this._targetDiv)
}
async onData(data: string): Promise<void> {
await this._shell.input(data)
}
async onResize(arg: any): Promise<void> {
await this._shell.setSize(arg.rows, arg.cols)
}
private outputCallback(text: string): void {
this._term!.write(text)
}
private _targetDiv: HTMLElement;
private _term: Terminal
private _fitAddon: FitAddon
private _shell: Shell
}