Skip to content

Commit 1fa919e

Browse files
committed
Upgraded xterm.js, added xterm-addon-fit without surfacing it
1 parent 5703fbf commit 1fa919e

File tree

6 files changed

+54
-40
lines changed

6 files changed

+54
-40
lines changed

client/apiclient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use strict"
1+
'use strict'
22

33
function apiclient (baseurl) {
44
baseurl = baseurl || ''

client/dialog.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function dialog (world) {
2626
const closebutton = document.createElement('div')
2727
closebutton.className = 'closebutton'
2828
closebutton.innerText = '✖'
29-
closebutton.onclick = function closeButtonClick(e) {
29+
closebutton.onclick = function closeButtonClick (e) {
3030
self.close()
3131
}
3232
headingsection.appendChild(closebutton)
@@ -42,30 +42,23 @@ function dialog (world) {
4242

4343
const modaldialog = new ModalDialog(world.game(), opts)
4444

45-
function open() {
46-
// const parentElement = world.options().parentElement
47-
// const width = parentElement.clientWidth * 0.8
48-
// const height = parentElement.clientHeight * 0.8
49-
50-
// box.style.width = width + 'px'
51-
// box.style.height = height + 'px'
52-
45+
function open () {
5346
modaldialog.open()
5447
}
5548

56-
function close() {
49+
function close () {
5750
clean()
5851
modaldialog.close()
5952
}
6053

61-
function heading(text) {
54+
function heading (text) {
6255
if (text) {
6356
headingelement.innerText = text
6457
}
6558
return headingelement.innerText
6659
}
6760

68-
function html(arg) {
61+
function html (arg) {
6962
if (arg) {
7063
clean()
7164
innerbox.innerHTML = arg
@@ -75,28 +68,28 @@ function dialog (world) {
7568
return innerbox.innerHTML
7669
}
7770

78-
function iframe(src, initialmessage, messagehandler) {
71+
function iframe (src, initialmessage, messagehandler) {
7972
clean()
8073

8174
frame = document.createElement('iframe')
8275
innerbox.appendChild(frame)
8376

8477
frame.src = src
8578
messageHandler = messagehandler
86-
frame.onload = function onDialogIframeLoaded() {
79+
frame.onload = function onDialogIframeLoaded () {
8780
window.addEventListener('message', messageHandler, false)
8881

8982
postMessage(initialmessage)
9083
}
9184
};
9285

93-
function postMessage(message) {
86+
function postMessage (message) {
9487
if (frame) {
9588
frame.contentWindow.postMessage(message, '*')
9689
}
9790
}
9891

99-
function clean() {
92+
function clean () {
10093
if (frame) {
10194
if (frame.parentElement) {
10295
frame.parentElement.removeChild(frame)

package-lock.json

Lines changed: 31 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"check-env": "node -e 'console.log(process.env)'",
1111
"test": "echo \"Error: no test specified\" && exit 1",
12-
"build-public": "copyfiles --up 1 public/css/* public/fonts/* public/js/* public/textures/* public/*.html out && copyfiles -f node_modules/xterm/dist/xterm.js out/js && copyfiles -f node_modules/xterm/dist/xterm.css out/css",
12+
"build-public": "copyfiles --up 1 public/css/* public/fonts/* public/js/* public/textures/* public/*.html out && copyfiles -f node_modules/@xterm/xterm/lib/xterm.js out/js && copyfiles -f node_modules/@xterm/addon-fit/lib/addon-fit.js out/js && copyfiles -f node_modules/@xterm/xterm/css/xterm.css out/css",
1313
"clean-public": "rimraf out/css out/fonts out/js/*dialog.js out/js/xterm.js out/textures out/*.html",
1414
"build-client-debug": "browserify --debug client/main.js -o out/js/client.js",
1515
"build-client-release": "browserify client/main.js -o out/js/client.js",
@@ -40,6 +40,8 @@
4040
},
4141
"homepage": "https://github.com/rajch/voxel-dockerclient#readme",
4242
"dependencies": {
43+
"@xterm/addon-fit": "^0.10.0",
44+
"@xterm/xterm": "^5.5.0",
4345
"shellwords": "^0.1.0",
4446
"voxel-console": "^1.0.1",
4547
"voxel-engine": "git+https://github.com/rajch/voxel-engine.git",
@@ -48,8 +50,7 @@
4850
"voxel-modal-dialog": "^1.0.1",
4951
"voxel-player": "^0.1.0",
5052
"voxel-plugins": "^0.5.0",
51-
"voxel-walk": "0.0.5",
52-
"xterm": "^3.8.1"
53+
"voxel-walk": "0.0.5"
5354
},
5455
"devDependencies": {
5556
"browserify": "^13.3.0",

public/js/terminaldialog.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99

1010
window.addEventListener('message', onMessageReceived, false)
1111

12-
function ab2str (buf) {
13-
return String.fromCharCode.apply(null, new Uint8Array(buf))
14-
}
15-
1612
function onMessageReceived (event) {
1713
sourceWindow = event.source
1814
eventOrigin = event.origin
@@ -28,7 +24,12 @@
2824
cols: 80,
2925
rows: 26
3026
})
27+
28+
const fitaddon = new FitAddon.FitAddon()
29+
3130
terminal.open(document.getElementById('terminal-container'))
31+
terminal.loadAddon(fitaddon)
32+
fitaddon.fit()
3233

3334
const wsUri = 'ws://' + window.location.host + '/websocket/containers/' + containername +
3435
'/attach/ws?logs=0&stderr=1&stdout=1&stream=1&stdin=1'
@@ -47,7 +48,8 @@
4748

4849
socket.onmessage = function onMessage (evt) {
4950
if (evt.data instanceof ArrayBuffer) {
50-
terminal.write(ab2str(evt.data))
51+
const binarydata = new Uint8Array(evt.data)
52+
terminal.write(binarydata)
5153
} else {
5254
terminal.write(evt.data)
5355
}
@@ -58,7 +60,7 @@
5860
errorcreated = true
5961
}
6062

61-
terminal.on('data', function (data) {
63+
terminal.onData(function terminalOnData (data) {
6264
socket.send(data)
6365
})
6466

public/terminaldialog.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<link rel="stylesheet" href="css/xterm.css">
55
<script src="js/xterm.js"></script>
6+
<script src="js/addon-fit.js"></script>
67
<style>
78
body {
89
margin: 0;

0 commit comments

Comments
 (0)