From 39e1c65bfe168187f4518c36081e9de6adf8d751 Mon Sep 17 00:00:00 2001 From: dcorral Date: Thu, 6 Nov 2025 22:13:11 +0100 Subject: [PATCH] term --- main.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 708fc82..1977287 100644 --- a/main.go +++ b/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)})