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.

Functions§

render
Render segments 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_warn with their own closure).
render_to_runs
Render segments into a flat StyledRun sequence. One run per surviving segment, plus one run per non-empty inter-segment separator (in render order). Layout decisions — priority-drop, shrink_to_fit, truncatable reflow, width-bound truncation — match render / render_with_warn exactly; only the emit form differs.
render_with_warn
Same as render but routes segment render-error diagnostics through warn 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.