Skip to content

fix: Monitor TTY size when using SSH #1119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Monitor TTY size when using SSH
The TTY wasn't resizing properly, and reasonably so considering
we weren't updating it 🤦.
  • Loading branch information
kylecarbs committed Apr 25, 2022
commit e1257c019f5c809286c98554199d506a75f2d055
13 changes: 13 additions & 0 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ func ssh() *cobra.Command {
defer func() {
_ = term.Restore(int(os.Stdin.Fd()), state)
}()

windowChange := listenWindowSize(cmd.Context())
go func() {
for {
select {
case <-cmd.Context().Done():
return
case <-windowChange:
}
width, height, _ := term.GetSize(int(stdoutFile.Fd()))
_ = sshSession.WindowChange(height, width)
}
}()
}

err = sshSession.RequestPty("xterm-256color", 128, 128, gossh.TerminalModes{})
Expand Down
22 changes: 22 additions & 0 deletions cli/ssh_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !windows
// +build !windows

package cli

import (
"context"
"os"
"os/signal"

"golang.org/x/sys/unix"
)

func listenWindowSize(ctx context.Context) <-chan os.Signal {
windowSize := make(chan os.Signal, 1)
signal.Notify(windowSize, unix.SIGWINCH)
go func() {
<-ctx.Done()
signal.Stop(windowSize)
}()
return windowSize
}
27 changes: 27 additions & 0 deletions cli/ssh_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build windows
// +build windows

package cli

import (
"context"
"os"
"time"
)

func listenWindowSize(ctx context.Context) <-chan os.Signal {
windowSize := make(chan os.Signal, 3)
ticker := time.NewTicker(time.Second)
go func() {
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
}
windowSize <- nil
}
}()
return windowSize
}