← 全部工具

cgroening/rs-sparcli

热度 75 更新于 开发与构建

Styled CLI output and interactive input widgets for Rust – tables, panels, trees, progress bars, prompts. Built on crossterm.

githubauto-collected

安装

暂未验证可直接使用的安装命令,请查看项目官方文档或 Release。

sparcli

A lightweight, cross-platform toolkit for styled CLI output and interactive input widgets in Rust. It renders directly to the terminal via crossterm (no ratatui dependency) but mirrors ratatui's familiar vocabulary (Style, Color, Span, Line, Text), so the API feels at home if you already use ratatui.

sparcli is meant for small, lightweight CLI tools: a single accent color, muted defaults, rounded borders, graceful NOCOLOR and non-terminal behavior. Heavy, full-screen/retained TUIs are out of scope (that is what ratatui is for).

Highlights

  • Output: styled text, markup, tables (colspan, striping, wrap, titles), panels, cards (a filled surface whose whole palette is derived from one accent color), alerts, rules, lists, trees, key-value lists, badges, progress bars, spinners, multi-progress, diffs, columns, live display, pager, and composition helpers (align, pad, vstack).
  • Input: confirm, text (validation, char filters, history, ghost autocomplete), password, number (with a calculator), textarea, single/multi select, an inline fuzzy select, and a calendar date picker.
  • Unified theme for input and output, set once and overridable per call.
  • Robust: no panics on input, RAII terminal restore, Result-based errors.

Install

[dependencies]
sparcli = "0.4"
# Opt-in features (the base stays small):
# sparcli = { version = "0.4", features = ["markup", "fuzzy", "pager"] }

MSRV: Rust 1.88 (edition 2024).

| Feature | Adds | | -------- | ------------------------------------------------- | | markup | [bold red]…[/] inline markup parsing | | fuzzy | inline fuzzy-select (pulls in nucleo-matcher) | | pager | paging via $PAGER / less / more | | full | enables markup, fuzzy and pager |

From a local checkout or Git

To use an unpublished or local copy instead of the crates.io release, point Cargo at the source directory or repository:

[dependencies]
# Local path (absolute or relative to your Cargo.toml):
sparcli = { path = "../sparcli" }
# Straight from Git:
# sparcli = { git = "https://github.com/cgroening/rs-sparcli", branch = "main" }

Output example

use sparcli::prelude::*;
use sparcli::{Alert, Table};

fn main() -> sparcli::Result<()> {
    Alert::success("Build finished.").print()?;

    Table::new()
        .columns(["Name", "Status"])
        .row(["web-1", "online"])
        .row(["db-1", "online"])
        .striped(true)
        .print()?;

}


Every output widget implements `Renderable`: call `.print()` to write to stdout, or `.print_to(&mut writer)` to capture output. When stdout is not a terminal (a pipe, a file, or with `NO_COLOR`), no escape codes are emitted.

Widgets like `Panel` frame their content with a rounded border and an optional title:

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

Panel::new("All systems nominal.") .title(Title::new("Status")) .print()?;