Skip to main content

Crate rich_plugin_api

Crate rich_plugin_api 

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

PluginMetadata
Who a plugin is. Build it with PluginMetadata::new.

Enums§

Capability
One thing a plugin registered, as a host reports it.
PluginError
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_version equals the host’s.

Traits§

Plugin
Something that extends rich.
PluginRegistrar
What a plugin can add. Plugin::register receives one of these.
SourceRenderer
Turns source text into a renderable: a diagram, a data format, a report. Registered under a name with PluginRegistrar::renderer.
TextTransform
Rewrites a Text: keeps some lines, styles matches, masks secrets. Registered under a name with PluginRegistrar::transform; a host chains named transforms into a pipeline.

Functions§

is_valid_name
Whether name is 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§

HighlighterFactory
Makes a fresh regex Highlighter each time a host installs it, so one registration can be installed onto many consoles.