mirror of https://github.com/coder/coder.git
fix: Monitor TTY size when using SSH (#1119)
The TTY wasn't resizing properly, and reasonably so considering
we weren't updating it 🤦.
This commit is contained in:
parent
0c042dc249
commit
885d5f2098
13
cli/ssh.go
13
cli/ssh.go
|
@ -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{})
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue