Skip to main content

PluginComponent

Trait PluginComponent 

Source
pub trait PluginComponent: Send {
    // Required methods
    fn handle(
        &mut self,
        event: &ComponentEvent,
        context: &ComponentContext<'_>,
    ) -> ComponentFlow;
    fn render(&self, context: &ComponentContext<'_>) -> ComponentView;

    // Provided methods
    fn bindings(&self) -> Vec<ComponentBinding> { ... }
    fn focusable(&self) -> bool { ... }
    fn tick(&self) -> Option<Duration> { ... }
    fn mouse(&self) -> bool { ... }
}
Expand description

An interactive component: a state machine that handles one event at a time and renders its state. Registered with PluginRegistrar::component through a ComponentFactory.

Key presses and pastes come as text from the user, and so does anything a component shows of them: treat them as untrusted. The host keeps terminal controls out of what is painted.

Required Methods§

Source

fn handle( &mut self, event: &ComponentEvent, context: &ComponentContext<'_>, ) -> ComponentFlow

Handle one event. Ctrl+C never arrives: the host ends the run.

Source

fn render(&self, context: &ComponentContext<'_>) -> ComponentView

Render the current state.

Provided Methods§

Source

fn bindings(&self) -> Vec<ComponentBinding>

The keys it uses now, for help and hints. None, by default.

Source

fn focusable(&self) -> bool

Whether it takes focus in a container. Yes, by default; a view that only shows something says no.

Source

fn tick(&self) -> Option<Duration>

How often it wants ComponentEvent::Tick. Never, by default.

Source

fn mouse(&self) -> bool

Whether it wants mouse events. No, by default: reporting the mouse takes text selection away from the terminal.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§