Skip to main content

sparcli/
lib.rs

1//! `sparcli` is a lightweight, cross-platform toolkit for styled command-line
2//! output and interactive input widgets.
3//!
4//! It renders directly to the terminal via [`crossterm`] (no `ratatui`
5//! dependency) but mirrors ratatui's familiar vocabulary ([`Style`],
6//! [`Color`], [`Span`], [`Line`], [`Text`]). Output widgets implement
7//! [`Renderable`] and can be printed inline; input widgets run small,
8//! self-contained prompt loops.
9//!
10//! The base crate stays small; heavier features live behind cargo features
11//! (`markup`, `fuzzy`, `pager`).
12//!
13//! # Examples
14//!
15//! Build a styled panel and render it to a string (no terminal required),
16//! which is exactly how the output widgets are tested:
17//!
18//! ```
19//! use sparcli::{Color, Panel, Renderable, Style, Title};
20//!
21//! let panel = Panel::new("Build succeeded.")
22//!     .title(Title::new("Status"))
23//!     .border_style(Style::new().fg(Color::Green));
24//!
25//! let out = panel.render(40);
26//! assert!(out.plain().contains("Build succeeded."));
27//! ```
28//!
29//! In a real program you would print it straight to the terminal with
30//! `panel.print()?` instead of rendering to a string.
31//!
32//! [`Style`]: crate::Style
33//! [`Color`]: crate::Color
34//! [`Span`]: crate::Span
35//! [`Line`]: crate::Line
36//! [`Text`]: crate::Text
37//! [`Renderable`]: crate::Renderable
38
39#![deny(missing_docs)]
40
41pub(crate) mod core;
42pub(crate) mod error;
43pub(crate) mod input;
44pub(crate) mod output;
45
46pub use core::border::BorderType;
47pub use core::geometry::{Align, Edges, Position, Title, VAlign};
48pub use core::render::{Renderable, Rendered};
49pub use core::style::{Attribute, Color, Modifier, Style};
50pub use core::text::{Line, Span, Text};
51pub use core::theme::{Theme, set_theme, theme};
52pub use error::{Result, SparcliError};
53pub use output::alert::{Alert, AlertKind};
54pub use output::badge::Badge;
55pub use output::columns::Columns;
56pub use output::diff::Diff;
57pub use output::kv::KeyValue;
58pub use output::list::{List, Marker};
59pub use output::live::Live;
60pub use output::multiprogress::MultiProgress;
61pub use output::panel::Panel;
62pub use output::progress::{ProgressBar, ProgressStyle, Thresholds};
63pub use output::rule::Rule;
64pub use output::spinner::{Spinner, SpinnerStyle};
65pub use output::table::{Cell, Column, Table};
66pub use output::tree::{Tree, TreeNode};
67
68#[cfg(feature = "pager")]
69pub use output::pager::Pager;
70
71pub use input::Outcome;
72pub use input::confirm::Confirm;
73pub use input::datepicker::{Date, DatePicker};
74pub use input::editor::edit_file;
75pub use input::history::History;
76pub use input::number::NumberInput;
77pub use input::password::PasswordInput;
78pub use input::select::Select;
79pub use input::shortcut::Shortcut;
80pub use input::text::TextInput;
81pub use input::textarea::Textarea;
82
83#[cfg(feature = "fuzzy")]
84pub use input::fuzzy::FuzzySelect;
85
86/// Rich-style inline markup parsing (`[bold red]text[/]`).
87#[cfg(feature = "markup")]
88pub mod markup {
89    pub use crate::core::markup::{markup_print, markup_println, parse};
90}
91
92/// Value validators and character filters for text prompts.
93pub mod validate {
94    pub use crate::input::validate::{
95        CharFilter, Validator, alnum, alpha, decimal, digits, min_len,
96        no_space, non_empty,
97    };
98}
99
100/// Keyboard events and the dependency-injected event source (for headless
101/// testing and custom input backends).
102pub mod event {
103    pub use crate::input::event::{
104        CrosstermSource, EventSource, InputEvent, KeyCode, KeyPress,
105    };
106}
107
108/// Keyboard shortcuts and their footer-hint / help-overlay rendering.
109pub mod shortcut {
110    pub use crate::input::shortcut::{
111        Shortcut, find, help_overlay, hint_line, key_name,
112    };
113}
114
115/// Unicode-aware display-width helpers (width, ANSI stripping, wrap, truncate).
116pub mod width {
117    pub use crate::core::width::{strip_ansi, truncate, visible_width, wrap};
118}
119
120/// Terminal capability and size detection.
121pub mod terminal {
122    pub use crate::core::terminal::{
123        ColorSupport, color_support, is_input_tty, is_output_tty, term_height,
124        term_width, terminal_size,
125    };
126}
127
128/// Commonly used types, re-exported for `use sparcli::prelude::*;`.
129pub mod prelude {
130    pub use crate::core::border::BorderType;
131    pub use crate::core::geometry::{Align, Edges, Position, Title, VAlign};
132    pub use crate::core::render::{Renderable, Rendered};
133    pub use crate::core::style::{Attribute, Color, Modifier, Style};
134    pub use crate::core::text::{Line, Span, Text};
135    pub use crate::core::theme::{Theme, set_theme, theme};
136    pub use crate::error::{Result, SparcliError};
137    pub use crate::output::alert::{Alert, AlertKind};
138    pub use crate::output::badge::Badge;
139    pub use crate::output::compose::{align, pad, vstack};
140    pub use crate::output::kv::KeyValue;
141    pub use crate::output::list::{List, Marker};
142    pub use crate::output::panel::Panel;
143    pub use crate::output::rule::Rule;
144    pub use crate::output::tree::{Tree, TreeNode};
145}