Skip to main content

Crate rich_ext

Crate rich_ext 

Source
Expand description

§rich-ext

Extensions layered on top of the faithful rich core, plus the internal plugin registry. Anything that is not a faithful port of upstream rich belongs here, so the core stays a clean, easily-synced mirror.

This crate carries its own independent SemVer (it does not track any upstream version). See AGENTS.md → Versioning and docs/PLUGINS.md.

§Modules

  • Errors and logs: diagnostic, dashboard, stacktrace, hyperlink, log_handler (RichHandler, SpanView), adapters (EventSink; LogAdapter and EventLayer with the log / tracing features), event, log_stream (log records parsed, filtered, collapsed and grouped, and ChannelSink).
  • Data and authoring: data, deps (Cargo dependency trees) and schema (JSON Schema trees and diffs, and the format-neutral schema model), all behind the data feature; derive, macros (the macros feature re-exports richf! and #[derive(Rich)]), inspect (rich.inspect from #[derive(Inspect)]), cli_doc (clap feature for clap::Command).
  • Diffs and testing: diff, testing and qa (testing feature).
  • Terminals: capabilities, fidelity, a11y, target, ansi_explain, sanitize, encoding, clipboard (OSC 52).
  • Workflows: workflow, transfer, countdown, notify, cancel, table, badge, size_bar, format, redact (experimental).
  • Charts: chart (sparklines, bars, histograms, line and scatter plots, gauges, heatmaps, status matrices, KPI cards and timelines; ratatui’s chart, canvas with a world map, and gauges).
  • Colour: palette (Tailwind’s and Material’s palettes; HSL, HSV, Okhsv and Oklab colours, blends and gradients).
  • Inspectors: source_view, hex, unicode_inspect, env_inspect.
  • Documents: document (Org, AsciiDoc and man pages beside Markdown and rst, with format detection; syntax feature).
  • Layout and live output: layout, live, surface (positioned drawing that writes only what changed).
  • Pipelines: transform, and data::transform (jsonpath feature).
  • Files: filetype (icons, colours, MIME types), fs (local times, owners), listing (entries, sorting, a tree walk), open (opener rules), file_ops (copy, move, delete with progress), trash (the FreeDesktop trash), git (status per file), and archive (tar and zip listing and extraction; archive feature).

The user guide (https://buchochelliq-labs.github.io/rs-rich-cli/guide/ext/) covers each module with compiled examples.

use rich::{Console, ColorSystem};
use rich_ext::ConsoleExt;

let mut console = Console::builder()
    .force_terminal(true)
    .color_system(Some(ColorSystem::Truecolor))
    .build();
console.install_extensions(); // registers the number highlighter, etc.
let out = console.render_str_to_string("count=7");
assert!(out.contains("\x1b[1;36m7\x1b[0m"));

Re-exports§

pub use highlighter::NumberHighlighter;
pub use registry::BuiltinPlugin;
pub use registry::ExtensionRegistry;
pub use registry::HighlighterChoiceError;
pub use registry::RegisteredPlugin;
pub use registry::install_defaults;
pub use sanitize::sanitize_terminal_controls;
pub use theme::EXTRA_STYLES;
pub use theme::extended_theme;
pub use inspect::Inspect;
pub use inspect::Inspectable;
pub use inspect::inspect;
pub use log_handler::RichHandler;
pub use log_handler::SpanView;
pub use rich_plugin_api as plugin;

Modules§

a11y
Accessibility: semantic text for screen readers (semantic), user presentation preferences (policy) and colour checks (contrast).
adapters
Facade adapters with explicit ownership; no global installation. EventSink is always here; LogAdapter needs the log feature and EventLayer the tracing feature.
ansi_explain
Explain terminal output: tokenize text with escape sequences and describe every sequence in words.
archive
What is inside an archive, and taking it out: the entries of a tar, gzipped tar or zip file (entries), and extraction into a directory (extract) that never writes outside it. A file manager previews an archive with the listing and extracts it with Yazi’s extract opener.
badge
Compact badges and status chips for statuses, labels, links and metadata.
cancel
A shared cancellation flag for workflows: task trees, transfers, retries.
capabilities
Terminal capability detection with provenance. No probes: every answer is derived from environment variables and tty facts supplied through an Environment, so detection is deterministic under a MapEnvironment.
chart
Charts drawn with text: sparklines, bars, histograms, line and scatter plots, and the KPI and status renderables a dashboard is made of (gauges, heatmaps, status matrices, KPI cards and timelines).
cli
Optional CLI conveniences, kept outside the faithful command parser.
cli_doc
CLI authoring: describe a command once, then render its help, errors, shell completions, Markdown and man pages, config reference and config precedence through rich.
clipboard
Copy to the terminal’s clipboard with OSC 52 (#488), and the text a table cell or row copies as (#434).
countdown
Retry and rate-limit countdowns: a Backoff policy, the RetryStatus and RateLimit lines, a shrinking CountdownBar, and CountdownWait, which waits while showing the time left.
dashboard
A dashboard over many diagnostics: counts by level, the most frequent codes, and every diagnostic grouped by file in location order.
data
Structured data: a format-neutral document tree, parsers that fill it, and views that render it.
deps
Cargo dependency graphs (#248), read from cargo metadata.
derive
The runtime behind #[derive(Rich)] (the macros feature).
diagnostic
Compiler-style diagnostics. They render supplied source only; no filesystem or clock access.
diff
Diffs: an engine, terminal views and the inputs they read.
document
Documentation formats: Markdown, reStructuredText, Org, AsciiDoc and man pages, behind one DocumentFormat interface.
dsp
Signal processing for live views of audio and other sampled data: a fast Fourier transform, a Hann window and magnitude spectra; test signals (tones, harmonic partials, noise and a mix of them); trigger detection, as an oscilloscope’s; a spectrum’s peak and log-spaced bands, with levels that fall under gravity (Falloff), as a bar spectrum’s (cava’s); and the frequencies of musical notes, in equal temperament or scope-tui’s table (NoteTable), with the note nearest a frequency, and a Tuner reading a spectrum’s note and cents, smoothed.
encoding
Explicit text decoding for CLI and application inputs.
env_inspect
Inspect environment variables and PATH-like lists.
event
Typed, ordered events. Time and context are supplied by the caller.
fidelity
Graceful degradation: pick how rich output may be, then render at that level.
file_ops
File operations as a file manager runs them: copy, move, link, delete and trash, reporting progress as they go and stopping when cancelled, with Yazi’s rules for names that are taken (a copy gets _1, _2… before its extension) and for directories pasted into themselves (refused).
filetype
File-type icons, colours and MIME types, for file managers and pickers: the glyph and colour Yazi shows by default for a file, a MIME type guessed from a name or from the first bytes, Yazi’s type colours, and whether a Nerd Font is likely in use.
format
Semantic formatters: sizes, rates, durations, times, percentages and numbers as people read them.
frame
Frames: a rendered result as rows of styled runs (#226).
fs
What a file listing shows beside a name: times in the local time zone, and the names of a file’s owner and group.
git
Git’s view of a working tree, file by file: what git status says of each path (modified, added, untracked, ignored, …), read from git status --porcelain=v1 -z in a subprocess, with no git library. A file manager shows it as a sign beside each name, as Yazi’s git plugin does; a directory takes the most pressing change inside it.
gradient
Text coloured along a gradient: GradientText puts each character of a Text at its place along two or more colours, across, down or corner to corner, through palette::gradient.
graphics
What a terminal can draw beyond text (#573): the graphics protocol, and the size of one cell in pixels.
hex
A byte and hex inspector in the style of hexdump -C.
highlighter
Example extension: a number highlighter.
hyperlink
Semantic hyperlinks for URLs, paths, source locations and references.
inspect
A report on a Rust value, laid out as upstream’s rich.inspect lays out its report on a Python object (rich/_inspect.py, #796).
layout
Bounded extension layouts.
listing
Directory listings as a file manager shows them: the entries of a directory with what a row needs (size, mode, times, owner, where a link points), sorted as Yazi sorts them, and the cells its line modes write; plus a directory walk for finders.
live
Synchronous single-writer coordination for inline terminal regions.
log_handler
A log sink in the style of upstream rich.logging.RichHandler.
log_stream
Log streams: records read from JSON Lines or plain-text logs, then filtered, collapsed and grouped (#724).
macros
Convenience macros and the print helpers they use.
markdown_export
GitHub-flavoured Markdown from renderables, for pull request comments, issue bodies and job summaries.
notify
Transient notifications for command-line apps: small toasts that appear beside live output and vanish when they expire, without a full-screen UI.
open
Which program opens a file: Yazi’s [opener] and [open] tables as data. An Opener says how to open (the editor, the system’s opener, a folder view, a shell command, or extracting an archive) and whether it takes the terminal; a Rule picks openers by MIME type or name glob; Rules::matching gives the openers for a file, the first one what Enter uses.
palette
Colour palettes, and colours made from numbers: Tailwind CSS’s and Material Design’s palettes as #rrggbb constants, and helpers that make a rich::Color from HSL, HSV, Okhsv or Oklab, or mix colours.
plugin_loading
Runtime plugins: native libraries and WASM modules loaded from a path.
qa
Render quality tooling: screenshots, layout stress, lint, explain, profiling, fuzzing, a capability matrix and benchmarks.
qr
QR codes drawn with text: QrCode encodes text or bytes and draws the modules two to a cell with half blocks, inside a quiet zone, so a phone can read it off the terminal.
redact
Redact secrets from strings, terminal output, rendered segments and exports.
registry
The extension registry: where plugins are hosted.
rst
reStructuredText, rendered as rich-rst 2.2.0 renders it: the RestructuredText renderable that rich-cli’s --rst prints.
sanitize
Opt-in input sanitizing for terminal-control bytes.
schema
Schemas drawn as trees (#244), what changed between two (#268), and how a schema evolved (#347), for JSON Schema, SQL DDL, Arrow and anything else in the format-neutral model.
size_bar
A compact bar for a size relative to a total or a limit.
source_view
A line-numbered, searchable view of a source file.
sql
A small SQL highlighter in pure Rust: no syntect, no C, no dependencies.
stacktrace
Stack traces from Rust, Python, Java and JavaScript, in one shape.
surface
Positioned drawing: render any rich renderable into a rectangle of the terminal, and write only the cells that changed.
syntax
Warming up syntax highlighting before it is first needed.
table
Table data operations layered on the core rich::Table.
target
Explicit destinations for deterministic, nested rendering. No environment probes.
testing
Deterministic snapshots for downstream render regression tests.
theme
Extra named styles layered on the upstream theme.
transfer
Download and upload progress: byte counts with a smoothed rate, an ETA, retries and cancellation.
transform
Composable transforms: rewrite what is about to be rendered, one stage at a time.
trash
The desktop trash, as the FreeDesktop.org trash specification keeps it: put moves a file or directory to the trash with a note of where it was and when, list reads what is there, restore puts an item back and purge deletes it for good. File managers on Linux and the BSDs (GNOME Files, Dolphin, Thunar, Yazi through trash-cli) share this trash, so what is put here shows up in theirs.
unicode_inspect
Inspect text one grapheme cluster at a time.
workflow
Workflow renderables: commands, task trees and completion summaries.

Macros§

assert_render_eq
Assert a renderable renders as expected at width (default 80) through a plain, deterministic target; trailing whitespace is ignored.
assert_rich_eq
Assert two strings are equal; on failure, panic with a rendered line diff.
assert_rich_json_eq
Assert two Serialize values are equal as JSON; on failure, panic with a diff of both pretty-printed.
assert_snapshot_eq
Assert two RenderSnapshots are equal; on failure, panic with their ANSI diff (style-only changes marked ~) and the first differing field.
markup
Check a markup literal at compile time and return it as &'static str. Accepts keys[...] before the literal, as richf! does.
rich_dbg
dbg! through Pretty: prints [file:line:column] expression = value to standard error with the value highlighted, and returns the value.
rich_eprintln
Print checked markup to standard error.
rich_inspect
Print a report on a value to standard output, its source text in the title. Options follow as name = value: help, methods, docs, private, sort, value, types, variants, all, title, max_depth.
rich_panel
A panel around a renderable, or around markup when given a string literal. Optional title = … and subtitle = … follow.
rich_println
Print checked markup to standard output: rich_println!("[bold]{x}[/]").
rich_progress
Iterate with a progress bar on standard output: core’s track.
rich_table
A table from a header row and cell rows; each cell is anything Display. Headers and cells are displayed literally, never parsed as markup.
rich_trace
Print checked markup to standard error after a dim file:line — a quick trace line. For log pipelines, route log/tracing through RichHandler.
rich_tree
A tree from nested labels: rich_tree!("root" => ["a", "b" => ["c"]]). Labels are displayed literally, never parsed as markup.
richf
A Text from checked markup with format!-style placeholders.
style
A Style parsed at compile time: style!("bold red on white").
theme_key
A theme key checked against the default theme: theme_key!("repr.number") expands to the &'static str.

Traits§

ConsoleExt
Ergonomic extension methods on the core Console.

Attribute Macros§

inspect
Record an inherent impl block’s methods for rich_ext::inspect: each fn’s name, signature as written, doc comment, and whether it is pub or async. Mark the type #[inspect(methods)] to list them; one block per type. #[inspect(skip)] on a method leaves it out.

Derive Macros§

Inspect
Record what rich_ext::inspect reports on a struct or enum: the type’s name and doc comment, each field’s name, type as written, doc comment, visibility and value, and an enum’s variants.
Rich
Render a struct or enum through rich_ext::derive.