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

43
.gitignore vendored Normal file
View File

@@ -0,0 +1,43 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
sshserver
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (uncomment if using dep or similar)
# vendor/
# Go workspace file
go.work
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# IDE files
.vscode/
.idea/
*.swp
*.swo
# Logs
*.log
# Temporary files
*.tmp
# SSH host key
host_key

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