Option to turn off clear of the web terminal buffer when session is closed

pull/5/head
Faruk Kasumovic 4 years ago
parent a3683a2341
commit a03033e4bf

File diff suppressed because one or more lines are too long

@ -12,7 +12,8 @@
sessionID: {{.SessionID}}, sessionID: {{.SessionID}},
salt: {{.Salt}}, salt: {{.Salt}},
wsPath: {{.WSPath}}, wsPath: {{.WSPath}},
scrollBack: {{.ScrollBack}} scrollBack: {{.ScrollBack}},
noClear: {{.NoClear}}
} }
console.log("Initial data", window.ttyInitialData) console.log("Initial data", window.ttyInitialData)
</script> </script>

@ -28,5 +28,6 @@ wsAddress += ttyWindow.location.host + ttyWindow.ttyInitialData.wsPath;
const ttyReceiver = new TTYReceiver( const ttyReceiver = new TTYReceiver(
wsAddress, wsAddress,
document.getElementById('terminal') as HTMLDivElement, document.getElementById('terminal') as HTMLDivElement,
ttyWindow.ttyInitialData.scrollBack ttyWindow.ttyInitialData.scrollBack,
!ttyWindow.ttyInitialData.noClear
); );

@ -11,7 +11,7 @@ class TTYReceiver {
private xterminal: Terminal; private xterminal: Terminal;
private containerElement: HTMLElement; private containerElement: HTMLElement;
constructor(wsAddress: string, container: HTMLDivElement, scrollback: number) { constructor(wsAddress: string, container: HTMLDivElement, scrollback: number, clear: boolean) {
const connection = new WebSocket(wsAddress); const connection = new WebSocket(wsAddress);
this.xterminal = new Terminal({ this.xterminal = new Terminal({
@ -29,7 +29,9 @@ class TTYReceiver {
this.xterminal.blur(); this.xterminal.blur();
this.xterminal.setOption('cursorBlink', false); this.xterminal.setOption('cursorBlink', false);
this.xterminal.clear(); if (clear) {
this.xterminal.clear();
}
this.xterminal.write('Session closed'); this.xterminal.write('Session closed');
} }

@ -28,6 +28,7 @@ type SessionTemplateModel struct {
Salt string Salt string
WSPath string WSPath string
ScrollBack int ScrollBack int
NoClear bool
} }
// TTYServerConfig is used to configure the tty server before it is started // TTYServerConfig is used to configure the tty server before it is started
@ -40,6 +41,7 @@ type TTYServerConfig struct {
TLSKeyFile string TLSKeyFile string
FrontendPath string FrontendPath string
ScrollBack int ScrollBack int
NoClear bool
} }
// TTYServer represents the instance of a tty server // TTYServer represents the instance of a tty server
@ -192,6 +194,7 @@ func (server *TTYServer) handleSession(w http.ResponseWriter, r *http.Request) {
Salt: "salt&pepper", Salt: "salt&pepper",
WSPath: getWSPath(sessionID), WSPath: getWSPath(sessionID),
ScrollBack: server.config.ScrollBack, ScrollBack: server.config.ScrollBack,
NoClear: server.config.NoClear,
} }
err = t.Execute(w, templateModel) err = t.Execute(w, templateModel)

@ -17,6 +17,7 @@ func main() {
url := flag.String("url", "http://localhost", "The public web URL the server will be accessible at. This will be sent back to the tty-share tool to display it to the user.") url := flag.String("url", "http://localhost", "The public web URL the server will be accessible at. This will be sent back to the tty-share tool to display it to the user.")
frontendPath := flag.String("frontend_path", "", "The path to the frontend resources. By default, these resources are included in the server binary, so you only need this path if you don't want to use the bundled ones.") frontendPath := flag.String("frontend_path", "", "The path to the frontend resources. By default, these resources are included in the server binary, so you only need this path if you don't want to use the bundled ones.")
scrollBack := flag.Int("scroll_back", 1024, "Set scrollback buffer size for viewers") scrollBack := flag.Int("scroll_back", 1024, "Set scrollback buffer size for viewers")
noClear := flag.Bool("noclear", false, "Don't clear web terminal buffer when session is closed")
flag.Parse() flag.Parse()
log := MainLogger log := MainLogger
@ -28,6 +29,7 @@ func main() {
ServerURL: *url, ServerURL: *url,
FrontendPath: *frontendPath, FrontendPath: *frontendPath,
ScrollBack: *scrollBack, ScrollBack: *scrollBack,
NoClear: *noClear,
} }
server := NewTTYServer(config) server := NewTTYServer(config)

Loading…
Cancel
Save