socktop-webterm/templates/term.html

54 lines
1.5 KiB
HTML
Raw Normal View History

2019-01-03 17:15:07 +00:00
<!doctype html>
2019-03-04 07:24:56 +00:00
<!--
Copyright (c) 2019 Fabian Freyer <fabian.freyer@physik.tu-berlin.de>
SPDX-License-Identifier: BSD-3-Clause
-->
2019-01-03 17:15:07 +00:00
<html>
<head>
2019-03-29 13:49:01 +00:00
<meta charset="UTF-8" />
<link rel="stylesheet" href="{{ static_path|safe }}/xterm/dist/xterm.css" />
<script src="{{ static_path|safe }}/xterm/dist/xterm.js"></script>
<script src="{{ static_path|safe }}/xterm/dist/addons/attach/attach.js"></script>
<script src="{{ static_path|safe }}/xterm/dist/addons/terminado/terminado.js"></script>
<script src="{{ static_path|safe }}/xterm/dist/addons/fit/fit.js"></script>
<script src="{{ static_path|safe }}/xterm/dist/addons/search/search.js"></script>
2019-01-03 17:15:07 +00:00
<style>
body {
margin: 0;
}
html, body, #terminal {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="terminal"></div>
<script>
Terminal.applyAddon(terminado);
2019-01-03 17:15:07 +00:00
Terminal.applyAddon(fit);
Terminal.applyAddon(search);
var term = new Terminal();
var protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://';
var socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + "{{ websocket_path|safe }}";
2019-01-03 17:15:07 +00:00
var sock = new WebSocket(socketURL);
sock.addEventListener('open', function() {
term.terminadoAttach(sock);
2019-01-03 17:15:07 +00:00
term.fit();
});
2019-03-29 14:57:11 +00:00
sock.addEventListener('close', function() {
term.writeln("");
term.writeln("Connection closed.");
term.terminadoDetach(sock);
});
2019-01-03 17:15:07 +00:00
term.open(document.getElementById('terminal'));
window.onresize = function() {term.fit();};
</script>
</body>
</html>