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 | |
| 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')
| -rw-r--r-- | internal/tui/dashboard/model.go | 22 | ||||
| -rw-r--r-- | internal/tui/dashboard/tabregistry.go | 25 |
2 files changed, 21 insertions, 26 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{} }) } diff --git a/internal/tui/dashboard/tabregistry.go b/internal/tui/dashboard/tabregistry.go index 801ecab..76fa216 100644 --- a/internal/tui/dashboard/tabregistry.go +++ b/internal/tui/dashboard/tabregistry.go @@ -40,8 +40,9 @@ type tabDescriptor struct { // InitCmd is an optional extra Bubble Tea command to start alongside the // global refresh tick when this tab is the active tab on Init. Tabs that // need their own high-frequency tick (stream, flame) set this; others leave - // it nil. - InitCmd func() tea.Cmd + // it nil. The model is passed so the closure can use the configured + // fastRefreshEvery interval rather than a hardcoded constant. + InitCmd func(*Model) tea.Cmd // Render draws the tab body. Nil means the tab has no registered renderer // (used for tabs that handle rendering via other paths). Render tabRenderFn @@ -64,10 +65,12 @@ var tabDescriptors = map[Tab]tabDescriptor{ ShortName: "Flm", Position: 10, AllowedVizModes: []tabVizMode{tabVizModeTable}, - InitCmd: flameTickCmdFn, - Render: tabRenderFlame, - HandleScroll: nil, - ShortcutKey: func(k common.KeyMap) key.Binding { return k.One }, + // Use the model method so the configured fastRefreshEvery interval + // is honoured on the very first tick, not just on subsequent ticks. + InitCmd: func(m *Model) tea.Cmd { return m.flameTickCmd() }, + Render: tabRenderFlame, + HandleScroll: nil, + ShortcutKey: func(k common.KeyMap) key.Binding { return k.One }, }, TabOverview: { Name: "Overview", @@ -119,10 +122,12 @@ var tabDescriptors = map[Tab]tabDescriptor{ ShortName: "Str", Position: 70, AllowedVizModes: []tabVizMode{tabVizModeTable}, - InitCmd: streamTickCmdFn, - Render: tabRenderStream, - HandleScroll: tabScrollStream, - ShortcutKey: func(k common.KeyMap) key.Binding { return k.Seven }, + // Use the model method so the configured fastRefreshEvery interval + // is honoured on the very first tick, not just on subsequent ticks. + InitCmd: func(m *Model) tea.Cmd { return m.streamTickCmd() }, + Render: tabRenderStream, + HandleScroll: tabScrollStream, + ShortcutKey: func(k common.KeyMap) key.Binding { return k.Seven }, }, } |
