Expand description
linesmith-core: render engine + data context for the linesmith status line. Hosts the segment system, theming, layout, plugin host, config schema, and runtime predicates that both the CLI driver and the doctor consume.
run reads a JSON payload from a Read, renders a status line,
and writes the result to a Write. The linesmith-cli binary
crate wires this to stdin/stdout. See docs/specs/ for the
segment, theme, config, and plugin contracts.
Workspace-internal in v0.1 per ADR-0018; the public surface is free to refactor without SemVer cost until a publish decision lands (post-v1.0 at the earliest).
Re-exports§
pub use segments::builder::build_default_segments;pub use segments::builder::build_lines;pub use segments::builder::build_segments;
Modules§
- config
- User config: parse
config.toml, resolve its path, and apply per-segment overrides. Full contract indocs/specs/config.md. - data_
context - Shared data-access context threaded through every segment’s
rendercall. - input
StatusContextis the canonical, tool-agnostic model parsed from a statusline JSON payload (Claude Code today; per-tool normalizers are added as other tools wire in). Rate-limit windows live onDataContext::usage()and are not parsed from stdin; seedocs/specs/input-schema.mdfor the full contract.- layout
- Layout engine. Takes a list of
Segments plus aStatusContextand fits their renders into a terminal-width budget, dropping the highest-priority (numerically largest) segments first — or, when a segment opts in viatruncatable, shrinking it to fit before drop. Priority-0 segments are never dropped or truncated, even when that overflows the budget. - logging
- In-crate structured-logging facade.
- plugins
- Plugin runtime bridge layer.
- presets
- Embedded
config.tomlpresets perdocs/specs/config.md§Presets. - runtime
- Runtime predicates that both the CLI driver and the doctor must
agree on. Lifted out of
driver.rsso doctor can call them directly instead of mirroring them; every mirror is a drift opportunity vs. what the runtime actually does (the parity rule). - segments
- Segment trait and layout-intent types. Full contract lives in
docs/specs/segment-system.md; this module carries the subset the layout engine uses today: visibility, cell width, priority, separator preference, and theme role. - theme
- Role-based theme system. Segments declare semantic roles; themes map
roles to colors; the render path emits ANSI SGR around each segment
based on the terminal’s detected capability. Full contract in
docs/specs/theming.md.
Macros§
- lsm_
debug - Emit a debug-level diagnostic. Gated behind
LINESMITH_LOG=debug; theformat!call is skipped when suppressed. - lsm_
error - Emit a structural-failure diagnostic that bypasses the level gate.
Reserved for failures a user has no other way of seeing — segment
render errors, fatal plugin init, contract violations — so a user
who set
LINESMITH_LOG=offstill sees “the statusline broke.” - lsm_
warn - Emit a warning-level diagnostic. Fires at [
DEFAULT_LEVEL] and up.
Structs§
- RunContext
- CLI run-state bundle: theme + capability + terminal width + cwd.
Passed to
run_with_context; the CLI driver builds one from config (theme name), the color-policy precedence chain (CLI flags / env / config),CliEnv.terminal_widthminus any padding, and the process cwd. Distinct fromsegments::RenderContext, which is the per-segment-render layout state.
Functions§
- detect_
terminal_ width - Resolve the terminal width in cells. Prefers the OS-reported size, then
the
COLUMNSenv var, thenDEFAULT_TERMINAL_WIDTH. A set-but-invalidCOLUMNSvalue routes throughlsm_warn!so the user can correct their config; an unsetCOLUMNSfalls through silently (the common case when stdout is piped to Claude Code). - run
- Read a JSON payload from
reader, render a status line, and write it towriter. Parse failures render a?marker towriterand log detail to stderr; only I/O failures surface as errors. - run_
lines_ with_ context - Multi-line render entry. Each inner slice is one rendered line;
the layout algorithm runs independently per line with the full
terminal width budget. Stdin is parsed once into a shared
DataContextso every line sees the same data snapshot. Empty inner slices still emit awriteln!()— the user explicitly defined the line slot, so it stays in the output even if no segments rendered. - run_
with_ context - Full-control entry with injected stderr and explicit run context.
Parse failures render a
?marker towriter; only stdin/stdout I/O failures surface as errors. - run_
with_ segments_ and_ width - Full-control entry: pre-built
LineItemlist plus explicit width. Parse failures render a?marker and log to the real process stderr; output is unstyled. For themed output or injected-stderr testability (used bycli_main), callrun_with_contextinstead. - run_
with_ width - Same as
runbut with an explicit terminal width. Exposed so callers with their own width source (tests, a TUI wrapper) can bypassdetect_terminal_width.