fix: vim full screen
continuous-integration/drone/tag Build is passing Details

master v0.1.2
Evan Chen 2021-11-17 12:28:47 +08:00
parent a3b2e0026d
commit a5e826e284
5 changed files with 23 additions and 19 deletions

View File

@ -57,7 +57,10 @@ func main() {
Addr: flagAddr,
Handler: Middleware(g),
}
server.ListenAndServe()
err := server.ListenAndServe()
if err != nil {
panic(err)
}
}
func Middleware(next http.Handler) http.Handler {

View File

@ -9,7 +9,6 @@ import (
"os"
"os/exec"
"strings"
"sync"
"time"
"github.com/creack/pty"
@ -78,7 +77,6 @@ func New() *GTerm {
log.Info("current connections: ", cons)
time.Sleep(5 * time.Minute)
}
}()
return &GTerm{
AppName: "GTERM",
@ -165,8 +163,7 @@ func (g *GTerm) WS(w http.ResponseWriter, r *http.Request) {
}()
var connectionClosed bool
var waiter sync.WaitGroup
waiter.Add(1)
waiter := make(chan struct{}, 1)
// this is a keep-alive loop that ensures connection does not hang-up itself
lastPongTime := time.Now()
@ -183,7 +180,7 @@ func (g *GTerm) WS(w http.ResponseWriter, r *http.Request) {
time.Sleep(g.Timeout / 2)
if time.Since(lastPongTime) > g.Timeout {
l.Warn("failed to get response from ping, triggering disconnect now...")
waiter.Done()
waiter <- struct{}{}
return
}
l.Debug("received response from ping successfully")
@ -198,7 +195,7 @@ func (g *GTerm) WS(w http.ResponseWriter, r *http.Request) {
// can be terminated - this frees up memory so the service doesn't get
// overloaded
if errorCounter > g.ErrorLimit {
waiter.Done()
waiter <- struct{}{}
break
}
buffer := make([]byte, g.BufferSize)
@ -208,7 +205,7 @@ func (g *GTerm) WS(w http.ResponseWriter, r *http.Request) {
if err := conn.WriteMessage(websocket.TextMessage, []byte("bye!")); err != nil {
l.Warn("failed to send termination message from tty to xterm.js: ", err)
}
waiter.Done()
waiter <- struct{}{}
return
}
if err := conn.WriteMessage(websocket.BinaryMessage, buffer[:readLength]); err != nil {
@ -276,7 +273,8 @@ func (g *GTerm) WS(w http.ResponseWriter, r *http.Request) {
}
}()
waiter.Wait()
<-waiter
close(waiter)
l.Info("closing connection...")
connectionClosed = true
}

19
main.js
View File

@ -8,13 +8,13 @@ import 'xterm/css/xterm.css'
(function() {
const terminal = new Terminal({
screenKeys: true,
useStyle: true,
cursorBlink: true,
fullscreenWin: true,
maximizeWin: true,
screenReaderMode: true,
cols: 128,
// screenKeys: true,
// useStyle: true,
// cursorBlink: true,
// fullscreenWin: true,
// maximizeWin: true,
// screenReaderMode: true,
// cols: 128,
});
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
@ -29,7 +29,6 @@ import 'xterm/css/xterm.css'
const serializeAddon = new SerializeAddon();
terminal.loadAddon(serializeAddon);
terminal.open(document.getElementById("terminal"));
fitAddon.fit();
ws.onclose = function(event) {
console.log(event);
terminal.write('\r\n\nconnection has been terminated from the server-side (hit refresh to restart)\n')
@ -39,6 +38,9 @@ import 'xterm/css/xterm.css'
terminal._initialized = true;
terminal.focus();
setTimeout(function() {fitAddon.fit()});
document.addEventListener('keypress',(e)=>{
e.preventDefault();
})
terminal.onResize(function(event) {
var rows = event.rows;
var cols = event.cols;
@ -54,5 +56,6 @@ import 'xterm/css/xterm.css'
console.log("resize")
fitAddon.fit();
};
fitAddon.fit();
};
})();

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<!DOCTYPE html><html><head><link rel="stylesheet" href="index.6999253a.css"><title>{{.AppName}}</title><style>body::-webkit-scrollbar,div::-webkit-scrollbar,html::-webkit-scrollbar{display:none;width:0}body,html{margin:0;overflow:hidden;padding:0}div#terminal{height:100%;left:0;position:absolute;top:0;width:100%}div#terminal div{height:100%}.xterm-screen,.xterm-viewport{height:100%;margin:0;padding:0}</style></head><body> <div id="terminal"></div> <script type="module" src="index.b28ecb90.js"></script> </body></html>
<!DOCTYPE html><html><head><link rel="stylesheet" href="index.6999253a.css"><title>{{.AppName}}</title><style>body::-webkit-scrollbar,div::-webkit-scrollbar,html::-webkit-scrollbar{display:none;width:0}body,html{margin:0;overflow:hidden;padding:0}div#terminal{height:100%;left:0;position:absolute;top:0;width:100%}div#terminal div{height:100%}.xterm-screen,.xterm-viewport{height:100%;margin:0;padding:0}</style></head><body> <div id="terminal"></div> <script type="module" src="index.52560dc1.js"></script> </body></html>