Closed abradley2 closed 3 weeks ago
I plan on making a larger example for this during the weekend once I'm free from work, but curious to know what people think now. I'm on the fence about RunWithCallbacks
being necessary for what I'm trying to do here, though I still think it'd be helpfull to have the callback fields exposed either way
I plan on making a larger example for this during the weekend once I'm free from work, but curious to know what people think now. I'm on the fence about
RunWithCallbacks
being necessary for what I'm trying to do here, though I still think it'd be helpfull to have the callback fields exposed either way
I like exposing the SubmitCmd
and CancelCmd
. I think we don't need RunWithCallbacks
personally. So we should take it out, if we end up having a compelling use case we can add it in another PR.
I plan on making a larger example for this during the weekend once I'm free from work, but curious to know what people think now. I'm on the fence about
RunWithCallbacks
being necessary for what I'm trying to do here, though I still think it'd be helpfull to have the callback fields exposed either wayI like exposing the
SubmitCmd
andCancelCmd
. I think we don't needRunWithCallbacks
personally. So we should take it out, if we end up having a compelling use case we can add it in another PR.
I think you're right. As of now I'm no longer using RunWithCallbacks
, so I can't think of a concrete use-case. I've removed it
I'm using
huh
to make some internal tooling with neat little TUI's.In this case, we have suite of tools that are their own individual
huh
forms. These can be used as top level forms, but I've also set things up in a way where forms can compose other forms that are otherwise top level. This uses a pattern commonly referred to as Nested Tea. Some of our tools are sometimes the top level form, other times they're forms within a form and this pattern makes them super composable.It's a bit tricky, to compose them in this way, however. It often involves a line that looks sort of like this:
The tricky part is
if-statements
in the control flow of update. Missing simple statements likem.subFormFoo = nil
can cause a bad loop. When callbacks are configurable things become much easier and everything can stay in the msg/update pattern:Initializing a new form in this way is pretty straight forward
Notice that in these cases we aren't using
form.Run()
to run a form because it's undesirable to have it calltea.Quit
when that form is submitted.For this reason it isn't necessary to use the
RunWithCallbacks
function I added here. That would be used for top level forms where we want to stay in the "TEA mode" when the form is exited.