term
All checks were successful
Build, Test and Push Docker Image / e2e-test (push) Successful in 10s
Build, Test and Push Docker Image / build-and-push (push) Successful in 16s

This commit is contained in:
2025-11-06 22:13:11 +01:00
parent 94ae50745b
commit 39e1c65bfe

26
main.go
View File

@@ -96,17 +96,23 @@ func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
defer channel.Close() defer channel.Close()
var ptmx *os.File var ptmx *os.File
var termWidth, termHeight uint32 = 80, 24 var termWidth, termHeight uint32 = 80, 24
var term string
for req := range requests { for req := range requests {
switch req.Type { switch req.Type {
case "pty-req": case "pty-req":
if len(req.Payload) >= 8 { if len(req.Payload) >= 4 {
width := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-8:]) termLen := binary.BigEndian.Uint32(req.Payload[0:4])
height := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-4:]) if len(req.Payload) >= int(4+termLen+16) {
if width > 0 { term = string(req.Payload[4 : 4+termLen])
termWidth = width 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
} }
if height > 0 {
termHeight = height
} }
} }
req.Reply(true, nil) req.Reply(true, nil)
@@ -130,7 +136,11 @@ func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
command = "/app/tui" command = "/app/tui"
} }
cmd := exec.Command(command) 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 = "/" cmd.Dir = "/"
var err error var err error
ptmx, err = pty.StartWithSize(cmd, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)}) ptmx, err = pty.StartWithSize(cmd, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)})