Skip to content

Commit

Permalink
docs(exec): tidy up doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Apr 6, 2022
1 parent 7d6e0c2 commit 8e380dc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tea.go
Expand Up @@ -246,10 +246,10 @@ func HideCursor() Msg {
return hideCursorMsg{}
}

// Exec runs the given ExecCommand in a blocking fashion, effectively pausing the
// Program while the command is running. After the *exec.Cmd exists the Program
// resumes. It's useful for spawning other interactive applications such as
// editors and shells from within a Program.
// Exec runs the given ExecCommand in a blocking fashion, effectively pausing
// the Program while the command is running. After the *exec.Cmd exists the
// Program resumes. It's useful for spawning other interactive applications
// such as editors and shells from within a Program.
//
// To produce the command, pass an *exec.Command and a function which returns
// a message containing the error which may have occurred when running the
Expand Down Expand Up @@ -756,38 +756,41 @@ type ExecCommand interface {
SetStderr(io.Writer)
}

// WrapExecCommand wraps a exec.Cmd to be compatible with the Command interface.
// WrapExecCommand wraps an exec.Cmd so that it satisfies the ExecCommand
// interface.
func WrapExecCommand(c *exec.Cmd) ExecCommand {
return &osExecCommand{Cmd: c}
}

// osExecCommand is a layer over an exec.Cmd that satisfies the ExecCommand
// interface.
type osExecCommand struct{ *exec.Cmd }

// SetStdin to comply with the Command interface.
// SetStdin sets stdin on underlying exec.Cmd to the given io.Reader.
func (c *osExecCommand) SetStdin(r io.Reader) {
// If unset, have the command use the same input as the terminal.
if c.Stdin == nil {
c.Stdin = r
}
}

// SetStdout to comply with the Command interface.
// SetStdout sets stdout on underlying exec.Cmd to the given io.Writer.
func (c *osExecCommand) SetStdout(w io.Writer) {
// If unset, have the command use the same output as the terminal.
if c.Stdout == nil {
c.Stdout = w
}
}

// SetStderr to comply with the Command interface.
// SetStderr sets stderr on the underlying exec.Cmd to the given io.Writer.
func (c *osExecCommand) SetStderr(w io.Writer) {
// If unset, use stderr for the command's stderr
if c.Stderr == nil {
c.Stderr = w
}
}

// exec runs a Command and delivers the results to the program.
// exec runs an ExecCommand and delivers the results to the program as a Msg.
func (p *Program) exec(c ExecCommand, fn ExecCallback) {
if err := p.ReleaseTerminal(); err != nil {
// If we can't release input, abort.
Expand Down

0 comments on commit 8e380dc

Please sign in to comment.