Expand description
Rich-rs: Rich text and beautiful formatting for the terminal
A Rust port of Python’s Rich library.
§Example
use rich_rs::{Console, Text};
let mut console = Console::new();
// Print plain text
console.print_text("Hello, World!").unwrap();
// Print styled text using Text and render
let text = Text::from_markup("Hello, [bold red]World[/]!", false).unwrap();
console.print(&text, None, None, None, false, "\n").unwrap();Re-exports§
pub use error::ParseError;pub use error::Result as ParseResult;pub use text::Span;pub use text::Text;pub use text::TextPart;pub use wrap::divide_line;pub use loop_helpers::loop_first;pub use loop_helpers::loop_first_last;pub use loop_helpers::loop_last;pub use highlighter::Highlighter;pub use highlighter::NullHighlighter;pub use highlighter::RegexHighlighter;pub use highlighter::combine_regex;pub use highlighter::iso8601_highlighter;pub use highlighter::json_highlighter;pub use highlighter::repr_highlighter;pub use json::Json;pub use align::Align;pub use align::VerticalAlignMethod;pub use bar::Bar;pub use columns::Columns;pub use constrain::Constrain;pub use group::Group;pub use group::Lines;pub use group::Renderables;pub use padding::Padding;pub use padding::PaddingDimensions;pub use panel::Panel;pub use rule::AlignMethod;pub use rule::Rule;pub use styled::Styled;pub use table::Column;pub use table::Row;pub use table::Table;pub use tree::ASCII_GUIDES;pub use tree::BOLD_TREE_GUIDES;pub use tree::TREE_GUIDES;pub use tree::Tree;pub use tree::TreeGuides;pub use tree::TreeNodeOptions;pub use syntax::AnsiTheme;pub use syntax::DEFAULT_THEME;pub use syntax::Syntax;pub use syntax::SyntaxTheme;pub use syntax::SyntectTheme;pub use pretty::Pretty;pub use pretty::pprint;pub use pretty::pretty_repr;pub use scope::ScopeRenderable;pub use scope::render_scope;pub use layout::Layout;pub use layout::LayoutRender;pub use layout::SplitterKind;pub use live::Live;pub use live::LiveOptions;pub use live::VerticalOverflowMethod;pub use live_render::LiveRender;pub use progress::BarColumn;pub use progress::DownloadColumn;pub use progress::FileSizeColumn;pub use progress::MofNCompleteColumn;pub use progress::Progress;pub use progress::ProgressColumn;pub use progress::ProgressReader;pub use progress::ProgressTask;pub use progress::RenderableColumn;pub use progress::SpinnerColumn;pub use progress::TaskID;pub use progress::TaskProgressColumn;pub use progress::TextColumn;pub use progress::TimeElapsedColumn;pub use progress::TimeRemainingColumn;pub use progress::TotalFileSizeColumn;pub use progress::TrackConfig;pub use progress::TransferSpeedColumn;pub use progress::WrapFileBuilder;pub use progress_bar::ProgressBar;pub use recorder::FrameRecorder;pub use region::Region;pub use screen::Screen;pub use screen_buffer::Cell;pub use screen_buffer::ScreenBuffer;pub use screen_context::ScreenContext;pub use spinner::Spinner;pub use spinner::spinner_names;pub use status::Status;pub use traceback::Frame;pub use traceback::Stack;pub use traceback::SyntaxErrorInfo;pub use traceback::Trace;pub use traceback::Traceback;pub use traceback::TracebackBuilder;pub use prompt::Confirm;pub use prompt::FloatPrompt;pub use prompt::IntPrompt;pub use prompt::InvalidResponse;pub use prompt::Prompt;pub use prompt::PromptError;pub use prompt::Result as PromptResult;pub use file_proxy::FileProxy;pub use pager::BufferPager;pub use pager::NullPager;pub use pager::Pager;pub use pager::SystemPager;pub use export_format::CONSOLE_HTML_FORMAT;pub use export_format::CONSOLE_SVG_FORMAT;pub use terminal_theme::DEFAULT_TERMINAL_THEME;pub use terminal_theme::DIMMED_MONOKAI;pub use terminal_theme::MONOKAI;pub use terminal_theme::NIGHT_OWLISH;pub use terminal_theme::SVG_EXPORT_THEME;pub use terminal_theme::TerminalTheme;pub use markup::escape as escape_markup;
Modules§
- align
- Align: horizontal and vertical alignment wrapper for renderables.
- bar
- Bar: a horizontal bar renderable.
- box
- Box drawing characters for borders, panels, and tables.
- columns
- Columns: Display renderables in neat columns.
- constrain
- Constrain: clamp a renderable to a maximum width.
- error
- Error types for rich-rs.
- export_
format - Export format templates for SVG and HTML.
- file_
proxy - FileProxy: Redirect writes to a Console.
- group
- Group: a renderable that renders multiple children sequentially.
- highlighter
- Highlighter: apply styling to text based on patterns.
- json
- JSON: pretty-printed JSON renderable.
- layout
- Layout: split a terminal area into regions and render children.
- live
- Live: auto-updating display for terminal renderables.
- live_
render - LiveRender: A renderable that may be updated and tracks its shape.
- loop_
helpers - Iterator helpers.
- markdown
- Markdown rendering with Rich formatting.
- markup
- Markup: BBCode-like markup parsing.
- padding
- Padding: CSS-style spacing wrapper for renderables.
- pager
- Pager: Display content using a system pager.
- panel
- Panel: a bordered box around content.
- pretty
- Pretty: pretty-print Rust data structures.
- progress
- Progress: task tracking with live-updating progress bars.
- progress_
bar - ProgressBar: a progress bar renderable (used by Progress).
- prompt
- Interactive prompts for user input.
- recorder
- Frame recorder for animated terminal captures.
- region
- Region: Rectangle math for screen layouts.
- rule
- Rule: a horizontal line renderable.
- scope
- Scope: render local variables as a formatted table.
- screen
- Screen: A renderable that fills the terminal screen.
- screen_
buffer - ScreenBuffer: a 2D grid of styled cells plus a diff algorithm.
- screen_
context - ScreenContext: RAII context for alternate screen mode.
- spinner
- Spinner: simple terminal spinner animations (used by Progress).
- status
- Status: a spinner with status text for long-running operations.
- styled
- Styled: apply a style to any renderable.
- syntax
- Syntax: syntax-highlighted code rendering.
- table
- Table: a renderable table with columns and rows.
- terminal_
theme - Terminal themes for SVG/HTML export.
- text
- Text: rich text with styled spans.
- traceback
- Traceback: structured exception/error display.
- tree
- Tree: hierarchical tree rendering.
- wrap
- Text wrapping utilities.
Macros§
- log
- Log a renderable to the console with automatic timestamp and source location.
- rich_
print - Print styled content using the global console.
Structs§
- Ansi
Decoder - Translate ANSI escape codes in to styled
Text. - Color
- A terminal color definition.
- Color
Triplet - RGB color triplet with red, green, and blue components (0-255).
- Console
- The main console for rendering output.
- Console
Options - Options passed through the rendering pipeline.
- Control
- Emoji
- A single emoji character.
- Measurement
- The minimum and maximum width requirements of a renderable.
- Pager
Context - A guard that captures console output and sends it to a pager on drop.
- Pager
Options - Options for the pager context.
- Palette
- A palette of colors for color matching.
- Segment
- A segment of text with optional style and control codes.
- Segment
Lines - A simple renderable wrapping pre-rendered lines of segments.
- Segments
- A collection of segments, backed by SmallVec for efficiency.
- Style
- Text style with color and attributes.
- Style
Meta - Metadata for styles, used for hyperlinks and custom data.
- Style
Stack - A stack of styles where the current style is the combination of all pushed styles.
- Theme
- A container for style information.
- Theme
Stack - A stack of themes for scoped style overrides.
Enums§
- Color
System - The color system supported by a terminal.
- Color
Type - The type of color stored in a Color struct.
- Control
Type - Control codes that can be embedded in output.
- Emoji
Variant - Emoji variant selector.
- Justify
Method - Text justification method.
- Meta
Value - Structured metadata values (used by Textual handlers and richer annotations).
- Overflow
Method - Text overflow handling method.
- Simple
Color - Simple color enum for backward compatibility.
- Theme
Error - Errors that can occur when working with themes.
Constants§
- NULL_
STYLE - A null style with all attributes set to
None.
Statics§
- ANSI_
COLOR_ NAMES - Map of ANSI color names to their color numbers. Includes all ~250 named colors from Python Rich.
- EIGHT_
BIT_ PALETTE - 256-color (8-bit) palette.
- EMOJI
- Compile-time map of emoji names to emoji characters.
- STANDARD_
PALETTE - Standard 16 ANSI color palette.
- WINDOWS_
PALETTE - Windows 10 console color palette.
Traits§
- Renderable
- A type that can be rendered to the console.
- Rich
Cast - A type that can be converted to a Renderable.
Functions§
- blend_
rgb - Blend two colors together.
- cell_
len - Calculate the display width of a string in terminal cells.
- chop_
cells - Split text into lines such that each line fits within the available (cell) width.
- default_
styles - Create the default styles map.
- escape_
control_ codes - Escape control codes so they display as visible text.
- filesize_
decimal - Convert a filesize to a decimal string (powers of 1000), matching Rich’s behavior.
- filesize_
decimal_ with_ params - Convert a filesize to a decimal string with configurable precision and thousands separator.
- get_
console - Get a reference to the global console singleton.
- measure_
renderables - Get a combined measurement for multiple renderables.
- parse_
rgb_ hex - Parse a six-character hex string into a ColorTriplet.
- pick_
unit_ and_ suffix - Pick the largest unit <=
valuefromsuffixeswith the given base. - set_
cell_ size - Set the length of a string to fit within given number of cells.
- split_
graphemes - Split text into individual character graphemes.
- strip_
control_ codes - Strip control codes from text.