huh
huh copied to clipboard
Be able to specify output for forms
Running a form always outputs the UI to stdout: https://github.com/charmbracelet/huh/blob/main/form.go#L560
This is problematic if a program ultimately produces some output to stdout that the user wants to redirect into a file or pipe into another program.
It would be awesome if there was a way exposed to change this to Stderr
, or maybe it should just default to stderr like the spinner does:
https://github.com/charmbracelet/huh/blob/main/spinner/spinner.go#L144
Hi! There's actually support for this on main
in the form of Form.WithProgamOptions
:
err := huh.NewForm(/* ... */).
WithProgramOptions(tea.WithOutput(os.Stderr)).
Run()
That said, we may want to smooth the API out a little into something slightly more high level (i.e. Form.WithOutput()
).
Hi! There's actually support for this on
main
in the form ofForm.WithProgamOptions
:err := huh.NewForm(/* ... */). WithProgramOptions(tea.WithOutput(os.Stderr)). Run()
That said, we may want to smooth the API out a little into something slightly more high level (i.e.
Form.WithOutput()
).
Would appreciate something like that as well, thank you for providing the answer :)
@meowgorithm Is there an ETA on a new cut of a release from main for this? We are blocked on this feature, primarily because there's no way to make a Form work correctly when invoked with tea.NewProgram(...)
directly due to the submitCmd
being private (and only being set via Form.Run()
) - https://github.com/charmbracelet/huh/blob/main/form.go#L549
Our use case is using huh
with a Kong as a CLI wrapper, and Kong can provide its own Stdin/Stdout buffers, but obviously they are entirely disconnected from what huh.Form
does.
@meowgorithm It would be nice to direct the output of accessible mode to the specified output. Currently accessible forms use fmt.Println()
always sending to stdout
. With something like Form.WithOutput()
we would could use the output in accessible code with fmt.Fprintln(out, ...)
What do you think?
Hey! Just added a WithOutput
for TUI mode in #201 and will later propagate it to accessible mode!
Great! Thanks
@shakefu:
@meowgorithm Is there an ETA on a new cut of a release from main for this?
We expect to cut a release soon, but in the mean time it's totally reasonable to pin to main
;
go get github.com/charmbracelet/huh@main
Closing this as we added WithOutput
and will cut a new release ASAP!