Skip to main content

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//! ```
11//! use rich::{Console, ColorSystem};
12//! use rich_ext::ConsoleExt;
13//!
14//! let mut console = Console::builder()
15//!     .force_terminal(true)
16//!     .color_system(Some(ColorSystem::Truecolor))
17//!     .build();
18//! console.install_extensions(); // registers the number highlighter, etc.
19//! let out = console.render_str_to_string("count=7");
20//! assert!(out.contains("\x1b[1;36m7\x1b[0m"));
21//! ```
22
23pub mod cli;
24pub mod encoding;
25pub mod highlighter;
26pub mod registry;
27pub mod theme;
28
29pub use highlighter::NumberHighlighter;
30pub use registry::{install_defaults, ExtensionRegistry};
31pub use theme::{extended_theme, EXTRA_STYLES};
32
33use rich::Console;
34
35/// Ergonomic extension methods on the core [`Console`].
36///
37/// Defined here (not in core) so the core remains free of our additions.
38pub trait ConsoleExt {
39    /// Install this crate's default extensions onto the console.
40    fn install_extensions(&mut self) -> &mut Self;
41}
42
43impl ConsoleExt for Console {
44    fn install_extensions(&mut self) -> &mut Self {
45        install_defaults(self);
46        self
47    }
48}