-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
34 lines (34 loc) · 1.57 KB
/
index.html
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
<html>
<head>
<title>bash</title>
<link rel="stylesheet" href="/node_modules/xterm/dist/xterm.css" />
<link rel="stylesheet" href="/node_modules/xterm/dist/addons/fullscreen/fullscreen.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
<script src="/node_modules/xterm/dist/xterm.js"></script>
<script src="/node_modules/xterm/dist/addons/fit/fit.js"></script>
<script src="/node_modules/xterm/dist/addons/attach/attach.js"></script>
</head>
<body>
<div id="terminal"></div>
<script>
// No idea what these are about. Just copied them from the demo code
Terminal.applyAddon(attach);
Terminal.applyAddon(fit);
// The terminal
const term = new Terminal();
// This kinda makes sense
const container = document.getElementById('terminal');
term.open(container);
// Open the websocket connection to the backend
const protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://';
const port = location.port ? `:${location.port}` : '';
const challenge = window.location.hash.substr(1) || 'move-commit-from-branch-a-to-b';
const socketUrl = `${protocol}${location.hostname}${port}/${challenge}`;
const socket = new WebSocket(socketUrl);
// Attach the socket to the terminal
socket.onopen = (ev) => { term.attach(socket); };
// Not going to worry about close/error for the websocket
</script>
</body>
</html>