rich_ext/lib.rs
1//! # rich-ext
2//!
3//! Extensions layered on top of the faithful [`rich`] core, plus the internal
4//! plugin registry. **Anything that is not a faithful port of upstream `rich`
5//! belongs here**, so the core stays a clean, easily-synced mirror.
6//!
7//! This crate carries its own independent SemVer (it does not track any upstream
8//! version). See `AGENTS.md` → Versioning and `docs/PLUGINS.md`.
9//!
10//! ## Modules
11//!
12//! - Errors and logs: [`diagnostic`], [`dashboard`], [`stacktrace`],
13//! [`hyperlink`], [`log_handler`] (`RichHandler`, `SpanView`), [`adapters`]
14//! (`EventSink`; `LogAdapter` and `EventLayer` with the `log` / `tracing`
15//! features), [`event`], [`log_stream`] (log records parsed, filtered,
16//! collapsed and grouped, and [`ChannelSink`](log_stream::ChannelSink)).
17//! - Data and authoring: `data`, `deps` (Cargo dependency trees) and `schema`
18//! (JSON Schema trees and diffs, and the format-neutral schema model), all
19//! behind the `data` feature;
20//! [`derive`](mod@derive), [`macros`] (the
21//! `macros` feature re-exports `richf!` and `#[derive(Rich)]`),
22//! [`inspect`](mod@inspect) (`rich.inspect` from `#[derive(Inspect)]`), [`cli_doc`]
23//! (`clap` feature for `clap::Command`).
24//! - Diffs and testing: [`diff`], `testing` and `qa` (`testing` feature).
25//! - Terminals: [`capabilities`], [`fidelity`], [`a11y`], [`target`],
26//! [`ansi_explain`], [`sanitize`], [`encoding`], [`clipboard`] (OSC 52).
27//! - Workflows: [`workflow`], [`transfer`], [`countdown`], [`notify`],
28//! [`cancel`], [`table`], [`badge`], [`size_bar`], [`format`](mod@format), [`redact`]
29//! (experimental).
30//! - Charts: [`chart`] (sparklines, bars, histograms, line and scatter plots,
31//! gauges, heatmaps, status matrices, KPI cards and timelines; ratatui's
32//! chart, canvas with a world map, and gauges).
33//! - Colour: [`palette`] (Tailwind's and Material's palettes; HSL, HSV,
34//! Okhsv and Oklab colours, blends and gradients).
35//! - Inspectors: [`source_view`], [`hex`], [`unicode_inspect`],
36//! [`env_inspect`].
37//! - Documents: `document` (Org, AsciiDoc and man pages beside Markdown and
38//! `rst`, with format detection; `syntax` feature).
39//! - Layout and live output: [`layout`], [`live`], [`surface`] (positioned
40//! drawing that writes only what changed).
41//! - Pipelines: [`transform`], and `data::transform` (`jsonpath` feature).
42//! - Files: [`filetype`] (icons, colours, MIME types), [`fs`] (local times,
43//! owners), [`listing`] (entries, sorting, a tree walk), [`open`] (opener
44//! rules), [`file_ops`] (copy, move, delete with progress), [`trash`] (the
45//! FreeDesktop trash), [`git`] (status per file), and `archive` (tar and zip
46//! listing and extraction; `archive` feature).
47//!
48//! The user guide (<https://buchochelliq-labs.github.io/rs-rich-cli/guide/ext/>)
49//! covers each module with compiled examples.
50//!
51//! ```
52//! use rich::{Console, ColorSystem};
53//! use rich_ext::ConsoleExt;
54//!
55//! let mut console = Console::builder()
56//! .force_terminal(true)
57//! .color_system(Some(ColorSystem::Truecolor))
58//! .build();
59//! console.install_extensions(); // registers the number highlighter, etc.
60//! let out = console.render_str_to_string("count=7");
61//! assert!(out.contains("\x1b[1;36m7\x1b[0m"));
62//! ```
63
64// A builder method that returns `Self` is `#[must_use]`: dropping its
65// result drops the value (CONTRIBUTING.md, "API conventions").
66#![warn(clippy::return_self_not_must_use)]
67
68pub mod a11y;
69pub mod ansi_explain;
70// Tar, tar.gz and zip listings and extraction.
71#[cfg(feature = "archive")]
72pub mod archive;
73pub mod badge;
74pub mod cancel;
75pub mod capabilities;
76pub mod chart;
77pub mod cli;
78pub mod clipboard;
79// Documentation formats (Markdown, reStructuredText, Org, AsciiDoc, man).
80#[cfg(feature = "syntax")]
81pub mod document;
82// FFT, Hann window and spectrum.
83pub mod dsp;
84pub mod encoding;
85pub mod env_inspect;
86pub mod fidelity;
87// File-type icons, MIME types and the Nerd Font check.
88pub mod filetype;
89pub mod format;
90pub mod frame;
91// Text coloured along a gradient of two or more colours.
92pub mod gradient;
93// Local times and owner names for file listings.
94pub mod fs;
95// File operations with progress: copy, move, delete, trash.
96pub mod file_ops;
97// Git's status of each file, through `git status --porcelain`.
98pub mod git;
99pub mod graphics;
100pub mod hex;
101pub mod highlighter;
102// Directory entries, sorting, line-mode cells and a lazy tree walk.
103pub mod listing;
104pub mod markdown_export;
105// Which program opens a file: Yazi's opener rules.
106pub mod open;
107pub mod palette;
108pub mod plugin_loading;
109// QR codes drawn with half blocks.
110#[cfg(feature = "qr")]
111pub mod qr;
112pub mod redact;
113pub mod registry;
114#[cfg(feature = "syntax")]
115pub mod rst;
116pub mod sanitize;
117pub mod size_bar;
118pub mod source_view;
119// A pure-Rust SQL highlighter (no syntect), with Jinja blocks for dbt.
120#[cfg(feature = "sql")]
121pub mod sql;
122pub mod surface;
123// Warming up syntax highlighting on a worker thread.
124#[cfg(feature = "syntax")]
125pub mod syntax;
126pub mod table;
127pub mod target;
128pub mod theme;
129pub mod transform;
130// The FreeDesktop trash: put, list, restore, purge.
131pub mod trash;
132pub mod unicode_inspect;
133pub mod workflow;
134
135pub use highlighter::NumberHighlighter;
136pub use registry::{
137 BuiltinPlugin, ExtensionRegistry, HighlighterChoiceError, RegisteredPlugin, install_defaults,
138};
139/// The plugin contract, re-exported so a host needs only `rich_ext`.
140pub use rich_plugin_api as plugin;
141pub use sanitize::sanitize_terminal_controls;
142pub use theme::{EXTRA_STYLES, extended_theme};
143
144use rich::Console;
145
146/// Ergonomic extension methods on the core [`Console`].
147///
148/// Defined here (not in core) so the core remains free of our additions.
149pub trait ConsoleExt {
150 /// Install this crate's default extensions onto the console.
151 fn install_extensions(&mut self) -> &mut Self;
152}
153
154impl ConsoleExt for Console {
155 fn install_extensions(&mut self) -> &mut Self {
156 install_defaults(self);
157 self
158 }
159}
160
161#[cfg(feature = "testing")]
162pub mod testing;
163
164// QA tooling: screenshots, stress, lint, explain, profile, fuzz, matrix, bench.
165#[cfg(feature = "testing")]
166pub mod qa;
167
168pub mod layout;
169
170pub mod event;
171
172pub mod diagnostic;
173
174pub mod dashboard;
175
176pub mod derive;
177
178pub mod macros;
179
180#[cfg(feature = "macros")]
181pub use rich_macros::{Rich, markup, richf, style, theme_key};
182
183// `rich.inspect` from compile-time data (#796): the report is always here;
184// `#[derive(Inspect)]` and `#[inspect]` on impl blocks need `macros`.
185pub mod inspect;
186pub use inspect::{Inspect, Inspectable, inspect};
187#[cfg(feature = "macros")]
188pub use rich_macros::{Inspect, inspect};
189
190/// Paths the macros expand to. Not a public API.
191#[doc(hidden)]
192pub mod __private {
193 pub use rich;
194}
195
196pub mod hyperlink;
197
198pub mod stacktrace;
199
200pub mod log_handler;
201pub use log_handler::{RichHandler, SpanView};
202
203// Log streams: parsing, filtering, collapsing and grouping records (#724).
204pub mod log_stream;
205
206// `EventSink` always; `LogAdapter` and `EventLayer` behind `log` and `tracing`.
207pub mod adapters;
208
209pub mod live;
210
211#[cfg(feature = "data")]
212pub mod data;
213
214// Real sources drawn as trees: Cargo dependency graphs and JSON Schemas.
215#[cfg(feature = "data")]
216pub mod deps;
217#[cfg(feature = "data")]
218pub mod schema;
219
220// CLI authoring: help, errors, completions, docs, config reference and
221// precedence from one command description.
222pub mod cli_doc;
223
224// Diffs: engine, views, source/patch renderers, test reports and assertions.
225pub mod diff;
226
227// Transfers, retry/rate-limit countdowns and transient notifications.
228pub mod countdown;
229pub mod notify;
230pub mod transfer;