Documentation
¶
Overview ¶
Package paneframe is the presentation half of the pane tree: the chrome one placed leaf wears, the handle one split draws, and the compositor that turns a panelayout.Layout into cells. internal/panelayout owns structure and geometry and knows nothing about rendering; this package owns rendering and knows nothing about terminals, documents, issues, or persistence.
It exists so the project workspace preview and the global Workspaces browser ("Sessions") compose panes through one code path. Every windowing behaviour a user can see — per-leaf borders, focus and interactive chrome, drag-handle hover and drag colours, the widened divider hit target, the order regions are registered in — is decided here once and is therefore the same on both surfaces by construction. A change made to one workspace's windowing that does not land in the other is a bug in this package's callers, not a feature.
Index ¶
- Constants
- func ChromeFloors(content panelayout.Floors) panelayout.Floors
- func ChromeFloorsFor(content panelayout.Floors, chrome func(panelayout.Kind) Chrome) panelayout.Floors
- func Compose(host Host, layout panelayout.Layout, canvas Box, width, height int) string
- func ComposeLeaf(host Host, placement panelayout.Placement, zoomed bool) string
- func FocusHeldOutsidePanes() bool
- func FocusLeafAt(host Host, x, y int) bool
- func HandleStateFor(splitID int, dragging bool, dragSplitID int, hovering bool, hoverSplitID int) ui.HandleState
- func LeafAt(layout panelayout.Layout, x, y int) *panelayout.Node
- func LeafAtForHost(host Host, layout panelayout.Layout, x, y int) *panelayout.Node
- func RegisterRegions(sink RegionSink, host Host, layout panelayout.Layout)
- func RenderContent(host Host, node *panelayout.Node, inner Box, zoomed bool) string
- func RenderDividerHandle(divider panelayout.Divider, state ui.HandleState) string
- func SetFocusHeldOutsidePanes(held bool)
- func WrapLeaf(content string, outer Box, chrome Chrome) string
- type Box
- type Chrome
- type Content
- type Geom
- type Host
- type RegionSink
- type Render
- type Size
Constants ¶
const ( // BorderWidth is the left plus right border, one column each. BorderWidth = 2 // PaddingWidth is the left plus right padding, one column each. PaddingWidth = 2 // Overhead is the total columns a panel spends on chrome. Overhead = BorderWidth + PaddingWidth // ContentInset is the columns chrome spends on the left alone. ContentInset = Overhead / 2 // BorderRows is the panel's top border row; the bottom costs the same, which // is why the height subtraction below is BorderWidth rather than BorderRows. BorderRows = 1 // HeaderRows is the single row every leaf reserves for its tab strip and // close button, read from the shared presentation layer so a terminal leaf // and a document leaf put their bodies on the same relative row. HeaderRows = termpreview.HeaderRows )
Chrome constants are what one RenderPanel costs a leaf. Layout hands out OUTER boxes; a content draws into the INNER box these describe.
Variables ¶
This section is empty.
Functions ¶
func ChromeFloors ¶
func ChromeFloors(content panelayout.Floors) panelayout.Floors
ChromeFloors adds each leaf's own chrome budget to a set of content floors, so a tree only claims to fit when every leaf has room for its border as well as its content. Callers state the minimum a content needs; the frame knows what it costs to draw one.
func ChromeFloorsFor ¶ added in v1.2.0
func ChromeFloorsFor(content panelayout.Floors, chrome func(panelayout.Kind) Chrome) panelayout.Floors
ChromeFloorsFor adds the budget required by each kind's selected chrome. A nil selector means every kind is framed. This keeps fit decisions aligned with GeometryForChrome when a host deliberately embeds an already-composed, borderless surface beside ordinary framed leaves.
func Compose ¶
Compose draws every leaf and divider of an already-laid-out tree onto the box layout gave it. The caller lays out first so it can inspect Layout.Zoomed before anything is rendered — composing a leaf sizes its content, which is a side effect a surface that is about to decline the frame must not pay.
Joining rendered blocks back together instead would re-derive that geometry in string space at every level of nesting, and the levels only have to disagree by a cell for a divider to walk sideways. canvas is the surface-local OUTER rectangle the tree was laid out in, and width/height are the returned block's size: the canvas rectangle in production, a smaller viewport in tests.
func ComposeLeaf ¶
func ComposeLeaf(host Host, placement panelayout.Placement, zoomed bool) string
ComposeLeaf draws one placed leaf's content in its INNER box and wraps the OUTER box in this surface's chrome. placement.Box is surface-local OUTER.
Sizing inside a frame is what the document viewer already required, and both contents answer nil: a live terminal is resized from the state change that moved its box, not from a render. A content that does answer one is asserting geometry beyond this process, and a render has nothing to dispatch it with, so the frame hands it to the host for the next update rather than dropping it.
func FocusHeldOutsidePanes ¶ added in v1.2.0
func FocusHeldOutsidePanes() bool
FocusHeldOutsidePanes reports the current signal.
func FocusLeafAt ¶
FocusLeafAt moves the surface's keyboard focus to the leaf under a pointer, and reports whether a leaf was there. It moves focus and nothing else: the event carries on to whichever region claimed it, so a press inside a terminal leaf still reaches the live pane and a press on a file row still selects it.
Focus is answered from GEOMETRY rather than from the region a press landed on, and that is the whole point. Which region consumes a press belongs to the content — a terminal leaf's presses are claimed by the live pane and forwarded to tmux, a diff leaf's by its file rows — so a surface that hung focus off those handlers needed one focus call per leaf kind and got the ring wrong for the kind nobody remembered. A leaf's box, by contrast, is something every leaf has, including kinds that do not exist yet.
func HandleStateFor ¶
func HandleStateFor(splitID int, dragging bool, dragSplitID int, hovering bool, hoverSplitID int) ui.HandleState
HandleStateFor resolves a split's handle state from the surface's pointer state. dragSplitID is the split a drag in progress owns (0 when the surface does not track one); hoverSplitID is the split the pointer is over.
func LeafAt ¶
func LeafAt(layout panelayout.Layout, x, y int) *panelayout.Node
LeafAt is the leaf whose OUTER box contains a surface-local point, or nil for a point on a divider's drag target, outside the canvas, or on nothing the tree placed.
Placement boxes never overlap, so at most one leaf can answer a point and the first match is the only match. Dividers are subtracted first because DividerHitBox deliberately reaches one cell into the leaf's border on each side, and that cell belongs to the handle: this is the same precedence RegisterRegions gives it by registering dividers after leaf bodies, said once so a pointer cannot resize past a pane and re-focus it in the same press.
func LeafAtForHost ¶ added in v1.2.0
func LeafAtForHost(host Host, layout panelayout.Layout, x, y int) *panelayout.Node
LeafAtForHost is LeafAt using the same chrome-aware divider targets that the host registered for the rendered frame.
func RegisterRegions ¶
func RegisterRegions(sink RegionSink, host Host, layout panelayout.Layout)
RegisterRegions puts one composed frame's targets into the sink in the one order that makes the visible thing the clickable thing. The order is the whole point of this function existing, so it is stated here once rather than re-derived per surface:
- Leaf bodies first: they are the fallback for scroll and focus.
- Dividers next, in layout order — each split before the splits inside it. Widened targets overlap once splits nest, and two can only overlap when one split encloses the other, because sibling subtrees are held apart by the divider between them. Registering the enclosing split first leaves the enclosed one last, and HitMap's reverse scan returns it for a point both claim.
- Tab strips next: they win the one cell a column divider reaches into a header, which is the cell a click on the leftmost tab lands on.
- Close buttons next: the X occupies the right edge the strip no longer claims, and a one-cell miss on a tab must not steal the close.
- Content-owned regions last, so they beat the tree divider and the leaf body drawn under them.
func RenderContent ¶
RenderContent draws one leaf's body into its INNER box, with no chrome around it, so the compose path never asks what kind of leaf it is drawing. A leaf with no content draws nothing and the canvas leaves its box blank, rather than shifting its neighbours into it. inner is surface-local, which is what turns the leaf's box into the rectangle a pointer is tested against.
func RenderDividerHandle ¶
func RenderDividerHandle(divider panelayout.Divider, state ui.HandleState) string
RenderDividerHandle draws one split's 1-cell drag handle in its own state.
func SetFocusHeldOutsidePanes ¶ added in v1.2.0
func SetFocusHeldOutsidePanes(held bool)
SetFocusHeldOutsidePanes tells the frame that an app-level surface outside every pane tree owns the keyboard. It is an alias for the shared signal: the shell sets it once, around the content render, and both pane surfaces and every other plugin inherit it.
func WrapLeaf ¶
WrapLeaf draws content inside one leaf's OUTER box. Content bytes are never dimmed; only the border states change.
The chrome the caller asks for is passed through EffectiveChrome first, so a surface cannot draw a focused leaf while an app-level surface outside every pane tree holds the keyboard. Applying it here rather than in each Host is what makes exactly-one-focused-pane an app-wide property: every focused border on both surfaces, including the lone-preview frame that never goes through Compose, is painted by this function.
Types ¶
type Box ¶
type Box = termpreview.Box
Box is the pane tree's rectangle. Layout places it; this package draws in it.
func DividerHitBox ¶
func DividerHitBox(divider panelayout.Divider) Box
DividerHitBox widens a 1-cell divider into the forgiving target a pointer is actually tested against: the divider plus one cell of the leaf on each side, on both axes.
What that cell is, is why this is safe. Layout places OUTER boxes with the divider in the gap between them, so the cell either side is a leaf's own border — never its header row, which sits one cell further in. A header's tabs and close button are therefore never masked, and the two axes can behave the same way. (They did not always: before every leaf wore its own chrome, a row divider sat directly against the lower leaf's header and could only widen upward.)
Tab and close targets are registered after dividers regardless, so even an overlap would resolve to the header. This keeps the pointer from having to be exact in the first place.
func DividerHitBoxFor ¶ added in v1.2.0
func DividerHitBoxFor(host Host, layout panelayout.Layout, divider panelayout.Divider) Box
DividerHitBoxFor widens a divider only into neighbouring framed chrome. A borderless leaf owns every cell in its placement, so taking its edge column or row would steal a real content target. When a nested divider touches more than one leaf on a side, every touching leaf must be framed before that side contributes the one-cell resize margin.
type Chrome ¶
type Chrome int
Chrome is the border a leaf wears. It is a reader of focus, not a decision a content makes: a leaf that chose its own border could disagree with the leaf beside it about which one of them has the keyboard.
const ( // ChromeIdle is a leaf that does not own the surface's focus. ChromeIdle Chrome = iota // ChromeActive is the focused leaf's border. ChromeActive // ChromeInteractive is the focused terminal leaf while the user is typing // into the live pane. ChromeInteractive // ChromeFlash is the focused terminal leaf's attention flash. ChromeFlash // ChromeNone leaves the placed outer box unframed. Its content receives the // whole box, so an already-composed primary surface can sit beside framed // passive leaves without acquiring a second, visually nested perimeter. ChromeNone )
func EffectiveChrome ¶ added in v1.2.0
EffectiveChrome is the border a leaf actually wears once app-level focus is accounted for: the surface's own answer, or the idle border when focus is held outside the pane trees. WrapLeaf applies it, so a surface never has to call this; it is exported so a caller that needs to reason about the drawn state reads the same rule the renderer used.
type Content ¶
type Content interface {
// Kind is the stable persistence key and registry key for this content.
Kind() string
// Title is the content's identity for a header row.
Title() string
// SetSize gives the content its box. The command is how a content asserts
// geometry it owns beyond this process, such as a live tmux pane.
SetSize(Size) tea.Cmd
// View draws exactly Size.Height rows of exactly Size.Width columns.
View(Render) string
}
Content is what one pane-tree leaf shows. The tree places boxes and this package composes them; neither learns what is inside one. A bottom-relative offset, a freeze, a tmux geometry lease are the content's business alone — the structure layer never sees a *tty.Model.
The contract is four methods on purpose. Capability beyond it — update, focus, keys, pointers, scrolling, persistence — arrives as an optional interface when its first real implementation does, not before: a document leaf has no native cursor and no transport to gate, and a mandatory method invites a wrong stub.
type Geom ¶
Geom is one leaf's chrome versus its content. Layout places Outer; tmux, the native cursor, tab hits, and content hits all use Inner.
func GeometryForChrome ¶ added in v1.2.0
GeometryForChrome pairs a placed box with the content box implied by its chrome. Borderless content owns the whole placement; every framed state uses the shared panel inset.
type Host ¶
type Host interface {
// Content adapts a leaf to the content contract. A leaf whose content is
// gone answers nil, and the canvas leaves its box blank rather than letting a
// neighbour spread into it.
Content(node *panelayout.Node) Content
// Chrome is the border this leaf wears, given the surface's focus state.
Chrome(node *panelayout.Node) Chrome
// Focus is the leaf ID that owns the surface's keyboard focus.
Focus() int
// SetFocus gives one leaf the surface's keyboard focus. It is the write half
// of Focus, and it exists so the two halves cannot be different values: the
// ring is drawn from Focus, a pointer moves it through SetFocus, and a
// surface has no third place to record "who is being typed into". A surface
// whose live terminal holds the keyboard separately must give it up here —
// focus that has moved off a leaf and keys that have not is precisely the
// divergence this pair is for.
SetFocus(node *panelayout.Node)
// Layout is the pane tree as the surface last DREW it — the same placement
// Compose and RegisterRegions were driven with — so the frame can answer
// which leaf a screen point belongs to. It must be false whenever the tree
// is not what is on screen. Answering geometry the surface could place but
// did not draw hands out phantom leaf boxes to whatever replaced the tree,
// and a pointer then focuses panes the user cannot see.
Layout() (panelayout.Layout, bool)
// HandleState is the pointer state of one split's drag handle.
HandleState(splitID int) ui.HandleState
// QueueSizeCmd takes a command a content returned from SetSize. A render has
// no runtime to dispatch one with, so the surface holds it for the next
// update rather than dropping it.
QueueSizeCmd(tea.Cmd)
}
Host is everything a surface answers about its own pane tree that the frame cannot work out for itself. It is deliberately small: the frame asks what is in a leaf, which border it wears, who has focus, and what state a handle is in — never what kind of thing a leaf is or how the surface stores it.
Both the project workspace plugin and the global Workspaces browser implement it, which is what makes their windowing the same behaviour rather than two behaviours that happen to look alike.
type RegionSink ¶
type RegionSink interface {
// Leaf covers a whole leaf, OUTER, and is the lowest-priority target.
Leaf(node *panelayout.Node, outer Box)
// Divider is one split's widened drag target.
Divider(splitID int, hit Box)
// Tabs is a leaf's header tab strip, in its chrome-aware content box.
Tabs(node *panelayout.Node, inner Box)
// Close is a leaf's header X, in its chrome-aware content box.
Close(node *panelayout.Node, inner Box)
// Body is anything a leaf's content owns inside its own box — a diff list
// divider, a file row — in its chrome-aware content box. It registers last
// so it beats everything the frame put down.
Body(node *panelayout.Node, inner Box)
}
RegionSink is where a surface puts the hit regions one composed frame earns. The frame decides the ORDER; the surface decides the region IDs and payloads, because those are its own mouse vocabulary.
type Render ¶
type Render struct {
// Focused is true when this leaf owns the preview's keyboard focus.
Focused bool
// Zoomed is true when the box could not hold the whole tree and this leaf
// was given all of it.
Zoomed bool
// Origin is the leaf's INNER box in surface-local coordinates, which is what
// hit math needs; the size handed to SetSize is content-local.
Origin mouse.Rect
}
Render is what the frame knows about a placed leaf and the content does not. It carries no theme: styles are process-global in internal/styles, so a content reads them there rather than through a copy that can go stale.