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

View File

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

View File

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

View File

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