Get the term value

This commit is contained in:
Chris Miller 2020-01-10 01:18:32 +00:00 committed by Andrey Petrov
parent dd2fadd6c1
commit fe84822f5d
2 changed files with 19 additions and 5 deletions

View File

@ -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
}

View File

@ -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
}