feat: implement auto-polling in cli
This commit is contained in:
@@ -28,13 +28,23 @@ type model struct {
|
||||
height int
|
||||
}
|
||||
|
||||
type tickMsg time.Time
|
||||
|
||||
func tick() tea.Cmd {
|
||||
return tea.Tick(5*time.Second, func(t time.Time) tea.Msg {
|
||||
return tickMsg(t)
|
||||
})
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return fetchServices
|
||||
return tea.Batch(fetchServices, tick())
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
switch msg := msg.(type) {
|
||||
case tickMsg:
|
||||
return m, tea.Batch(fetchServices, tick())
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "esc", "q", "ctrl+c":
|
||||
|
||||
Reference in New Issue
Block a user