diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-14 08:27:02 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-14 08:27:02 +0300 |
| commit | 2bd75e2218cbc1544a8e4da374805a9853aeb385 (patch) | |
| tree | 46ab201f74322f8a7f307e046db92da3f538aee4 /internal/tui/dashboard/model.go | |
| parent | 17beb6ba6a739f7323288aeae673dd43f7ee50e5 (diff) | |
use configurable fastRefreshEvery for InitCmd on flame and stream tabs
Change tabDescriptor.InitCmd from func() tea.Cmd to func(*Model) tea.Cmd
so the initial tick for the flame and stream tabs uses the model's
fastRefreshEvery interval rather than hardcoded 200 ms constants.
Both call sites in Init() and postKeyTransitionCmd() now pass the model
pointer. The now-unused streamTickCmdFn/flameTickCmdFn package-level
adapters are removed; the TabFlame and TabStream registry entries use
inline closures that delegate to m.flameTickCmd()/m.streamTickCmd().
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/tui/dashboard/model.go')
| -rw-r--r-- | internal/tui/dashboard/model.go | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/internal/tui/dashboard/model.go b/internal/tui/dashboard/model.go index 2104cb6..1c6f66c 100644 --- a/internal/tui/dashboard/model.go +++ b/internal/tui/dashboard/model.go @@ -173,7 +173,9 @@ func (m Model) Init() tea.Cmd { cmds := []tea.Cmd{tickCmd(m.refreshEvery)} d := lookupTab(m.activeTab) if d.InitCmd != nil { - cmds = append(cmds, d.InitCmd()) + // Pass the model so the closure can read fastRefreshEvery and use + // the configured cadence rather than falling back to a constant. + cmds = append(cmds, d.InitCmd(&m)) } else if m.bubbleEnabledForTab(m.activeTab) { cmds = append(cmds, bubbleTickCmdFn()) } @@ -791,7 +793,9 @@ func (m Model) postKeyTransitionCmd(prevActiveTab Tab, cmd tea.Cmd) tea.Cmd { if prevActiveTab != m.activeTab { d := lookupTab(m.activeTab) if d.InitCmd != nil { - cmds = append(cmds, d.InitCmd()) + // Pass the model so the closure reads fastRefreshEvery and honours + // the configured cadence from the first tick after a tab switch. + cmds = append(cmds, d.InitCmd(&m)) } else if m.bubbleEnabledForTab(m.activeTab) { cmds = append(cmds, bubbleTickCmdFn()) } @@ -1530,20 +1534,6 @@ func (m Model) flameTickCmd() tea.Cmd { return tea.Tick(d, func(time.Time) tea.Msg { return flameTickMsg{} }) } -// streamTickCmdFn is a package-level adapter used by the tab registry's InitCmd -// field. It uses the constant cadence and is replaced on subsequent ticks by -// the model-method version that respects fastRefreshEvery. -func streamTickCmdFn() tea.Cmd { - return tea.Tick(streamRefreshMs*time.Millisecond, func(time.Time) tea.Msg { return streamTickMsg{} }) -} - -// flameTickCmdFn is a package-level adapter used by the tab registry's InitCmd -// field. It uses the constant cadence and is replaced on subsequent ticks by -// the model-method version that respects fastRefreshEvery. -func flameTickCmdFn() tea.Cmd { - return tea.Tick(flameRefreshMs*time.Millisecond, func(time.Time) tea.Msg { return flameTickMsg{} }) -} - func bubbleTickCmdFn() tea.Cmd { return tea.Tick(bubbleRefreshMs*time.Millisecond, func(time.Time) tea.Msg { return bubbleTickMsg{} }) } |
