This commit is contained in:
Zhi Wang 2022-01-12 07:33:06 -05:00
parent e9241e7a6e
commit cd895cfef7
5 changed files with 12 additions and 7 deletions

View File

@ -46,6 +46,10 @@ window (xterm.js) and create a websocket with the server, which relays the data
The program has been tested on Linux, WSL2, Raspberry Pi 3B (Debian), and MacOSX using Google Chrome, Firefox, and Safari.
## Known bug
WiTTY has some display/encoding issues on macOS with Firefox, especially for zsh. Safari works fine though.
## An Screencast <sub>featuring an older version of WiTTY</sub>
Here is a screencast for sshing into Raspberry Pi running

View File

@ -1,14 +1,14 @@
#terminal {
display: flex;
justify-content: center;
margin: 20px 0 50px;
margin: 10px 0 20px;
}
#terminal #terminal_view {
padding: 10px 20px;
border-radius: 6px;
background-color: #282a36;
max-width: 860px;
max-width: 880px;
}
.xterm-viewport.xterm-viewport {

View File

@ -32,7 +32,7 @@ function createTerminal(path) {
});
term.open(document.getElementById('terminal_view'));
term.resize(122, 37);
term.resize(124, 37);
const weblinksAddon = new WebLinksAddon.WebLinksAddon();
term.loadAddon(weblinksAddon);
@ -45,6 +45,7 @@ function createTerminal(path) {
// create the websocket and connect to the server
const ws_uri = "wss://" + window.location.host + path;
const socket = new WebSocket(ws_uri);
socket.binaryType = "arraybuffer";
const attachAddon = new AttachAddon.AttachAddon(socket);
term.loadAddon(attachAddon);

View File

@ -28,7 +28,7 @@
</div>
</div>
<div style="margin-top: 7em;">
<div style="margin-top: 5em;">
<div id="terminal">
<div id="terminal_view"></div>
</div>
@ -39,7 +39,7 @@
// print something to test output and scroll
var str = [
' ┌────────────────────────────────────────────────────────────────────────────┐\n',
' │ Powered by \u001b[32;1mGo, Gin, websocket, pty, and https://xtermjs.org\x1b[0m │\n',
' │ Powered by \u001b[32;1mGo, Gin, websocket, pty, and xterm.js\x1b[0m │\n',
' └────────────────────────────────────────────────────────────────────────────┘\n',
''
].join('');

View File

@ -209,7 +209,7 @@ out:
// We could add ws to viewers as well (then we can use io.MultiWriter),
// but we want to handle errors differently
tc.ws.SetWriteDeadline(time.Now().Add(writeWait))
if err := tc.ws.WriteMessage(websocket.TextMessage, buf); err != nil {
if err := tc.ws.WriteMessage(websocket.BinaryMessage, buf); err != nil {
log.Println("Failed to write message: ", err)
break out
}
@ -222,7 +222,7 @@ out:
// if the viewer exits, we will just ignore the error
w.SetWriteDeadline(time.Now().Add(viewWait))
if err := w.WriteMessage(websocket.TextMessage, buf); err != nil {
if err := w.WriteMessage(websocket.BinaryMessage, buf); err != nil {
log.Println("Failed to write message to viewer: ", err)
viewers[i] = nil