| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "log" |
| 7 | "math/rand" |
| 8 | "time" |
| 9 | |
| 10 | "github.com/charmbracelet/huh/spinner" |
| 11 | ) |
| 12 | |
| 13 | func main() { |
| 14 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 15 | defer cancel() |
| 16 | |
| 17 | err := spinner.New(). |
| 18 | Context(ctx). |
| 19 | Action(func() { |
| 20 | time.Sleep(time.Minute) |
| 21 | }). |
| 22 | Accessible(rand.Int()%2 == 0). |
| 23 | Run() |
| 24 | if err != nil { |
| 25 | log.Fatalln(err) |
| 26 | } |
| 27 | fmt.Println("Done!") |
| 28 | } |