Skip to content

Commit 78e2787

Browse files
committed
fix: Monitor TTY size when using SSH
The TTY wasn't resizing properly, and reasonably so considering we weren't updating it 🤦.
1 parent 23295f7 commit 78e2787

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cli/ssh.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import (
55
"io"
66
"net"
77
"os"
8+
"os/signal"
89
"strings"
10+
"syscall"
911
"time"
1012

1113
"github.com/google/uuid"
1214
"github.com/mattn/go-isatty"
1315
"github.com/spf13/cobra"
1416
gossh "golang.org/x/crypto/ssh"
17+
"golang.org/x/crypto/ssh/terminal"
1518
"golang.org/x/term"
1619
"golang.org/x/xerrors"
1720

@@ -134,6 +137,21 @@ func ssh() *cobra.Command {
134137
defer func() {
135138
_ = term.Restore(int(os.Stdin.Fd()), state)
136139
}()
140+
141+
windowSize := make(chan os.Signal, 1)
142+
signal.Notify(windowSize, syscall.SIGWINCH)
143+
defer signal.Stop(windowSize)
144+
go func() {
145+
for {
146+
select {
147+
case <-cmd.Context().Done():
148+
return
149+
case <-windowSize:
150+
}
151+
width, height, _ := terminal.GetSize(int(stdoutFile.Fd()))
152+
_ = sshSession.WindowChange(height, width)
153+
}
154+
}()
137155
}
138156

139157
err = sshSession.RequestPty("xterm-256color", 128, 128, gossh.TerminalModes{})

0 commit comments

Comments
 (0)