vcom/internal/tui/status.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

98 lines
2.4 KiB
Go

package tui
import (
"fmt"
"strings"
"github.com/charmbracelet/x/ansi"
"vcom/internal/tui/notify"
"vcom/internal/tui/viewer"
)
// modeBadge names the mode shown at the left of the status line.
func (a *App) modeBadge() string {
switch {
case a.nativeSelect:
return "SELECT"
case a.filter != nil:
return "FILTER"
case a.viewer.Focus == viewer.Visual && a.screen != ScreenBrowse:
return "VISUAL"
case a.viewer.Focus == viewer.Caret && a.screen != ScreenBrowse:
return "CARET"
case a.screen == ScreenView:
return "VIEW"
case a.screen == ScreenInfo:
return "INFO"
}
return ""
}
// statusLine: mode badge and current note on the left; jobs and the
// connection state of the active panel on the right (design §7.6).
func (a *App) statusLine() string {
st := a.styles
w := a.layout.Status.W
var left strings.Builder
if b := a.modeBadge(); b != "" {
left.WriteString(st.Badge.Render(b))
left.WriteString(st.Status.Render(" "))
}
if n, ok := a.notes.Current(); ok {
s := st.NoteInfo
switch n.Level {
case notify.Success:
s = st.NoteOK
case notify.Warn:
s = st.NoteWarn
case notify.Error:
s = st.NoteError
}
left.WriteString(s.Render(n.Text))
} else if e, ok := a.Active().Selected(); ok && !e.Parent {
left.WriteString(st.Status.Render(e.Name))
}
var right []string
if jobs := a.activeJobs(); len(jobs) > 0 {
j := jobs[0]
pct := ""
if t := j.Progress.BytesTotal; t > 0 {
pct = fmt.Sprintf(" %d%%", j.Progress.BytesDone*100/t)
}
r := fmt.Sprintf("⟳ %s%s", j.Title, pct)
if len(jobs) > 1 {
r += fmt.Sprintf(" · +%d", len(jobs)-1)
}
right = append(right, r)
}
if b := a.Active().Badge; b != "" {
right = append(right, b)
}
r := st.Status.Render(strings.Join(right, " "))
rw := ansi.StringWidth(r)
l := ansi.Truncate(left.String(), max(0, w-rw-1), "…")
gap := max(0, w-ansi.StringWidth(l)-rw)
return l + st.Status.Render(strings.Repeat(" ", gap)) + r
}
// footerLine lists the footer bindings of the context owning input.
func (a *App) footerLine() string {
st := a.styles
w := a.layout.Footer.W
var b strings.Builder
used := 0
for _, it := range a.keys.Footer(a.inputOwner()) {
k := st.FooterKey.Render(it.Keys)
h := st.Footer.Render(" " + it.Help + " ")
n := ansi.StringWidth(k) + ansi.StringWidth(h)
if used+n > w {
break
}
b.WriteString(k)
b.WriteString(h)
used += n
}
return b.String() + st.Footer.Render(strings.Repeat(" ", max(0, w-used)))
}