Add initial width and height
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 19s

This commit is contained in:
2025-11-06 20:23:15 +01:00
parent 4d5d14bb26
commit 3bc3859a2d
2 changed files with 64 additions and 3 deletions

24
main.go
View File

@@ -95,15 +95,32 @@ func handleConn(conn net.Conn, config *ssh.ServerConfig) {
func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
defer channel.Close()
var ptmx *os.File
var termWidth, termHeight uint32 = 15, 15
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
}
}
req.Reply(true, nil)
case "window-change":
width := binary.BigEndian.Uint32(req.Payload)
height := binary.BigEndian.Uint32(req.Payload[4:])
if width > 0 {
termWidth = width
}
if height > 0 {
termHeight = height
}
if ptmx != nil {
width := binary.BigEndian.Uint32(req.Payload)
height := binary.BigEndian.Uint32(req.Payload[4:])
pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(width), Rows: uint16(height)})
pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)})
}
req.Reply(true, nil)
case "shell":
@@ -121,6 +138,7 @@ func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
log.Println("PTY start error:", err)
return
}
pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)})
go func() {
defer ptmx.Close()
go io.Copy(channel, ptmx)