Skip to main content

Module layout

Module layout 

Source
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§

LayoutObservers
Two-channel observer the layout engine threads through every render entry point per ADR-0026. warn is required (the engine uses it for segment-render error diagnostics); on_decision is optional and receives a typed LayoutDecision per emit site.

Enums§

LayoutDecision
Event emitted by the layout engine when it takes one of five decisions under width pressure. The id field on every variant is borrowed from [crate::segments::LineItem::Segment.id] (per ADR-0026); built-in segment ids carry as Cow::Borrowed so the production path stays allocation-free.

Functions§

render
Render items for ctx within terminal_width cells. Returns the final line without a trailing newline. Segment render errors go through crate::lsm_error! so a broken segment always surfaces, even under LINESMITH_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 use render_with_observers with their own observers).
render_to_runs
Render items into a flat StyledRun sequence. 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 — match render / render_with_observers exactly; only the emit form differs.
render_with_observers
Same as render but routes segment render-error diagnostics (and LayoutDecision events, when an observer is attached) through observers, and emits ANSI SGR around each segment per theme and capability. Used by crate::run_with_context so cli_main tests can capture segment errors alongside exit codes while the render path picks up theme colors.
runs_to_ansi
Emit a flat StyledRun sequence as an ANSI SGR-wrapped string suitable for terminal stdout. Each run with non-empty styling gets its own sgr_open / sgr_reset pair so decorations don’t leak across boundaries; plain runs pass through unwrapped. When hyperlinks is true, runs carrying Style.hyperlink are 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 = false drops the URL silently — the run still emits, just without the link.