Skip to main content

Crate linesmith_core

Crate linesmith_core 

Source
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 in docs/specs/config.md.
data_context
Shared data-access context threaded through every segment’s render call.
input
StatusContext is 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 on DataContext::usage() and are not parsed from stdin; see docs/specs/input-schema.md for the full contract.
layout
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.
logging
In-crate structured-logging facade.
plugins
Plugin runtime bridge layer.
presets
Embedded config.toml presets per docs/specs/config.md §Presets.
runtime
Runtime predicates that both the CLI driver and the doctor must agree on. Lifted out of driver.rs so 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; the format! 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=off still 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_width minus any padding, and the process cwd. Distinct from segments::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 COLUMNS env var, then DEFAULT_TERMINAL_WIDTH. A set-but-invalid COLUMNS value routes through lsm_warn! so the user can correct their config; an unset COLUMNS falls 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 to writer. Parse failures render a ? marker to writer and 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 DataContext so every line sees the same data snapshot. Empty inner slices still emit a writeln!() — 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 to writer; only stdin/stdout I/O failures surface as errors.
run_with_segments_and_width
Full-control entry: pre-built LineItem list 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 by cli_main), call run_with_context instead.
run_with_width
Same as run but with an explicit terminal width. Exposed so callers with their own width source (tests, a TUI wrapper) can bypass detect_terminal_width.