Skip to content

Commit a8360d1

Browse files
committed
Support starting PTY with a size
You get unexpected padding in screen if you try to resize afterward.
1 parent 0c73164 commit a8360d1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pty/pty.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,19 @@ type WithFlags interface {
8080
EchoEnabled() (bool, error)
8181
}
8282

83-
// Options represents a an option for a PTY.
83+
// Options represents an option for a PTY.
8484
type Option func(*ptyOptions)
8585

86+
type Winsize struct {
87+
Height uint16
88+
Width uint16
89+
}
90+
8691
type ptyOptions struct {
8792
logger *log.Logger
8893
sshReq *ssh.Pty
8994
setGPGTTY bool
95+
size *Winsize
9096
}
9197

9298
// WithSSHRequest applies the ssh.Pty request to the PTY.
@@ -113,6 +119,13 @@ func WithGPGTTY() Option {
113119
}
114120
}
115121

122+
// WithSize sets the initial size at which to spawn the PTY.
123+
func WithSize(size *Winsize) Option {
124+
return func(opts *ptyOptions) {
125+
opts.size = size
126+
}
127+
}
128+
116129
// New constructs a new Pty.
117130
func New(opts ...Option) (PTY, error) {
118131
return newPty(opts...)

pty/pty_other.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ func newPty(opt ...Option) (retPTY *otherPty, err error) {
2626
if err != nil {
2727
return nil, err
2828
}
29+
if opts.size != nil {
30+
_ = pty.Setsize(ptyFile, &pty.Winsize{
31+
Rows: opts.size.Height,
32+
Cols: opts.size.Width,
33+
})
34+
}
2935
opty := &otherPty{
3036
pty: ptyFile,
3137
tty: ttyFile,

0 commit comments

Comments
 (0)