Expand description
The plugin contract for the rich Rust port.
A plugin implements Plugin: it describes itself with PluginMetadata
and adds capabilities through a PluginRegistrar. A host (rs-rich-ext’s
ExtensionRegistry) calls Plugin::register, checks the result, and then
makes the capabilities available to consoles and commands.
This crate depends only on core rich, so a plugin never needs rs-rich-ext.
Everything first-party plugins do goes through this same contract.
use rich_plugin_api::{Plugin, PluginError, PluginMetadata, PluginRegistrar};
use rich::Theme;
struct Solarized;
impl Plugin for Solarized {
fn metadata(&self) -> PluginMetadata {
PluginMetadata::new("solarized", "Solarized themes", "1.0.0")
}
fn register(&self, registrar: &mut dyn PluginRegistrar) -> Result<(), PluginError> {
let theme = Theme::from_styles([("repr.number", "#268bd2")], true)
.map_err(|e| PluginError::Other(e.to_string()))?;
registrar.theme("solarized", theme);
Ok(())
}
}Stability: at 0.0.x this contract still changes. Every breaking change
bumps PLUGIN_API_VERSION, and hosts refuse a plugin built for another
version rather than misbehaving.
Structs§
- Plugin
Metadata - Who a plugin is. Build it with
PluginMetadata::new.
Enums§
- Capability
- One thing a plugin registered, as a host reports it.
- Plugin
Error - Why a plugin could not be added, or a renderer failed.
Constants§
- PLUGIN_
API_ VERSION - The version of this contract. A host accepts a plugin only if the plugin’s
PluginMetadata::api_versionequals the host’s.
Traits§
- Plugin
- Something that extends
rich. - Plugin
Registrar - What a plugin can add.
Plugin::registerreceives one of these. - Source
Renderer - Turns source text into a renderable: a diagram, a data format, a report.
Registered under a name with
PluginRegistrar::renderer. - Text
Transform - Rewrites a
Text: keeps some lines, styles matches, masks secrets. Registered under a name withPluginRegistrar::transform; a host chains named transforms into a pipeline.
Functions§
- is_
valid_ name - Whether
nameis a valid plugin id or capability name: lowercase letters, digits,-,_and., starting with a letter or digit so it is never read as a flag (-x) or a path component (.,..).
Type Aliases§
- Highlighter
Factory - Makes a fresh regex
Highlightereach time a host installs it, so one registration can be installed onto many consoles.