pull/5/merge
Faruk Kasumovic 4 years ago committed by GitHub
commit 59d6953696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because one or more lines are too long

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

@ -25,4 +25,9 @@ let ttyWindow = window as any;
wsAddress += ttyWindow.location.host + ttyWindow.ttyInitialData.wsPath; wsAddress += ttyWindow.location.host + ttyWindow.ttyInitialData.wsPath;
const ttyReceiver = new TTYReceiver(wsAddress, document.getElementById('terminal') as HTMLDivElement); const ttyReceiver = new TTYReceiver(
wsAddress,
document.getElementById('terminal') as HTMLDivElement,
ttyWindow.ttyInitialData.scrollBack,
!ttyWindow.ttyInitialData.noClear
);

@ -11,13 +11,13 @@ class TTYReceiver {
private xterminal: Terminal; private xterminal: Terminal;
private containerElement: HTMLElement; private containerElement: HTMLElement;
constructor(wsAddress: string, container: HTMLDivElement) { 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({
cursorBlink: true, cursorBlink: true,
macOptionIsMeta: true, macOptionIsMeta: true,
scrollback: 0, scrollback: scrollback,
fontSize: 12, fontSize: 12,
letterSpacing: 0, letterSpacing: 0,
}); });
@ -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');
} }

@ -24,9 +24,11 @@ var log = MainLogger
// SessionTemplateModel used for templating // SessionTemplateModel used for templating
type SessionTemplateModel struct { type SessionTemplateModel struct {
SessionID string SessionID string
Salt string Salt string
WSPath string WSPath string
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
@ -38,6 +40,8 @@ type TTYServerConfig struct {
TLSCertFile string TLSCertFile string
TLSKeyFile string TLSKeyFile string
FrontendPath string FrontendPath string
ScrollBack int
NoClear bool
} }
// TTYServer represents the instance of a tty server // TTYServer represents the instance of a tty server
@ -186,9 +190,11 @@ func (server *TTYServer) handleSession(w http.ResponseWriter, r *http.Request) {
} }
templateModel := SessionTemplateModel{ templateModel := SessionTemplateModel{
SessionID: sessionID, SessionID: sessionID,
Salt: "salt&pepper", Salt: "salt&pepper",
WSPath: getWSPath(sessionID), WSPath: getWSPath(sessionID),
ScrollBack: server.config.ScrollBack,
NoClear: server.config.NoClear,
} }
err = t.Execute(w, templateModel) err = t.Execute(w, templateModel)

@ -16,6 +16,8 @@ func main() {
senderAddress := flag.String("sender_address", ":6543", "The bind address for the tty-share TLS connections. tty-share tool will connect to this address.") senderAddress := flag.String("sender_address", ":6543", "The bind address for the tty-share TLS connections. tty-share tool will connect to this address.")
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")
noClear := flag.Bool("noclear", false, "Don't clear web terminal buffer when session is closed")
flag.Parse() flag.Parse()
log := MainLogger log := MainLogger
@ -26,6 +28,8 @@ func main() {
TTYSenderAddress: *senderAddress, TTYSenderAddress: *senderAddress,
ServerURL: *url, ServerURL: *url,
FrontendPath: *frontendPath, FrontendPath: *frontendPath,
ScrollBack: *scrollBack,
NoClear: *noClear,
} }
server := NewTTYServer(config) server := NewTTYServer(config)

Loading…
Cancel
Save