mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-07-02 03:34:29 +02:00
Get the term value
This commit is contained in:
parent
dd2fadd6c1
commit
fe84822f5d
@ -6,8 +6,8 @@ import "encoding/binary"
|
|||||||
|
|
||||||
// parsePtyRequest parses the payload of the pty-req message and extracts the
|
// parsePtyRequest parses the payload of the pty-req message and extracts the
|
||||||
// dimensions of the terminal. See RFC 4254, section 6.2.
|
// dimensions of the terminal. See RFC 4254, section 6.2.
|
||||||
func parsePtyRequest(s []byte) (width, height int, ok bool) {
|
func parsePtyRequest(s []byte) (term string, width, height int, ok bool) {
|
||||||
_, s, ok = parseString(s)
|
term, s, ok = parseString(s)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ type Terminal struct {
|
|||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
env []EnvVar
|
env []EnvVar
|
||||||
|
term string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make new terminal from a session channel
|
// Make new terminal from a session channel
|
||||||
@ -185,11 +186,16 @@ func (t *Terminal) listen(requests <-chan *ssh.Request, ready chan<- struct{}) {
|
|||||||
close(ready)
|
close(ready)
|
||||||
}
|
}
|
||||||
case "pty-req":
|
case "pty-req":
|
||||||
width, height, ok = parsePtyRequest(req.Payload)
|
var term string
|
||||||
|
term, width, height, ok = parsePtyRequest(req.Payload)
|
||||||
if ok {
|
if ok {
|
||||||
// TODO: Hardcode width to 100000?
|
// TODO: Hardcode width to 100000?
|
||||||
err := t.SetSize(width, height)
|
err := t.SetSize(width, height)
|
||||||
ok = err == nil
|
ok = err == nil
|
||||||
|
// Save the term:
|
||||||
|
t.mu.Lock()
|
||||||
|
t.term = term
|
||||||
|
t.mu.Unlock()
|
||||||
}
|
}
|
||||||
case "window-change":
|
case "window-change":
|
||||||
width, height, ok = parseWinchRequest(req.Payload)
|
width, height, ok = parseWinchRequest(req.Payload)
|
||||||
@ -222,3 +228,11 @@ func (t *Terminal) Env() Env {
|
|||||||
defer t.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
return Env(t.env)
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user