charmbracelet / huh

Build terminal forms and prompts 🤷🏻‍♀️
MIT License
3.72k stars 94 forks source link

feat(spinner): make action return an error #292

Open caarlos0 opened 2 weeks ago

caarlos0 commented 2 weeks ago

I think it would be great to allow the spinner action to return an error, so it simplifies error handling in some cases.

this pr is wip to see what you think, if you think its a good idea, I'll work more on it.

caarlos0 commented 2 weeks ago

another idea would be to have a

type Spinner[T any] struct {
  action func () T
  // ..

and maybe a

type Spinner2[T any, Q any] struct {
  action func() (T, Q)
}

the later being most commonly used as Spinner2[Something, error] I would guess, maybe even worth making the second arg an error always.

caarlos0 commented 1 week ago

@maaslalani I reworked some stuff: