Skip to main content

Crate rich_rs

Crate rich_rs 

Source
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§

AnsiDecoder
Translate ANSI escape codes in to styled Text.
Color
A terminal color definition.
ColorTriplet
RGB color triplet with red, green, and blue components (0-255).
Console
The main console for rendering output.
ConsoleOptions
Options passed through the rendering pipeline.
Control
Emoji
A single emoji character.
Measurement
The minimum and maximum width requirements of a renderable.
PagerContext
A guard that captures console output and sends it to a pager on drop.
PagerOptions
Options for the pager context.
Palette
A palette of colors for color matching.
Segment
A segment of text with optional style and control codes.
SegmentLines
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.
StyleMeta
Metadata for styles, used for hyperlinks and custom data.
StyleStack
A stack of styles where the current style is the combination of all pushed styles.
Theme
A container for style information.
ThemeStack
A stack of themes for scoped style overrides.

Enums§

ColorSystem
The color system supported by a terminal.
ColorType
The type of color stored in a Color struct.
ControlType
Control codes that can be embedded in output.
EmojiVariant
Emoji variant selector.
JustifyMethod
Text justification method.
MetaValue
Structured metadata values (used by Textual handlers and richer annotations).
OverflowMethod
Text overflow handling method.
SimpleColor
Simple color enum for backward compatibility.
ThemeError
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.
RichCast
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 <= value from suffixes with 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.