webterm 0.2.0

xterm.js - based webterminal
<!doctype html>
<!--
Copyright (c) 2019 Fabian Freyer <fabian.freyer@physik.tu-berlin.de>
SPDX-License-Identifier: BSD-3-Clause
-->

<html>
	<head>
		<meta charset="UTF-8" />
		<link rel="stylesheet" href="{{ static_path }}/xterm/dist/xterm.css" />
		<script src="{{ static_path }}/xterm/dist/xterm.js"></script>
		<script src="{{ static_path }}/xterm/dist/addons/attach/attach.js"></script>
		<script src="{{ static_path }}/xterm/dist/addons/terminado/terminado.js"></script>
		<script src="{{ static_path }}/xterm/dist/addons/fit/fit.js"></script>
		<script src="{{ static_path }}/xterm/dist/addons/search/search.js"></script>
<style>
	body {
		margin: 0;
	}
	html, body, #terminal {
		width: 100%;
		height: 100%;
	}
</style>
	</head>
	<body>
		<div id="terminal"></div>
		<script>
			Terminal.applyAddon(terminado);
			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 }}";
			var sock = new WebSocket(socketURL);

			sock.addEventListener('open', function() {
				term.terminadoAttach(sock);
				term.fit();
			});

			sock.addEventListener('close', function() {
				term.writeln("");
				term.writeln("Connection closed.");
				term.terminadoDetach(sock);
			});

			term.open(document.getElementById('terminal'));
			window.onresize = function() {term.fit();};
		</script>
	</body>
</html>