Add initial width and height
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 19s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 19s
This commit is contained in:
24
main.go
24
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user