term
This commit is contained in:
28
main.go
28
main.go
@@ -96,17 +96,23 @@ func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
|
||||
defer channel.Close()
|
||||
var ptmx *os.File
|
||||
var termWidth, termHeight uint32 = 80, 24
|
||||
var term string
|
||||
for req := range requests {
|
||||
switch req.Type {
|
||||
case "pty-req":
|
||||
if len(req.Payload) >= 8 {
|
||||
width := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-8:])
|
||||
height := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-4:])
|
||||
if width > 0 {
|
||||
termWidth = width
|
||||
}
|
||||
if height > 0 {
|
||||
termHeight = height
|
||||
if len(req.Payload) >= 4 {
|
||||
termLen := binary.BigEndian.Uint32(req.Payload[0:4])
|
||||
if len(req.Payload) >= int(4+termLen+16) {
|
||||
term = string(req.Payload[4 : 4+termLen])
|
||||
log.Println("Client TERM:", term)
|
||||
cols := binary.BigEndian.Uint32(req.Payload[4+termLen : 4+termLen+4])
|
||||
rows := binary.BigEndian.Uint32(req.Payload[4+termLen+4 : 4+termLen+8])
|
||||
if cols > 0 {
|
||||
termWidth = cols
|
||||
}
|
||||
if rows > 0 {
|
||||
termHeight = rows
|
||||
}
|
||||
}
|
||||
}
|
||||
req.Reply(true, nil)
|
||||
@@ -130,7 +136,11 @@ func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
|
||||
command = "/app/tui"
|
||||
}
|
||||
cmd := exec.Command(command)
|
||||
cmd.Env = []string{"PATH=/bin", "TERM=xterm-256color"}
|
||||
envTerm := "TERM=xterm-256color"
|
||||
if term != "" {
|
||||
envTerm = "TERM=" + term
|
||||
}
|
||||
cmd.Env = []string{"PATH=/bin", envTerm}
|
||||
cmd.Dir = "/"
|
||||
var err error
|
||||
ptmx, err = pty.StartWithSize(cmd, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)})
|
||||
|
||||
Reference in New Issue
Block a user