-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathxterm_profile.js
More file actions
35 lines (29 loc) · 775 Bytes
/
xterm_profile.js
File metadata and controls
35 lines (29 loc) · 775 Bytes
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
Terminal.applyAddon(fit)
const term = new Terminal({
cols: 80,
rows: 24
})
const ws = new WebSocket(`ws://${location.hostname}:8999`)
ws.addEventListener('open', function() {
console.info('WebSocket connected')
})
ws.addEventListener('message', function(event) {
console.debug('Message from server ', event.data)
try {
let output = JSON.parse(event.data)
term.write(output.output)
} catch (e) {
console.error(e)
}
})
term.open(document.getElementById('terminal'))
term.on('data', data => ws.send(JSON.stringify({ input: data })))
window.addEventListener('resize', () => {
term.fit()
})
term.fit()
term.on('resize', size => {
console.debug('resize')
let resizer = JSON.stringify({ resizer: [size.cols, size.rows] })
ws.send(resizer)
})