vcom/internal/tui/help.go
vrubelroman 40b8722d58 feat(tui): App skeleton with mode machine, async navigation and effects (6.1.5)
The new UI's root model: Screen x viewer focus x native selection x
filter edit x modal stack, one inputOwner, keys resolved through the
registry, an action table that features extend from register_*.go.
Directory reads and previews run in Cmds with tickets: Update never
blocks (N-P1-1), stale results are dropped (U-P1-13), failed navigation
keeps the panel and a vanished directory climbs up (U-P1-8). q closes
layers before asking to quit (U-P1-16), PgDn pages (U-P1-6), the theme
list previews live and saves with config.SetKey. Mouse mode is
reconciled after every Update; View only reads state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 09:11:39 +03:00

61 lines
1.4 KiB
Go

package tui
import (
"fmt"
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
"vcom/internal/tui/keys"
"vcom/internal/tui/modal"
)
// openHelp shows the bindings of the context that owned input, generated
// from the registry (design §7.4).
func (a *App) openHelp() tea.Cmd {
ctx := a.inputOwner()
var lines []string
for i, s := range a.keys.Help(ctx) {
if i > 0 {
lines = append(lines, "")
}
lines = append(lines, "── "+s.Title+" ──")
w := 0
for _, it := range s.Items {
w = max(w, ansi.StringWidth(it.Keys))
}
for _, it := range s.Items {
lines = append(lines, fmt.Sprintf(" %s%s %s", it.Keys, strings.Repeat(" ", w-ansi.StringWidth(it.Keys)), it.Help))
}
}
a.openModal(modal.NewText("Help: "+contextTitle(ctx), lines), nil)
return nil
}
func contextTitle(c keys.Context) string {
switch c {
case keys.CtxBrowse:
return "panels"
case keys.CtxInfo:
return "info"
case keys.CtxViewScroll:
return "viewer"
}
return c.String()
}
// openLog is "L": the message log, newest last.
func (a *App) openLog() tea.Cmd {
var lines []string
for _, n := range a.notes.Log() {
lines = append(lines, fmt.Sprintf("%s %-5s %s", n.At.Format("15:04:05"), n.Level, n.Text))
}
if len(lines) == 0 {
lines = []string{"(no messages)"}
}
l := modal.NewText("Messages", lines)
a.openModal(l, nil)
l.Key(keys.ModalEnd, tea.KeyMsg{})
return nil
}