Skip to content

Commit 04d7943

Browse files
committed
Fix tty for dev client
1 parent ffd4776 commit 04d7943

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

dev/client/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import (
44
"context"
55
"io"
66
"os"
7+
"os/signal"
8+
"syscall"
79

810
"cdr.dev/wsep"
911
"github.com/spf13/pflag"
1012
"go.coder.com/cli"
1113
"go.coder.com/flog"
14+
"golang.org/x/crypto/ssh/terminal"
1215
"nhooyr.io/websocket"
1316
)
1417

@@ -71,6 +74,27 @@ func do(fl *pflag.FlagSet, tty bool) {
7174
if err != nil {
7275
flog.Fatal("failed to start remote command: %v", err)
7376
}
77+
if tty {
78+
ch := make(chan os.Signal, 1)
79+
signal.Notify(ch, syscall.SIGWINCH)
80+
go func() {
81+
for range ch {
82+
width, height, err := terminal.GetSize(int(os.Stdin.Fd()))
83+
if err != nil {
84+
continue
85+
}
86+
process.Resize(ctx, uint16(height), uint16(width))
87+
}
88+
}()
89+
ch <- syscall.SIGWINCH
90+
91+
oldState, err := terminal.MakeRaw(int(os.Stdin.Fd()))
92+
if err != nil {
93+
flog.Fatal("failed to make terminal raw for tty: %w", err)
94+
}
95+
defer terminal.Restore(int(os.Stdin.Fd()), oldState)
96+
}
97+
7498
go io.Copy(os.Stdout, process.Stdout())
7599
go io.Copy(os.Stderr, process.Stderr())
76100
go io.Copy(process.Stdin(), os.Stdin)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/spf13/pflag v1.0.5
1010
go.coder.com/cli v0.4.0
1111
go.coder.com/flog v0.0.0-20190906214207-47dd47ea0512
12+
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
1213
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
1314
nhooyr.io/websocket v1.8.6
1415
)

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eT
112112
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
113113
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
114114
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
115+
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
115116
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
116117
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
117118
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=

tty_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func testTTY(ctx context.Context, t *testing.T, e Execer) {
4949
t.Logf("bash tty stderr = %s", stderr)
5050
assert.True(t, "stderr is empty", len(stderr) == 0)
5151
}()
52-
time.Sleep(5 * time.Second)
52+
time.Sleep(3 * time.Second)
5353

5454
process.Close()
5555
wg.Wait()

0 commit comments

Comments
 (0)