summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/tabs.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 08:32:39 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 08:32:39 +0200
commit9c400937d9e32f3ce85c668d9ca52c351f8b5d13 (patch)
tree90170eedda64c59a063c0010d1452f6b3e5d71f5 /internal/tui/dashboard/tabs.go
parentba7af922d289a9d0fff1c4ef33764b1852c774f6 (diff)
tui: add dashboard tab framework model
Diffstat (limited to 'internal/tui/dashboard/tabs.go')
-rw-r--r--internal/tui/dashboard/tabs.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/internal/tui/dashboard/tabs.go b/internal/tui/dashboard/tabs.go
new file mode 100644
index 0000000..d456b44
--- /dev/null
+++ b/internal/tui/dashboard/tabs.go
@@ -0,0 +1,103 @@
+package dashboard
+
+import (
+ "ior/internal/tui"
+ "strings"
+
+ "github.com/charmbracelet/lipgloss"
+)
+
+// Tab is a dashboard tab identifier.
+type Tab int
+
+const (
+ // TabOverview is the high-level summary tab.
+ TabOverview Tab = iota
+ // TabSyscalls is the syscall table tab.
+ TabSyscalls
+ // TabFiles is the file ranking tab.
+ TabFiles
+ // TabProcesses is the process breakdown tab.
+ TabProcesses
+ // TabLatency is the latency histogram tab.
+ TabLatency
+ // TabGaps is the inter-syscall gap tab.
+ TabGaps
+)
+
+var allTabs = []Tab{
+ TabOverview,
+ TabSyscalls,
+ TabFiles,
+ TabProcesses,
+ TabLatency,
+ TabGaps,
+}
+
+func (t Tab) String() string {
+ switch t {
+ case TabOverview:
+ return "Overview"
+ case TabSyscalls:
+ return "Syscalls"
+ case TabFiles:
+ return "Files"
+ case TabProcesses:
+ return "Processes"
+ case TabLatency:
+ return "Latency"
+ case TabGaps:
+ return "Gaps"
+ default:
+ return "Unknown"
+ }
+}
+
+func nextTab(tab Tab) Tab {
+ idx := tabIndex(tab)
+ return allTabs[(idx+1)%len(allTabs)]
+}
+
+func prevTab(tab Tab) Tab {
+ idx := tabIndex(tab)
+ if idx == 0 {
+ return allTabs[len(allTabs)-1]
+ }
+ return allTabs[idx-1]
+}
+
+func tabIndex(tab Tab) int {
+ for i, candidate := range allTabs {
+ if candidate == tab {
+ return i
+ }
+ }
+ return 0
+}
+
+func renderTabBar(active Tab, width int) string {
+ parts := make([]string, 0, len(allTabs))
+ for _, tab := range allTabs {
+ label := tab.String()
+ if tab == active {
+ parts = append(parts, tui.TabActiveStyle.Render(label))
+ } else {
+ parts = append(parts, tui.TabInactiveStyle.Render(label))
+ }
+ }
+
+ bar := lipgloss.JoinHorizontal(lipgloss.Left, parts...)
+ if width <= 0 {
+ return bar
+ }
+ return lipgloss.NewStyle().Width(width).Render(bar)
+}
+
+func renderHelpBar(keys tui.KeyMap) string {
+ parts := make([]string, 0, len(keys.DashboardShortHelp()))
+ for _, binding := range keys.DashboardShortHelp() {
+ help := binding.Help()
+ parts = append(parts, help.Key+" "+help.Desc)
+ }
+ return tui.HelpBarStyle.Render(strings.Join(parts, " • "))
+}