Skip to content

Capture output for wish.Command #291

@robinovitch61

Description

@robinovitch61

Describe the bug
For tea.ExecProcess, I've done something like this to capture output back to the application:

type StdoutProxy struct {
    SavedOutput []byte
}

func (so *StdoutProxy) Write(p []byte) (n int, err error) {
    so.SavedOutput = append(so.SavedOutput, p...)
    return os.Stdout.Write(p)
}

c := exec.Command("bash")
stdoutProxy := &StdoutProxy{}
c.Stdout = stdoutProxy
tea.ExecProcess(c, func(err error) tea.Msg {
    return ExecCompleteMsg{Output: string(stdoutProxy.SavedOutput)}
}

Which has worked nicely. But when I do something similar with a wish.Command and tea.Exec, it doesn't work:

wc := wish.Command(session, "bash")
wc.SetStdout(stdoutProxy)
tea.Exec(wc, func(err error) tea.Msg {
    return ExecCompleteMsg{Output: string(stdoutProxy.SavedOutput)}
}

In this second case, SavedOutput is empty. Any tips here?

Setup
Please complete the following information along with version numbers, if applicable.

  • OS macOS
  • Shell zsh
  • Terminal Emulator iterm2
  • Terminal Multiplexer tmux

Note: you might encounter rendering issues if your locale does not use
UTF-8 encoding. Please check your locale (locale on POSIX systems) to
see what encoding is being used by your system.

❯ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=

Expected behavior
SavedOutput is not empty in the second case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions