Skip to content

Commit

Permalink
chore(exec): better name for Exec func that wraps exec.Cmd (thanks, @…
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Jun 1, 2022
1 parent f488d3e commit 2f88b3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/exec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type editorFinishedMsg struct{ err error }

func openEditor() tea.Cmd {
c := exec.Command(os.Getenv("EDITOR")) //nolint:gosec
return tea.OSExec(c, func(err error) tea.Msg {
return tea.ExecProcess(c, func(err error) tea.Msg {
return editorFinishedMsg{err}
})
}
Expand Down
15 changes: 7 additions & 8 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ type execMsg struct {
// pausing the Program while execution is runnning and resuming it when
// execution has completed.
//
// To run operating-system-level applications like vim and htop from within
// a Program use OSExec.
// Most of the time you'll want to use ExecProcess, which runs an exec.Cmd.
//
// For non-interactive i/o you should use a Cmd (that is, a tea.Cmd).
func Exec(c ExecCommand, fn ExecCallback) Cmd {
Expand All @@ -26,9 +25,9 @@ func Exec(c ExecCommand, fn ExecCallback) Cmd {
}
}

// OSExec runs the given *exec.Cmd 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
// ExecProcess runs the given *exec.Cmd 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.Cmd and a function which returns
Expand All @@ -39,16 +38,16 @@ func Exec(c ExecCommand, fn ExecCallback) Cmd {
//
// c := exec.Command("vim", "file.txt")
//
// cmd := OSExec(c, func(err error) Msg {
// cmd := ExecProcess(c, func(err error) Msg {
// return VimFinishedMsg{err: error}
// })
//
// Or, if you don't care about errors, you could simply:
//
// cmd := OSExec(exec.Command("vim", "file.txt"), nil)
// cmd := ExecProcess(exec.Command("vim", "file.txt"), nil)
//
// For non-interactive i/o you should use a Cmd (that is, a tea.Cmd).
func OSExec(c *exec.Cmd, fn ExecCallback) Cmd {
func ExecProcess(c *exec.Cmd, fn ExecCallback) Cmd {
return Exec(wrapExecCommand(c), fn)
}

Expand Down

0 comments on commit 2f88b3c

Please sign in to comment.