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>
92 lines
2.7 KiB
Go
92 lines
2.7 KiB
Go
package tui
|
|
|
|
import (
|
|
"vcom/internal/tui/geom"
|
|
"vcom/internal/tui/panel"
|
|
)
|
|
|
|
// Layout holds every screen rectangle. Rendering, mouse hit-tests and the
|
|
// image overlay use the same values (design §7.3).
|
|
type Layout struct {
|
|
W, H int
|
|
Panes [2]geom.Rect // empty when the pane is hidden (Info shows only the active one)
|
|
Preview geom.Rect // Info: the preview box (with border)
|
|
PreviewBody geom.Rect // inside the preview border
|
|
Viewer geom.Rect // View screen: full content area
|
|
Status geom.Rect
|
|
Footer geom.Rect
|
|
Screen geom.Rect // whole terminal (modals center in it)
|
|
}
|
|
|
|
// computeLayout splits the terminal for the current screen.
|
|
func computeLayout(w, h int, screen Screen, active int, footer bool, previewPct, gap int) Layout {
|
|
l := Layout{W: w, H: h, Screen: geom.Rect{W: w, H: h}}
|
|
bottom := 1
|
|
if footer && h >= 8 {
|
|
bottom = 2
|
|
}
|
|
l.Status = geom.Rect{X: 0, Y: h - bottom, W: w, H: 1}
|
|
if bottom == 2 {
|
|
l.Footer = geom.Rect{X: 0, Y: h - 1, W: w, H: 1}
|
|
}
|
|
body := geom.Rect{W: w, H: max(0, h-bottom)}
|
|
switch screen {
|
|
case ScreenView:
|
|
l.Viewer = body
|
|
case ScreenInfo:
|
|
pct := previewPct
|
|
if pct < 20 || pct > 80 {
|
|
pct = 50
|
|
}
|
|
pw := body.W * pct / 100
|
|
lw := body.W - pw
|
|
l.Panes[active] = geom.Rect{X: 0, Y: 0, W: lw, H: body.H}
|
|
l.Preview = geom.Rect{X: lw, Y: 0, W: pw, H: body.H}
|
|
l.PreviewBody = geom.Rect{X: lw + 1, Y: 2, W: max(0, pw-2), H: max(0, body.H-3)}
|
|
default:
|
|
gap = max(0, min(gap, 4))
|
|
lw := (body.W - gap) / 2
|
|
l.Panes[0] = geom.Rect{X: 0, Y: 0, W: lw, H: body.H}
|
|
l.Panes[1] = geom.Rect{X: lw + gap, Y: 0, W: body.W - lw - gap, H: body.H}
|
|
}
|
|
return l
|
|
}
|
|
|
|
// paneAt returns the pane whose rectangle contains (x, y).
|
|
func (l Layout) paneAt(x, y int) (int, bool) {
|
|
for i, r := range l.Panes {
|
|
if !r.Empty() && r.Contains(x, y) {
|
|
return i, true
|
|
}
|
|
}
|
|
return 0, false
|
|
}
|
|
|
|
// listRect is the rows area of pane i given its filter state.
|
|
func (a *App) listRect(i int) geom.Rect {
|
|
return panel.ListRect(a.layout.Panes[i], a.filterRow(i))
|
|
}
|
|
|
|
func (a *App) filterRow(i int) bool {
|
|
return a.panels[i].Filter() != "" || (a.filter != nil && i == a.active)
|
|
}
|
|
|
|
// relayout recomputes the layout and tells panels and the viewer their
|
|
// sizes. Called after every Update (cheap) so View stays pure.
|
|
func (a *App) relayout() {
|
|
c := a.deps.Config.UI
|
|
a.layout = computeLayout(a.w, a.h, a.screen, a.active, c.ShowFooter, c.PreviewWidthPercent, c.PaneGap)
|
|
for i, p := range a.panels {
|
|
r := a.layout.Panes[i]
|
|
if r.Empty() {
|
|
r = a.layout.Panes[a.active]
|
|
}
|
|
p.SetRows(panel.ListRect(r, a.filterRow(i)).H)
|
|
}
|
|
switch a.screen {
|
|
case ScreenView:
|
|
a.viewer.SetRows(a.layout.Viewer.H - 1)
|
|
case ScreenInfo:
|
|
a.viewer.SetRows(a.layout.PreviewBody.H)
|
|
}
|
|
}
|