Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 62ffe24

Browse files
committed
Fix resize stutter effect
1 parent 6a7b2ca commit 62ffe24

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

cmd/coder/shell.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55
"io"
66
"os"
77
"os/signal"
8+
"time"
89

910
"github.com/spf13/pflag"
1011
"go.coder.com/cli"
1112
"go.coder.com/flog"
1213
"golang.org/x/crypto/ssh/terminal"
1314
"golang.org/x/sys/unix"
15+
"golang.org/x/time/rate"
1416

1517
client "cdr.dev/coder-cli/internal/entclient"
1618
"cdr.dev/coder-cli/wush"
@@ -39,6 +41,9 @@ func (cmd *shellCmd) sendResizeEvents(termfd int, client *wush.Client) {
3941
sigs := make(chan os.Signal, 16)
4042
signal.Notify(sigs, unix.SIGWINCH)
4143

44+
// Limit the frequency of resizes to prevent a stuttering effect.
45+
resizeLimiter := rate.NewLimiter(rate.Every(time.Millisecond*100), 1)
46+
4247
for {
4348
width, height, err := terminal.GetSize(termfd)
4449
if err != nil {
@@ -51,8 +56,10 @@ func (cmd *shellCmd) sendResizeEvents(termfd int, client *wush.Client) {
5156
flog.Error("get term size: %v", err)
5257
return
5358
}
59+
5460
// Do this last so the first resize is sent.
5561
<-sigs
62+
resizeLimiter.Wait(context.Background())
5663
}
5764
}
5865

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
golang.org/x/crypto v0.0.0-20200422194213-44a606286825
1717
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
1818
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4
19+
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
1920
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
2021
nhooyr.io/websocket v1.8.5
2122
)

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
5959
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY=
6060
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6161
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
62+
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
6263
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
6364
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
6465
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

0 commit comments

Comments
 (0)