Skip to main content

rusty_rich/
lib.rs

1//! # rusty-rich
2//!
3//! **Rich text and beautiful formatting in the terminal** — a Rust port of
4//! the popular Python [Rich](https://github.com/Textualize/rich) library.
5//!
6//! ## Features
7//!
8//! - 🎨 **Style**: foreground/background colors, bold, italic, underline,
9//!   dim, blink, reverse, strikethrough
10//! - 📝 **Console markup**: `[bold red]text[/bold red]` for inline styling
11//! - 📊 **Table**: tabular data with headers, footers, column alignment
12//! - 🌲 **Tree**: hierarchical tree rendering
13//! - 📦 **Panel**: bordered containers with optional titles
14//! - ➖ **Rule**: horizontal dividers with optional titles
15//! - 📐 **Padding & Align**: spacing and alignment helpers
16//! - 📋 **Columns**: side-by-side layout
17//! - 🗂️ **Layout**: split-pane layout system
18//! - ⏳ **Progress**: multi-task progress bars
19//! - 🔄 **Spinner**: animated spinners
20//! - 📌 **Status**: status messages with spinner
21//! - 🔄 **Live**: auto-updating live displays
22//! - 🖥️ **Screen**: full-screen rendering and alternate screen buffer
23//! - 🌈 **Syntax highlighting**: powered by syntect (like Pygments)
24//! - 📝 **Markdown**: rich markdown rendering
25//! - 📋 **JSON**: pretty-printed, syntax-highlighted JSON
26//! - 🔍 **Logging**: Rich-formatted log records
27//! - 🖼️ **Box drawing**: 12 box styles (rounded, square, heavy, double, etc.)
28//! - 🎯 **TrueColor / 256 / 16** color support with automatic detection
29//!
30//! ## Quick Start
31//!
32//! ```rust,no_run
33//! use rusty_rich::{
34//!     Console, Panel, Table, Column, Rule, Tree,
35//!     Style, Color, AlignMethod, Padding,
36//! };
37//!
38//! fn main() {
39//!     let mut console = Console::new();
40//!
41//!     // Print with markup
42//!     console.print_str("[bold green]Hello, [red]World![/red][/bold green]");
43//!
44//!     // Create a panel
45//!     let panel = Panel::new("Hello inside a rounded box!")
46//!         .title("My Panel")
47//!         .border_style(Style::new().color(Color::parse("cyan").unwrap()));
48//!     console.println(&panel);
49//!
50//!     // Create a table
51//!     let mut table = Table::new();
52//!     table.add_column(Column::new("Name").justify(AlignMethod::Left));
53//!     table.add_column(Column::new("Age").justify(AlignMethod::Right));
54//!     table.add_row(vec!["Alice".into(), "30".into()]);
55//!     table.add_row(vec!["Bob".into(), "25".into()]);
56//!     console.println(&table);
57//!
58//!     // Create a tree
59//!     let mut tree = Tree::new("Root");
60//!     tree.add("Child 1").add("Grandchild");
61//!     tree.add("Child 2");
62//!     console.println(&tree);
63//! }
64//! ```
65
66// -- Core modules -----------------------------------------------------------
67pub mod cells;
68pub mod color;
69pub mod style;
70pub mod segment;
71pub mod text;
72pub mod theme;
73pub mod measure;
74pub mod align;
75pub mod markup;
76pub mod ratio;
77pub mod highlighter;
78pub mod console;
79pub mod box_drawing;
80
81// -- Renderable components --------------------------------------------------
82pub mod panel;
83pub mod table;
84pub mod tree;
85pub mod rule;
86pub mod padding;
87pub mod columns;
88pub mod layout;
89
90// -- Dynamic / animated components ------------------------------------------
91pub mod prompt;
92pub mod progress;
93pub mod progress_columns;
94pub mod spinner;
95pub mod status;
96pub mod live;
97pub mod screen;
98
99// -- Content rendering ------------------------------------------------------
100pub mod syntax;
101pub mod markdown;
102pub mod json;
103pub mod logging;
104pub mod traceback;
105
106// -- Export -----------------------------------------------------------------
107pub mod export;
108
109// -- Re-exports for convenience ---------------------------------------------
110
111// Core types
112pub use color::Color;
113pub use color::ColorSystem;
114pub use color::ColorType;
115
116pub use style::Style;
117pub use style::StyleStack;
118
119pub use segment::Segment;
120pub use segment::Segments;
121
122pub use text::Text;
123pub use text::Span;
124
125pub use theme::Theme;
126
127pub use align::AlignMethod;
128pub use align::VerticalAlignMethod;
129pub use align::Align;
130
131pub use measure::Measurement;
132
133// Console
134pub use console::Console;
135pub use console::ConsoleOptions;
136pub use console::ConsoleDimensions;
137pub use console::OverflowMethod;
138pub use console::Renderable;
139pub use console::RenderResult;
140pub use console::RenderItem;
141pub use console::DynRenderable;
142pub use console::Group;
143pub use console::get_console;
144pub use console::print_objects as print;
145pub use console::print_str;
146pub use console::print_json_val as print_json;
147
148// Box drawing
149pub use box_drawing::BoxStyle;
150pub use box_drawing::{
151    BOX_ROUNDED, BOX_SQUARE, BOX_HEAVY, BOX_HEAVY_EDGE, BOX_HEAVY_HEAD,
152    BOX_DOUBLE, BOX_DOUBLE_EDGE, BOX_SIMPLE, BOX_SIMPLE_HEAVY,
153    BOX_MINIMAL, BOX_MINIMAL_HEAVY, BOX_ASCII, BOX_ASCII2,
154    BOX_SQUARE_DOUBLE_HEAD, BOX_MINIMAL_DOUBLE_HEAD, BOX_SIMPLE_HEAD,
155    BOX_ASCII_DOUBLE_HEAD,
156};
157
158// Renderables
159pub use panel::Panel;
160pub use table::{Table, Column, Cell};
161pub use tree::Tree;
162pub use rule::Rule;
163pub use padding::{Padding, PaddingDimensions};
164pub use columns::Columns;
165pub use layout::{Layout, LayoutNode, Direction, Region};
166
167pub use progress::{Progress, ProgressBar, ProgressFile, Task, TrackIterator};
168pub use progress_columns::{
169    BarColumn, DownloadColumn, FileSizeColumn, MofNCompleteColumn,
170    ProgressColumn, SpinnerColumn, TaskProgressColumn, TextColumn,
171    TimeElapsedColumn, TimeRemainingColumn, TotalFileSizeColumn,
172    TransferSpeedColumn, format_size, format_speed,
173};
174pub use spinner::{
175    Spinner, SpinnerFrames, DEFAULT_SPINNER, get_spinner,
176    SPINNER_ARC, SPINNER_ARROW, SPINNER_ARROW2, SPINNER_ARROW3,
177    SPINNER_BOUNCING_BAR, SPINNER_BOUNCING_BALL,
178    SPINNER_CHRISTMAS, SPINNER_CIRCLE, SPINNER_CLOCK,
179    SPINNER_EARTH, SPINNER_GRENADE,
180    SPINNER_GROW_HORIZONTAL, SPINNER_GROW_VERTICAL,
181    SPINNER_HAMBURGER, SPINNER_HEARTS, SPINNER_MONKEY,
182    SPINNER_NOISE, SPINNER_PONG, SPINNER_RUNNER, SPINNER_SHARK,
183    SPINNER_TOGGLE, SPINNER_TRIANGLE, SPINNER_VERTICAL_BARS,
184    SPINNERS,
185};
186pub use prompt::{
187    Prompt, PromptBase, PromptError, IntPrompt, FloatPrompt, Confirm, Select,
188};
189pub use status::Status;
190pub use live::Live;
191pub use screen::Screen;
192pub use screen::ScreenContext;
193pub use screen::ScreenUpdate;
194
195pub use syntax::Syntax;
196pub use markdown::render_markdown;
197pub use markdown::MarkdownRender;
198pub use json::render_json;
199pub use json::JsonRender;
200
201pub use logging::RichHandler;
202pub use traceback::{Traceback, Trace, Stack, Frame, install};
203pub use highlighter::{Highlighter, ReprHighlighter, NullHighlighter, RegexHighlighter};
204
205pub use export::{
206    export_html, save_html, ExportHtmlOptions,
207    export_svg, save_svg, ExportSvgOptions,
208    export_text, save_text, ExportTextOptions,
209    ExportTheme,
210    EXPORT_THEME_MONOKAI, EXPORT_THEME_DIMMED_MONOKAI,
211    EXPORT_THEME_NIGHT_OWLISH, EXPORT_THEME_SVG,
212    segments_to_html, escape_html, strip_ansi_escapes,
213    CONSOLE_HTML_FORMAT, CONSOLE_SVG_FORMAT,
214};
215
216pub use markup::{render as render_markup, escape as escape_markup};