Closed
Description
Describe the bug
When running a Spinner with a quick action, any output following the spinner's lifecycle is consistently pushed to the side.
To Reproduce
Here's a simple file that shows this weird behavior:
package main
import (
"time"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/huh/spinner"
)
func main() {
spinner.New().Title("I'm not so quick..").Action(func() {
time.Sleep(2 * time.Second)
}).Run()
huh.NewNote().Title("I'm right over here! Hit Enter to see the next spinner!").Run()
spinner.New().Title("I'm too fast!").Action(func() {
// No-op
}).Run()
huh.NewNote().Title("<- I swear there was a spinner here somewhere!").Run()
}
In this case, I've used a no-op action to showcase the behavior, but I've been able to replicate this in other projects where the action is occasionally faster than expected.
Expected behavior
I expected this to behave similarly to its equivalent counterpart, using context:
package main
import (
"context"
"time"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/huh/spinner"
)
func main() {
ctxSlow, cancelSlow := context.WithCancel(context.Background())
go func() {
time.Sleep(2 * time.Second)
cancelSlow()
}()
spinner.New().Title("I'm not so quick..").Context(ctxSlow).Run()
huh.NewNote().Title("I'm right over here! Hit Enter to see the next spinner!").Run()
ctxFast, cancelFast := context.WithCancel(context.Background())
go func() {
// No-op
cancelFast()
}()
spinner.New().Title("I'm too fast!").Context(ctxFast).Run()
huh.NewNote().Title("There was a fast spinner here, but at least I'm not over there ->").Run()
}
(Unrelated to this issue, but I've only been using Go for ~3 weeks, if my examples are weird or I'm misusing contexts, please let me know :) )
Environment
My example gif was recorded using vhs on an M2 Macbook Air running Sonoma 14.2.1, but I've also been able to replicate this on Windows 10 machines.
Activity