Files
nib-v1/internal/tui/statusbar.go
T
lerko e20fae3543 feat(tui): add broot-style tab affordances to header and footer
Header now renders stream/cards as tabs with keybindings inline —
active tab highlighted, inactive shows the key to switch. Footer
shows a capture tab affordance when in list state. Redundant mode
and capture hints removed from the context hint bar.
2026-05-20 11:16:58 -04:00

102 lines
2.8 KiB
Go

package tui
import (
"fmt"
"strings"
"github.com/charmbracelet/lipgloss"
)
type hint struct {
key string
desc string
}
func renderHints(hints []hint) string {
parts := make([]string, len(hints))
for i, h := range hints {
parts[i] = hintKeyStyle.Render(h.key) + " " + hintDescStyle.Render(h.desc)
}
return strings.Join(parts, " ")
}
func renderTab(label, key string, active bool) string {
if active {
return hintKeyStyle.Render(label) + " " + hintDescStyle.Render(key)
}
return hintDescStyle.Render(label) + " " + hintKeyStyle.Render(key)
}
func renderStatusBar(m model, width int) string {
var leftParts []string
if m.state == stateList {
leftParts = append(leftParts, renderTab("capture", "a", false))
}
if m.status != "" {
leftParts = append(leftParts, statusStyle.Render(m.status))
} else {
leftParts = append(leftParts, statusStyle.Render(countText(m)))
}
leftRendered := strings.Join(leftParts, " "+separatorStyle.Render("│")+" ")
right := renderHints(contextHints(m))
gap := width - lipgloss.Width(leftRendered) - lipgloss.Width(right)
if gap < 0 {
gap = 0
}
pad := lipgloss.NewStyle().Width(gap).Render("")
return leftRendered + pad + right
}
func countText(m model) string {
var total int
if m.mode == modeCards {
total = len(m.cards.filtered)
} else {
total = len(m.list.displayEntities())
}
if m.filterTag != "" {
return fmt.Sprintf("%d entities #%s", total, m.filterTag)
}
return fmt.Sprintf("%d entities", total)
}
func contextHints(m model) []hint {
switch m.state {
case stateDetail:
switch m.detail.mode {
case detailRun:
return []hint{{"space", "toggle"}, {"j/k", "nav"}, {"r", "reset"}, {"esc", "save+exit"}}
case detailFill:
return []hint{{"tab", "next"}, {"⇧tab", "prev"}, {"enter", "copy"}, {"esc", "cancel"}}
default:
return []hint{{"p", "promote"}, {"D", "demote"}, {"c", "copy"}, {"e", "edit"}, {"r", "run"}, {"f", "fill"}, {"!", "pin"}, {"esc", "back"}}
}
case stateInput:
return nil
case stateTagFilter:
return []hint{{"j/k", "nav"}, {"enter", "select"}, {"esc", "cancel"}}
case stateConfirm:
return []hint{{"y", "confirm"}, {"n", "cancel"}}
case statePromote:
return []hint{{"j/k", "nav"}, {"enter", "select"}, {"esc", "cancel"}}
case stateAbsorb:
return []hint{{"j/k", "nav"}, {"enter", "absorb"}, {"esc", "cancel"}}
default:
if m.splitDetail {
if m.focus == focusDetail {
return []hint{{"h", "list"}, {"c", "copy"}, {"e", "edit"}, {"p", "promote"}, {"D", "demote"}, {"!", "pin"}, {"esc", "back"}}
}
return []hint{{"l", "detail"}, {"d", "del"}, {"#", "filter"}, {"esc", "close"}, {"?", "help"}, {"q", "quit"}}
}
if m.mode == modeCards {
return []hint{{"s", "sort"}, {"tab", "intent"}, {"?", "help"}, {"q", "quit"}}
}
return []hint{{"?", "search"}, {"m", "absorb"}, {"d", "del"}, {"#", "filter"}, {"?", "help"}, {"q", "quit"}}
}
}