-
Notifications
You must be signed in to change notification settings - Fork 3
/
frontend.html
34 lines (29 loc) · 1 KB
/
frontend.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/xterm.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/xterm.min.css">
</head>
<body>
<div class="terminal" style="width: min-content; font-size: 12px;"></div>
<script>
const socket_url = `${location.protocol === 'http:' ? 'ws:' : 'wss:'}//${location.host}${location.pathname}`
const socket = new WebSocket(socket_url);
socket.onopen =() => {
window.term = new Terminal({
cols: 80,
rows: 24,
fontFamily: 'SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace',
});
term.onData(data => socket.send(data));
term.open(document.querySelector('.terminal'));
socket.onmessage = (message) => {
term.write(message.data);
}
};
</script>
</body>
</html>