charmbracelet / bubbles

TUI components for Bubble Tea 🫧
MIT License
5.51k stars 265 forks source link

Timer component #22

Closed CamiloGarciaLaRotta closed 3 years ago

CamiloGarciaLaRotta commented 3 years ago

👋🏽 hi, awesome work on the whole bubbletea framework!

What

I was wondering what would be the tea semantic way to incorporate a timer into a tea application. I want the app to display the time that is left and for the it to exit gracefully once the timer is done.

I looked under the hood of the Spinner, given that it ticks at at regular interval, as a base for a ticker component. I spotted the tea.Tick function which looks promising.

meowgorithm commented 3 years ago

Yep, you’re exactly right: tea.Tick is what you’re looking for. I just added a countdown example to illustrate your use case. There are lots of other ways you could model this, too.

If you wanted to synchronize the timer with the system clock you could also use tea.Every.

Thanks for the kind words about Bubble Tea!

meowgorithm commented 3 years ago

Reopening this, actually, as a timer component may make sense for the library.