feat: overhaul TUI dashboard with subscription data, new tabs, and setup wizard
Major rewrite of the Bubble Tea dashboard, adding live claude.ai integration and splitting the monolithic app.go into focused tab modules. App model (app.go): - Integrate claudeai.Client for live subscription/rate-limit data - Add SubDataMsg and async fetch with periodic refresh (every 5 min) - Add spinner for loading states (charmbracelet/bubbles spinner) - Integrate huh form library for in-TUI setup wizard - Rework tab routing to dispatch to dedicated tab renderers - Add compact layout detection for narrow terminals (<100 cols) TUI setup wizard (setup.go): - Full huh-based setup flow embedded in the TUI (not just CLI) - Three-step form: credentials, preferences (time range + theme), confirm - Pre-populates from existing config, validates session key prefix - Returns to dashboard on completion with config auto-saved New tab modules: - tab_overview.go: summary cards (sessions, prompts, cost, time), daily activity sparkline, rate-limit progress bars from live subscription data - tab_breakdown.go: per-model usage table with calls, input/output tokens, cost, and share percentage; compact mode for narrow terminals - tab_costs.go: cost analysis with daily cost chart, model cost breakdown, cache efficiency metrics, and budget tracking with progress bar Rewritten tabs: - tab_sessions.go: paginated session browser with sort-by-cost/tokens/time, per-session detail view, model usage breakdown per session, improved navigation (j/k, enter/esc, n/p for pages) - tab_settings.go: updated to work with new theme struct and config fields
This commit is contained in:
@@ -2,6 +2,7 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"cburn/internal/cli"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
|
||||
const (
|
||||
settingsFieldAPIKey = iota
|
||||
settingsFieldSessionKey
|
||||
settingsFieldTheme
|
||||
settingsFieldDays
|
||||
settingsFieldBudget
|
||||
@@ -56,13 +58,21 @@ func (a App) settingsStartEdit() (tea.Model, tea.Cmd) {
|
||||
if existing != "" {
|
||||
ti.SetValue(existing)
|
||||
}
|
||||
case settingsFieldSessionKey:
|
||||
ti.Placeholder = "sk-ant-sid..."
|
||||
ti.EchoMode = textinput.EchoPassword
|
||||
ti.EchoCharacter = '*'
|
||||
existing := config.GetSessionKey(cfg)
|
||||
if existing != "" {
|
||||
ti.SetValue(existing)
|
||||
}
|
||||
case settingsFieldTheme:
|
||||
ti.Placeholder = "flexoki-dark, catppuccin-mocha, tokyo-night, terminal"
|
||||
ti.SetValue(cfg.Appearance.Theme)
|
||||
ti.EchoMode = textinput.EchoNormal
|
||||
case settingsFieldDays:
|
||||
ti.Placeholder = "30"
|
||||
ti.SetValue(fmt.Sprintf("%d", cfg.General.DefaultDays))
|
||||
ti.SetValue(strconv.Itoa(cfg.General.DefaultDays))
|
||||
ti.EchoMode = textinput.EchoNormal
|
||||
case settingsFieldBudget:
|
||||
ti.Placeholder = "500 (monthly USD, leave empty to clear)"
|
||||
@@ -103,6 +113,8 @@ func (a *App) settingsSave() {
|
||||
switch a.settings.cursor {
|
||||
case settingsFieldAPIKey:
|
||||
cfg.AdminAPI.APIKey = val
|
||||
case settingsFieldSessionKey:
|
||||
cfg.ClaudeAI.SessionKey = val
|
||||
case settingsFieldTheme:
|
||||
// Validate theme name
|
||||
found := false
|
||||
@@ -162,10 +174,21 @@ func (a App) renderSettingsTab(cw int) string {
|
||||
}
|
||||
}
|
||||
|
||||
sessionKeyDisplay := "(not set)"
|
||||
existingSession := config.GetSessionKey(cfg)
|
||||
if existingSession != "" {
|
||||
if len(existingSession) > 16 {
|
||||
sessionKeyDisplay = existingSession[:12] + "..." + existingSession[len(existingSession)-4:]
|
||||
} else {
|
||||
sessionKeyDisplay = "****"
|
||||
}
|
||||
}
|
||||
|
||||
fields := []field{
|
||||
{"Admin API Key", apiKeyDisplay},
|
||||
{"Session Key", sessionKeyDisplay},
|
||||
{"Theme", cfg.Appearance.Theme},
|
||||
{"Default Days", fmt.Sprintf("%d", cfg.General.DefaultDays)},
|
||||
{"Default Days", strconv.Itoa(cfg.General.DefaultDays)},
|
||||
{"Monthly Budget", func() string {
|
||||
if cfg.Budget.MonthlyUSD != nil {
|
||||
return fmt.Sprintf("$%.0f", *cfg.Budget.MonthlyUSD)
|
||||
@@ -210,7 +233,7 @@ func (a App) renderSettingsTab(cw int) string {
|
||||
infoBody.WriteString(labelStyle.Render("Data directory: ") + valueStyle.Render(a.claudeDir) + "\n")
|
||||
infoBody.WriteString(labelStyle.Render("Sessions loaded: ") + valueStyle.Render(cli.FormatNumber(int64(len(a.sessions)))) + "\n")
|
||||
infoBody.WriteString(labelStyle.Render("Load time: ") + valueStyle.Render(fmt.Sprintf("%.1fs", a.loadTime.Seconds())) + "\n")
|
||||
infoBody.WriteString(labelStyle.Render("Config file: ") + valueStyle.Render(config.ConfigPath()))
|
||||
infoBody.WriteString(labelStyle.Render("Config file: ") + valueStyle.Render(config.Path()))
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString(components.ContentCard("Settings", formBody.String(), cw))
|
||||
|
||||
Reference in New Issue
Block a user