wish icon indicating copy to clipboard operation
wish copied to clipboard

Capture output for wish.Command

Open robinovitch61 opened this issue 7 months ago • 2 comments

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.

robinovitch61 avatar Jun 30 '24 15:06 robinovitch61