Update() is not being called every "tick"
(I don't know if bubbletea uses the term tick, but I assume it, because the ELM model suggests so)
I have a weird issue: I wanted to have a blinking cursor in the filter input. This is my implementation:
func (m *FilterTable) getBlink() string {
m.blink = !m.blink
if m.blink {
return "_"
}
return " "
}
// Add some info to the footer
func (m *FilterTable) updateFooter() {
filter := ""
if m.Table.GetIsFilterInputFocused() {
filter = StyleFilter.Render(fmt.Sprintf("Enter filter [ESC: abort, Enter: finish]> %s%s",
m.Table.GetCurrentFilter(),
m.getBlink()))
} else if m.Table.GetIsFilterActive() {
filter = StyleFilter.Render(fmt.Sprintf("Filter: %s", m.Table.GetCurrentFilter()))
}
selected := m.Table.SelectedRows()
m.Table = m.Table.WithStaticFooter(
filter +
fmt.Sprintf(" selected rows: %d ", len(selected)) +
"| " + StyleHelpHint.Render(HelpFooter))
}
Now, when I start entering a filter using the / key, just an _ appears, it doesn't blink. Only after I start entering letters, the blinking happens.
I also tried it with a counter. It only increments once the first letter has been entered in filter mode.
What's also interesting: if I delete the already filter so that it's empty, the blinking continues. So it seems the filter being empty on startup doesn't seem to be the cause.
I am calling the updateFooter() function unconditionally in Update() - so on every tick as I assumed. But by the looks of it, Update() is just not being called regularly unless I enter the first filter letter. Maybe there are no ticks or there's some condition in bubble-table which causes this.
When are you calling Update generally? There's no inherent timer in Bubble Tea unless you've added one, so it will only be called on any events coming in such as keypresses, etc. I would suspect that if you type really fast, you'd see some quick blinks, but as it is I'd be surprised if it's blinking on its own without seeing the rest of the code.
No after the first change, it blinks on its own and not very fast. The code is here.