-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: simple timer component #67
Conversation
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
one thing that comes to mind now is: should we have an "increasing timer" as well? if so, maybe this component should be called |
This is cool!
It would also be useful to allow for a custom decrement value, so you could do something like: m := Timer{
Timeout: time.Millisecond * 250,
TickEvery: time.Millisecond, // or maybe it's called Decrement?
} …and then maybe if the decrement value is Otherwise, |
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
agreed, made the changes... view actually returns the time remaining because on update we do an example usage now looks like: package main
import (
"fmt"
"os"
"time"
"github.com/charmbracelet/bubbles/timer"
tea "github.com/charmbracelet/bubbletea"
)
type model struct {
timer timer.Model
}
func (m model) Init() tea.Cmd {
return m.timer.Init()
}
func (m model) View() string {
return "Will exit in " + m.timer.View()
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
case timer.TimeoutMsg:
return m, tea.Quit
}
var cmd tea.Cmd
m.timer, cmd = m.timer.Update(msg)
return m, cmd
}
func main() {
m := model{
timer: timer.New(3*time.Second),
}
if err := tea.NewProgram(m).Start(); err != nil {
fmt.Println("Oh no, it didn't work:", err)
os.Exit(1)
}
} |
LGTM! |
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
* feat: simple timer component Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
closes #22
A simple timer component:
tea.Cmd
Simplest possible usage example:
let me know what you think