Skip to main content

rich/
lib.rs

1//! # rich
2//!
3//! A **faithful** Rust port of the Python [`rich`](https://github.com/Textualize/rich)
4//! terminal-rendering library. This crate mirrors upstream module-for-module.
5//! Its version is independent SemVer; the upstream release it reflects
6//! (currently `rich` 15.0.0) is recorded in `UPSTREAM.toml`.
7//!
8//! Local features and the plugin registry live in the separate `rich-ext` crate
9//! — do **not** add non-upstream behavior here. See `AGENTS.md`.
10//!
11//! ## What is ported
12//!
13//! - Console and styling: [`console`], [`style`], [`color`], [`segment`],
14//!   [`markup`], [`theme`], [`control`], [`screen`], [`export`].
15//! - Text: [`text`], [`cells`], [`wrap`], [`emoji`], [`highlighter`], [`ansi`].
16//! - Renderables: [`panel`], [`table`], [`tree`], [`layout`], [`columns`],
17//!   [`align`], [`padding`], [`constrain`], [`rule`], [`bar`], [`markdown`],
18//!   [`syntax`], [`json`], [`pretty`], [`scope`], [`traceback`],
19//!   [`log_render`].
20//! - Live output: [`live`], [`progress`] (with [`track`]), [`progress_bar`],
21//!   [`spinner`], [`status`].
22//! - Input and paging: [`prompt`], [`pager`].
23//! - Extension points: [`protocol`], [`measure`].
24//!
25//! ## Cargo features
26//!
27//! - `syntax` *(default)*: [`syntax`] with syntect as the code highlighter
28//!   used when none is given. Implies `code`.
29//! - `markdown` *(default)*: [`markdown`], parsed with pulldown-cmark.
30//!   Implies `code`, not `syntax`.
31//! - `code`: [`syntax`] and the [`CodeHighlighter`] plumbing without syntect.
32//!   A `Syntax` or Markdown code block highlights with its own highlighter or
33//!   the console's default ([`ConsoleCodeHighlighting`]); with neither it
34//!   renders as plain code in the same layout. Use
35//!   `default-features = false, features = ["code", "markdown"]` to keep
36//!   `Syntax` and `Markdown` without syntect and its dependencies.
37//! - `syntax-cache`, `onig`, `json-escape-safe`: opt-in divergences, see
38//!   `docs/DIVERGENCES.md`.
39//!
40//! Most modules are partial ports of their upstream counterpart; the per-module
41//! status and parity evidence are in `docs/PORTING.md`.
42
43pub mod align;
44pub mod ansi;
45pub mod bar;
46pub mod r#box;
47mod cell_widths;
48pub mod cells;
49pub mod color;
50mod color_names;
51pub mod columns;
52pub mod console;
53pub mod constrain;
54pub mod containers;
55pub mod control;
56pub mod emoji;
57mod emoji_codes;
58pub mod errors;
59pub mod export;
60pub mod file_proxy;
61pub mod filesize;
62pub mod highlighter;
63pub mod json;
64pub mod layout;
65pub mod live;
66pub mod live_render;
67pub mod log_render;
68#[cfg(feature = "markdown")]
69pub mod markdown;
70#[cfg(feature = "markdown")]
71mod markdown_url;
72pub mod markup;
73pub mod measure;
74pub mod padding;
75pub mod pager;
76pub mod panel;
77pub mod pretty;
78pub mod progress;
79pub mod progress_bar;
80pub mod prompt;
81pub mod protocol;
82pub mod pyformat;
83pub mod ratio;
84pub mod region;
85mod repr_patterns;
86pub mod rule;
87pub mod scope;
88pub mod screen;
89pub mod segment;
90pub mod spinner;
91mod spinner_data;
92pub mod status;
93pub mod style;
94pub mod styled;
95pub mod svg;
96#[cfg(feature = "code")]
97pub mod syntax;
98pub mod table;
99pub mod terminal_theme;
100pub mod text;
101pub mod theme;
102pub mod traceback;
103pub mod tree;
104pub mod wrap;
105
106/// The string type of rich's per-cell text: [`Segment::text`] and
107/// [`Color::name`]. Inline up to 24 bytes (so a short run or a colour's
108/// name allocates nothing), and a `&str` when read. Re-exported from
109/// [`compact_str`](https://docs.rs/compact_str).
110pub use compact_str::CompactString;
111
112// A small, curated prelude mirroring the most-used names from `rich`'s top level.
113pub use crate::align::{Align, HorizontalAlign, VerticalAlign, VerticalCenter};
114pub use crate::ansi::AnsiDecoder;
115pub use crate::bar::Bar;
116pub use crate::color::{Color, ColorSystem, ColorTriplet};
117pub use crate::columns::Columns;
118pub use crate::console::{
119    Console, ConsoleDimensions, ConsoleOptions, ExportHtmlOptions, ExportSvgOptions, Justify,
120    LogObject, LogOptions, Overflow, RenderHook, RenderStrOptions, ScreenContext, ScreenUpdate,
121    ThemeContext,
122};
123pub use crate::constrain::Constrain;
124pub use crate::control::{Control, ControlType};
125pub use crate::emoji::EmojiVariant;
126pub use crate::errors::{Result, RichError};
127pub use crate::file_proxy::{FileProxy, ProxyStream, ProxyTarget};
128pub use crate::highlighter::{
129    ISO8601Highlighter, JSONHighlighter, NullHighlighter, RegexHighlighter, ReprHighlighter,
130};
131pub use crate::json::Json;
132pub use crate::layout::{Layout, LayoutRender, Splitter};
133pub use crate::live::{AutoLive, Live, LiveHandle, LiveOptions, LivePanic};
134pub use crate::live_render::{LiveRender, VerticalOverflow};
135pub use crate::log_render::{level_text, LogLevel, LogRecord, LogRender};
136pub use crate::padding::Padding;
137pub use crate::pager::{Pager, SystemPager};
138pub use crate::panel::Panel;
139pub use crate::pretty::{Pretty, PrettyValue};
140pub use crate::progress::{
141    track, BarColumn, CustomColumn, CustomProgressColumn, LiveProgress, Progress, ProgressColumn,
142    ProgressReader, SpinnerColumn, Task, TaskId, TaskUpdate, TextColumn, TimeRemainingColumn,
143    Track, TrackStdout,
144};
145pub use crate::progress_bar::ProgressBar;
146pub use crate::protocol::{
147    CodeHighlighter, CodeHighlighting, ConsoleCodeHighlighting, FenceRenderer, HighlightError,
148    HighlightSpan, HighlightedCode, HighlightedLine, Highlighter, LineRenderable, Renderable,
149};
150pub use crate::region::Region;
151pub use crate::rule::Rule;
152pub use crate::scope::render_scope;
153pub use crate::screen::Screen;
154pub use crate::segment::Segment;
155pub use crate::spinner::Spinner;
156pub use crate::status::{LiveStatus, Status};
157pub use crate::style::{Meta, MetaValue, Style, StyleType};
158pub use crate::styled::Styled;
159#[cfg(feature = "code")]
160pub use crate::syntax::Syntax;
161#[cfg(feature = "syntax")]
162pub use crate::syntax::SyntectHighlighter;
163pub use crate::table::{Cell, ColumnOptions, Table};
164pub use crate::terminal_theme::{
165    TerminalTheme, DEFAULT_TERMINAL_THEME, DIMMED_MONOKAI, MONOKAI, NIGHT_OWLISH, SVG_EXPORT_THEME,
166};
167pub use crate::text::Text;
168pub use crate::theme::Theme;
169pub use crate::traceback::Traceback;
170pub use crate::tree::Tree;