feat: add TUI auto-refresh with configurable interval and manual refresh

Introduce background data refresh so the dashboard stays current without
restarting. This touches four layers:

Config (config.go):
- New TUIConfig struct with AutoRefresh (bool) and RefreshIntervalSec
  (int) fields, defaulting to enabled at 30-second intervals.
- Minimum interval floor of 10 seconds enforced at load time.

App core (app.go):
- RefreshDataMsg type for background refresh completion signaling.
- Auto-refresh state: interval timer, refreshing flag, lastRefresh
  timestamp. Checked on every tick; fires refreshDataCmd when elapsed.
- refreshDataCmd: background goroutine that loads session data via cache
  (with uncached fallback) and posts RefreshDataMsg on completion.
- Manual refresh keybind: 'r' triggers immediate refresh.
- Auto-refresh toggle keybind: 'R' toggles auto-refresh and persists
  the preference to config.toml.
- Help text updated with r/R keybind documentation.

Status bar (statusbar.go):
- Shows spinning refresh indicator during active refresh.
- Shows auto-refresh icon when auto-refresh is enabled.

Settings tab (tab_settings.go):
- Two new editable fields: Auto Refresh (bool) and Refresh Interval
  (seconds with 10s minimum).
- Settings display reads live App state to stay consistent with the
  R toggle keybind (avoids stale config-file reads).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
teernisse
2026-02-23 09:36:38 -05:00
parent 5b9edc7702
commit 93e343f657
4 changed files with 153 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ type Config struct {
ClaudeAI ClaudeAIConfig `toml:"claude_ai"`
Budget BudgetConfig `toml:"budget"`
Appearance AppearanceConfig `toml:"appearance"`
TUI TUIConfig `toml:"tui"`
Pricing PricingOverrides `toml:"pricing"`
}
@@ -48,6 +49,12 @@ type AppearanceConfig struct {
Theme string `toml:"theme"`
}
// TUIConfig holds TUI-specific settings.
type TUIConfig struct {
AutoRefresh bool `toml:"auto_refresh"`
RefreshIntervalSec int `toml:"refresh_interval_sec"`
}
// PricingOverrides allows user-defined pricing for specific models.
type PricingOverrides struct {
Overrides map[string]ModelPricingOverride `toml:"overrides,omitempty"`
@@ -72,6 +79,10 @@ func DefaultConfig() Config {
Appearance: AppearanceConfig{
Theme: "flexoki-dark",
},
TUI: TUIConfig{
AutoRefresh: true,
RefreshIntervalSec: 30,
},
}
}