From 39dacb988a004e1ab957bf882f98bdbf50771a8b Mon Sep 17 00:00:00 2001 From: sawka Date: Sat, 3 Sep 2022 23:26:57 -0700 Subject: [PATCH] default term rows should be 24 (not 25), add min/max values as well --- pkg/base/base.go | 10 ++++++++++ pkg/shexec/shexec.go | 24 +++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pkg/base/base.go b/pkg/base/base.go index 972d447ec..d89864cf9 100644 --- a/pkg/base/base.go +++ b/pkg/base/base.go @@ -269,3 +269,13 @@ func GetRemoteId() (string, error) { return uuidStr, nil } } + +func BoundInt(ival int, minVal int, maxVal int) int { + if ival < minVal { + return minVal + } + if ival > maxVal { + return maxVal + } + return ival +} diff --git a/pkg/shexec/shexec.go b/pkg/shexec/shexec.go index 1929baaf9..a7879ebda 100644 --- a/pkg/shexec/shexec.go +++ b/pkg/shexec/shexec.go @@ -30,10 +30,12 @@ import ( "golang.org/x/sys/unix" ) -const DefaultRows = 25 -const DefaultCols = 80 -const MaxRows = 1024 -const MaxCols = 1024 +const DefaultTermRows = 24 +const DefaultTermCols = 80 +const MinTermRows = 2 +const MinTermCols = 10 +const MaxTermRows = 1024 +const MaxTermCols = 1024 const MaxFdNum = 1023 const FirstExtraFilesFdNum = 3 const DefaultTermType = "xterm-256color" @@ -319,15 +321,11 @@ func ValidateRunPacket(pk *packet.RunPacketType) error { } func GetWinsize(p *packet.RunPacketType) *pty.Winsize { - rows := DefaultRows - cols := DefaultCols + rows := DefaultTermRows + cols := DefaultTermCols if p.TermOpts != nil { - if p.TermOpts.Rows > 0 && p.TermOpts.Rows <= MaxRows { - rows = p.TermOpts.Rows - } - if p.TermOpts.Cols > 0 && p.TermOpts.Cols <= MaxCols { - cols = p.TermOpts.Cols - } + rows = base.BoundInt(p.TermOpts.Rows, MinTermRows, MaxTermRows) + cols = base.BoundInt(p.TermOpts.Cols, MinTermCols, MaxTermCols) } return &pty.Winsize{Rows: uint16(rows), Cols: uint16(cols)} } @@ -1174,7 +1172,7 @@ func runSimpleCmdInPty(ecmd *exec.Cmd) ([]byte, error) { if err != nil { return nil, fmt.Errorf("opening new pty: %w", err) } - pty.Setsize(cmdPty, &pty.Winsize{Rows: DefaultRows, Cols: DefaultCols}) + pty.Setsize(cmdPty, &pty.Winsize{Rows: DefaultTermRows, Cols: DefaultTermCols}) ecmd.Stdin = cmdTty ecmd.Stdout = cmdTty ecmd.Stderr = cmdTty