Skip to main content

Module protocol

Module protocol 

Source
Expand description

Rendering & extension protocols.

Port of upstream rich/protocol.py + rich/abc.py + the highlighter interface. These traits are the sanctioned extension points of the port. Extensions in rich-ext (and, later, third-party plugins) implement them; the faithful core only ever ships upstream’s built-in implementations. See docs/PLUGINS.md.

Structs§

CodeHighlighting
A console-wide default CodeHighlighter and the theme to use with it. See ConsoleCodeHighlighting.
HighlightSpan
One styled byte range of a highlighted line.
HighlightedCode
What a CodeHighlighter returns: one HighlightedLine per element of code.split('\n'), so a trailing newline yields a final empty line.
HighlightedLine
The spans of one source line, plus the style of the line break after it.
RegionGuard
An entered region, exited when dropped, so an early return still exits.
RegionId
A region’s identity, chosen by the RegionSink that recorded it.
RegionInfo
A region a renderable reports: its role, and an optional label (a panel’s title, a heading’s text) and link target.
TargetCapabilities
Immutable destination capabilities supplied by an extension. No detection or I/O.

Enums§

HighlightError
Why a CodeHighlighter could not highlight. An unknown language is not an error: highlighters fall back to plain text.
RegionRole
What a semantic region is: the role a renderable reports for the cells it drew. See RegionSink.
Support
Evidence for an optional output protocol; inference is not confirmation.

Constants§

REGION_META_KEY
The Meta key under which a region’s id rides on the styles of the segments it drew. It never renders.

Traits§

CodeHighlighter
A syntax-highlighting engine behind Syntax and Markdown code blocks.
ConsoleCodeHighlighting
Attach/query a console’s default code highlighter.
ConsoleEnvironment
Attach/query a per-console immutable extension environment.
ConsoleRegions
Attach/query a console’s RegionSink.
FenceRenderer
Renders fenced Markdown code blocks of particular languages (for example ```mermaid) in place of the usual highlighted code.
Highlighter
A transformer that adds style spans to Text (e.g. syntax/number/URL highlighting). The Rust equivalent of upstream’s Highlighter ABC.
LineRenderable
Optional line-streaming extension point for renderables.
OwnedTableRows
Transfer already-owned table rows without cloning every cell string.
RegionSink
Observes semantic regions (#226): which cells a panel, table, table cell, rule, Markdown heading or code block drew. Not part of upstream.
RenderEnvironment
Optional context shared by nested renderables without changing their protocol.
Renderable
Anything that can be rendered to a stream of Segments within a width.

Functions§

enter_region
Enter a region when console has a sink. With none, None, and info is never called.
region_of
The region style was tagged with, if any.
report_region
render() as a region. Without a sink, exactly render().
tag_region
Set REGION_META_KEY to id on every non-control segment that has no region yet. An unstyled segment gets a style holding only the tag.