Skip to content

Commit

Permalink
Add StartWithSize to allow resizing pty before starting a command to …
Browse files Browse the repository at this point in the history
…avoid races (#62)
  • Loading branch information
virtuald authored and creack committed Sep 15, 2018
1 parent fa756f0 commit db8e3cd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db8e3cd

Please sign in to comment.