Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Send + Sync {
Show 13 methods // Required method fn metadata(&self) -> &PluginMetadata; // Provided methods fn get_menu(&self) -> Vec<MenuItem> { ... } fn get_commands(&self) -> Vec<ModalItem> { ... } fn on_load<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn on_unload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn on_output<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _line: &'life1 str, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn on_input<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _input: &'life1 [u8], _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn on_pre_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _command: &'life1 str, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn on_post_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _command: &'life1 str, _exit_code: i32, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn on_resize<'life0, 'life1, 'async_trait>( &'life0 mut self, _cols: u16, _rows: u16, _ctx: &'life1 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn on_attach<'life0, 'life1, 'async_trait>( &'life0 mut self, _client_id: u64, _ctx: &'life1 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn on_detach<'life0, 'life1, 'async_trait>( &'life0 mut self, _client_id: u64, _ctx: &'life1 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn on_remote_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _id: &'life1 str, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... }
}
Expand description

Main plugin trait that all plugins must implement

Plugins can hook into various events in the terminal lifecycle. All methods have default implementations that do nothing.

Required Methods§

Source

fn metadata(&self) -> &PluginMetadata

Get plugin metadata

Provided Methods§

Source

fn get_menu(&self) -> Vec<MenuItem>

Get the menu items for this plugin’s dock menu

This defines the menu that appears when the plugin is activated from the dock. Return an empty Vec if the plugin has no menu.

§Example
use scarab_plugin_api::menu::{MenuItem, MenuAction};

fn get_menu(&self) -> Vec<MenuItem> {
    vec![
        MenuItem::new("Chat", MenuAction::remote("open_chat"))
            .with_icon("💬"),
        MenuItem::new("Settings", MenuAction::remote("settings"))
            .with_icon("⚙️"),
    ]
}
Source

fn get_commands(&self) -> Vec<ModalItem>

Get list of commands provided by this plugin

Source

fn on_load<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when the plugin is loaded

This is where plugins should initialize their state and resources.

Source

fn on_unload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when the plugin is being unloaded

Plugins should clean up resources here.

Source

fn on_output<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _line: &'life1 str, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hook called before output is displayed to the terminal

Plugins can modify, block, or pass through the output.

Source

fn on_input<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _input: &'life1 [u8], _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hook called after input is received from the user

Plugins can intercept and modify input before it reaches the PTY.

Source

fn on_pre_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _command: &'life1 str, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hook called before a command is executed

Source

fn on_post_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _command: &'life1 str, _exit_code: i32, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hook called after a command completes

Source

fn on_resize<'life0, 'life1, 'async_trait>( &'life0 mut self, _cols: u16, _rows: u16, _ctx: &'life1 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Hook called when terminal is resized

Source

fn on_attach<'life0, 'life1, 'async_trait>( &'life0 mut self, _client_id: u64, _ctx: &'life1 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Hook called when a client attaches to the session

Source

fn on_detach<'life0, 'life1, 'async_trait>( &'life0 mut self, _client_id: u64, _ctx: &'life1 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Hook called when a client detaches from the session

Source

fn on_remote_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _id: &'life1 str, _ctx: &'life2 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hook called when a remote command is selected/triggered by the client

This is called when a user selects a menu item with MenuAction::Remote(id).

Implementors§