Skip to main content

Crate linesmith

Crate linesmith 

Source
Expand description

linesmith: Rust status line for Claude Code and other AI coding CLIs.

run reads a JSON payload from a Read, renders a status line, and writes the result to a Write. The binary in main.rs wires this to stdin/stdout. See docs/specs/ for the segment, theme, config, and plugin contracts.

Modules§

cli
Command-line argument parsing via lexopt. Full flag surface and rationale live in docs/specs/config.md.
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 models the parsed Claude Code statusline JSON. Rate-limit windows, cost, vim state, effort, output-style, and agent fields are added as segments start consuming them; 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. Priority-0 segments are never dropped, even when that overflows the budget.
logging
In-crate structured-logging facade.
plugins
Rhai plugin runtime for user-authored segments.
presets
Embedded config.toml presets per docs/specs/config.md §Presets.
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§

CliEnv
Process-ambient inputs the CLI reads: env vars consulted by resolve_config_path, the color-policy env flags, an optional terminal-width override, and an optional color-capability override. Passed through cli_main so tests can drive the whole binary without touching the real process env. #[non_exhaustive] leaves room for future env vars (TERM, …) without breaking external construction.
RenderContext
Theme + capability + terminal width + cwd bundled for the render path. 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.

Functions§

build_default_segments
Build the default segment list: every built-in in canonical order, no overrides applied.
build_segments
Build a segment list from an optional Config. None or a config without a [line] section uses the default order. warn receives a one-line diagnostic for each validation rule triggered (pass |_| {} to discard).
cli_main
CLI entry point. Returns a u8 exit code so callers convert to ExitCode only at the outermost layer.
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_with_context
Full-control entry with injected stderr and explicit render 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 segment 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.