Expand description
Layout engine. Takes a list of Segments plus a StatusContext and
fits their renders into a terminal-width budget, dropping the
highest-priority (numerically largest) segments first — or, when a
segment opts in via truncatable, shrinking it to fit before drop.
Priority-0 segments are never dropped or truncated, even when that
overflows the budget.
See docs/specs/segment-system.md §Layout algorithm.
Structs§
- Layout
Observers - Two-channel observer the layout engine threads through every
render entry point per ADR-0026.
warnis required (the engine uses it for segment-render error diagnostics);on_decisionis optional and receives a typedLayoutDecisionper emit site.
Enums§
- Layout
Decision - Event emitted by the layout engine when it takes one of five
decisions under width pressure. The
idfield on every variant is borrowed from [crate::segments::LineItem::Segment.id] (per ADR-0026); built-in segment ids carry asCow::Borrowedso the production path stays allocation-free.
Functions§
- render
- Render
itemsforctxwithinterminal_widthcells. Returns the final line without a trailing newline. Segment render errors go throughcrate::lsm_error!so a broken segment always surfaces, even underLINESMITH_LOG=off— a blank statusline with zero diagnostic is a bad UX even when the user opted into quiet mode. Output is unstyled (callers that want theming userender_with_observerswith their own observers). - render_
to_ runs - Render
itemsinto a flatStyledRunsequence. One run per surviving segment, plus one run per non-empty surviving separator (in render order). Layout decisions — priority-drop,shrink_to_fit, truncatable reflow, width-bound truncation — matchrender/render_with_observersexactly; only the emit form differs. - render_
with_ observers - Same as
renderbut routes segment render-error diagnostics (andLayoutDecisionevents, when an observer is attached) throughobservers, and emits ANSI SGR around each segment perthemeandcapability. Used bycrate::run_with_contextsocli_maintests can capture segment errors alongside exit codes while the render path picks up theme colors. - runs_
to_ ansi - Emit a flat
StyledRunsequence as an ANSI SGR-wrapped string suitable for terminal stdout. Each run with non-empty styling gets its ownsgr_open/sgr_resetpair so decorations don’t leak across boundaries; plain runs pass through unwrapped. Whenhyperlinksistrue, runs carryingStyle.hyperlinkare additionally wrapped in OSC 8 open/close so capable terminals render them as clickable links; the OSC 8 wrap sits outside the SGR pair so the link survives the SGR reset.hyperlinks = falsedrops the URL silently — the run still emits, just without the link.