This commit is contained in:
Zhi Wang 2022-01-04 21:21:21 -05:00
parent eedf025867
commit aa283ec188
4 changed files with 73 additions and 70 deletions

View File

@ -12,11 +12,12 @@
<script src="xterm-addon-attach.js"></script>
<script src="xterm-addon-fit.js"></script>
<script src="xterm-addon-web-links.js"></script>
<script src="main.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" href="xterm.css" />
<link rel="stylesheet" href="main.css" />
<title>Websocket Terminal</title>
</head>
@ -50,9 +51,6 @@
].join('\n\r');
term.writeln(str);
term.writeln(str);
term.writeln(str);
</script>
</body>

View File

@ -14,12 +14,15 @@
.xterm-viewport.xterm-viewport {
scrollbar-width: thin;
}
.xterm-viewport::-webkit-scrollbar {
width: 10px;
}
.xterm-viewport::-webkit-scrollbar-track {
opacity: 0;
}
.xterm-viewport::-webkit-scrollbar-thumb {
min-height: 20px;
background-color: #ffffff20;

View File

@ -1,5 +1,6 @@
function createTerminal() {
// vscode-snazzy https://github.com/Tyriar/vscode-snazzy
// copied from xterm.js website
var baseTheme = {
foreground: '#eff0eb',
background: '#282a36',
@ -26,13 +27,14 @@ function createTerminal() {
fontFamily: `'Fira Code', monospace`,
fontSize: 12,
theme: baseTheme,
convertEol: true,
});
term.open(document.getElementById('terminal_view'));
term.resize(120, 36);
const weblinksAddon = new WebLinksAddon.WebLinksAddon();
term.loadAddon(weblinksAddon)
term.loadAddon(weblinksAddon);
// fit the xterm viewpoint to parent element
const fitAddon = new FitAddon.FitAddon();
@ -40,10 +42,9 @@ function createTerminal() {
fitAddon.fit();
// create the websocket and connect to the server
const ws_uri = "ws://" + window.location.host + "/ws"
const socket = new WebSocket(ws_uri)
console.log("Attempting to connect to" + ws_uri);
const attachAddon = new AttachAddon.AttachAddon(socket)
const ws_uri = "ws://" + window.location.host + "/ws";
const socket = new WebSocket(ws_uri);
const attachAddon = new AttachAddon.AttachAddon(socket);
term.loadAddon(attachAddon);
return term;

View File

@ -2,9 +2,10 @@ package main
import (
"fmt"
"strings"
"net/http"
"net/url"
"strings"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)