Skip to content

Commit 30cd274

Browse files
committed
fix: Command: default rows and cols if set to 0
1 parent 5ba2389 commit 30cd274

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

server.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import (
1919
"cdr.dev/wsep/internal/proto"
2020
)
2121

22+
const (
23+
defaultRows = 80
24+
defaultCols = 24
25+
)
26+
2227
// Options allows configuring the server.
2328
type Options struct {
2429
SessionTimeout time.Duration
@@ -138,9 +143,14 @@ func (srv *Server) Serve(ctx context.Context, c *websocket.Conn, execer Execer,
138143
command := mapToClientCmd(header.Command)
139144

140145
if command.TTY {
141-
// Enforce rows and columns so the TTY will be correctly sized.
142-
if command.Rows == 0 || command.Cols == 0 {
143-
return xerrors.Errorf("rows and cols must be non-zero")
146+
// If rows and cols are not provided, default to 80x24.
147+
if command.Rows == 0 {
148+
flog.Info("rows not provided, defaulting to 80")
149+
command.Rows = defaultRows
150+
}
151+
if command.Cols == 0 {
152+
flog.Info("cols not provided, defaulting to 24")
153+
command.Cols = defaultCols
144154
}
145155
}
146156

tty_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ func TestReconnectTTY(t *testing.T) {
3939
server := newServer(t)
4040
ctx, command := newSession(t)
4141
command.Rows = 0
42-
connect(ctx, t, command, server, nil, "rows and cols must be non-zero")
42+
command.Cols = 0
43+
ps1, _ := connect(ctx, t, command, server, nil, "")
44+
expected := writeUnique(t, ps1)
45+
assert.True(t, "find initial output", checkStdout(t, ps1, expected, []string{}))
46+
47+
ps2, _ := connect(ctx, t, command, server, nil, "")
48+
assert.True(t, "find reconnected output", checkStdout(t, ps2, expected, []string{}))
4349
})
4450

4551
t.Run("DeprecatedServe", func(t *testing.T) {
@@ -188,8 +194,8 @@ func newSession(t *testing.T) (context.Context, Command) {
188194
Command: "sh",
189195
TTY: true,
190196
Stdin: true,
191-
Cols: 100,
192-
Rows: 100,
197+
Cols: defaultCols,
198+
Rows: defaultRows,
193199
Env: []string{"TERM=xterm"},
194200
}
195201

0 commit comments

Comments
 (0)