Skip to main content

Crate sparcli

Crate sparcli 

Source
Expand description

sparcli is a lightweight, cross-platform toolkit for styled command-line output and interactive input widgets.

It renders directly to the terminal via crossterm (no ratatui dependency) but mirrors ratatui’s familiar vocabulary (Style, Color, Span, Line, Text). Output widgets implement Renderable and can be printed inline; input widgets run small, self-contained prompt loops.

The base crate stays small; heavier features live behind cargo features (markup, fuzzy, pager).

§Examples

Build a styled panel and render it to a string (no terminal required), which is exactly how the output widgets are tested:

use sparcli::{Color, Panel, Renderable, Style, Title};

let panel = Panel::new("Build succeeded.")
    .title(Title::new("Status"))
    .border_style(Style::new().fg(Color::Green));

let out = panel.render(40);
assert!(out.plain().contains("Build succeeded."));

In a real program you would print it straight to the terminal with panel.print()? instead of rendering to a string.

Modules§

event
Keyboard events and the dependency-injected event source (for headless testing and custom input backends).
markup
Rich-style inline markup parsing ([bold red]text[/]).
prelude
Commonly used types, re-exported for use sparcli::prelude::*;.
shortcut
Keyboard shortcuts and their footer-hint / help-overlay rendering.
terminal
Terminal capability and size detection.
validate
Value validators and character filters for text prompts.
width
Unicode-aware display-width helpers (width, ANSI stripping, wrap, truncate).

Structs§

Alert
A bordered, pre-styled status message.
Attribute
Text attribute flags (bold, dim, italic, …), combinable with |.
Badge
A small inline token with configurable caps and style.
Cell
A single table cell.
Column
A single table column definition.
Columns
A horizontal arrangement of rendered blocks.
Confirm
A yes/no confirmation prompt.
Date
A calendar date (proleptic Gregorian).
DatePicker
A month-grid date picker prompt.
Diff
A unified diff between two texts.
Edges
Box-model spacing (padding or margin) in terminal cells.
FuzzySelect
An inline fuzzy-select prompt.
History
A bounded list of past input lines, optionally backed by a file.
KeyValue
A list of aligned key-value pairs.
Line
One visual line: a sequence of Spans.
List
A bulleted or ordered list.
Live
A live display that redraws content in place.
MultiProgress
A group of progress bars rendered as one block and updated in place.
NumberInput
A numeric input prompt with optional calculator expressions.
Pager
Pages content through an external pager.
Panel
A bordered panel around rich content.
PasswordInput
A masked password input prompt.
ProgressBar
A configurable progress bar.
Rendered
A fully laid-out block of styled lines, ready to print or compose.
Rule
A horizontal divider line, optionally labelled with a title.
Select
A scrollable selection list (single or multi).
Shortcut
A bound shortcut: a key, a caller-defined id and a footer label.
Span
A run of text sharing one Style and an optional hyperlink.
Spinner
An animated, single-line spinner with a label.
Style
A foreground/background color pair plus text attributes.
Table
A data table.
Text
Multi-line rich text.
TextInput
A single-line text input prompt.
Textarea
A multi-line text input prompt.
Theme
Visual defaults applied across input and output.
Thresholds
Threshold-based fill colors keyed on the completion ratio.
Title
A framed title, e.g. on a panel, rule or table.
Tree
A tree of TreeNodes rendered with connector glyphs.
TreeNode
A node in a Tree.

Enums§

AlertKind
The severity/kind of an Alert.
Align
Horizontal alignment.
BorderType
The visual style of a border.
Color
A terminal color.
Marker
The marker style for list items.
Outcome
The result of running an interactive prompt.
Position
Where a title sits relative to its frame.
ProgressStyle
The visual style of the filled/empty bar cells.
SparcliError
Errors that can occur while rendering output or running input prompts.
SpinnerStyle
The animation style of a spinner.
VAlign
Vertical alignment.

Traits§

Renderable
Anything that can be laid out into a Rendered and printed.

Functions§

edit_file
Opens an external editor on path, blocking until it exits.
set_theme
Replaces the process-wide theme.
theme
Returns a clone of the current theme.

Type Aliases§

Modifier
Familiar alias for Attribute (ratatui calls this Modifier).
Result
Result alias used throughout the crate.