diff --git a/run.go b/run.go index baecca8..2d7f961 100644 --- a/run.go +++ b/run.go @@ -12,11 +12,27 @@ import ( // and c.Stderr, calls c.Start, and returns the File of the tty's // corresponding pty. func Start(c *exec.Cmd) (pty *os.File, err error) { + return StartWithSize(c, nil) +} + +// StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, +// and c.Stderr, calls c.Start, and returns the File of the tty's +// corresponding pty. +// +// This will resize the pty to the specified size before starting the command +func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) { pty, tty, err := Open() if err != nil { return nil, err } defer tty.Close() + if sz != nil { + err = Setsize(pty, sz) + if err != nil { + pty.Close() + return nil, err + } + } c.Stdout = tty c.Stdin = tty c.Stderr = tty