diff --git a/sshd/pty.go b/sshd/pty.go index 4443fd3..d3ed9ca 100644 --- a/sshd/pty.go +++ b/sshd/pty.go @@ -6,8 +6,8 @@ import "encoding/binary" // parsePtyRequest parses the payload of the pty-req message and extracts the // dimensions of the terminal. See RFC 4254, section 6.2. -func parsePtyRequest(s []byte) (width, height int, ok bool) { - _, s, ok = parseString(s) +func parsePtyRequest(s []byte) (term string, width, height int, ok bool) { + term, s, ok = parseString(s) if !ok { return } diff --git a/sshd/terminal.go b/sshd/terminal.go index 74c9194..480fa59 100644 --- a/sshd/terminal.go +++ b/sshd/terminal.go @@ -87,8 +87,9 @@ type Terminal struct { done chan struct{} closeOnce sync.Once - mu sync.Mutex - env []EnvVar + mu sync.Mutex + env []EnvVar + term string } // Make new terminal from a session channel @@ -185,11 +186,16 @@ func (t *Terminal) listen(requests <-chan *ssh.Request, ready chan<- struct{}) { close(ready) } case "pty-req": - width, height, ok = parsePtyRequest(req.Payload) + var term string + term, width, height, ok = parsePtyRequest(req.Payload) if ok { // TODO: Hardcode width to 100000? err := t.SetSize(width, height) ok = err == nil + // Save the term: + t.mu.Lock() + t.term = term + t.mu.Unlock() } case "window-change": width, height, ok = parseWinchRequest(req.Payload) @@ -222,3 +228,11 @@ func (t *Terminal) Env() Env { defer t.mu.Unlock() return Env(t.env) } + +// Term returns the terminal string value as set by the pty. +// If there was no pty request, this is empty. +func (t *Terminal) Term() string { + t.mu.Lock() + defer t.mu.Unlock() + return t.term +}