use crate::auth::{AuthHandle, User};
use crate::theme::Theme;
use crossterm::event::KeyEvent;
use ratatui::layout::Rect;
use ratatui::Frame;
use std::path::Path;
use std::sync::Arc;
pub type PluginFactory = Arc<dyn Fn(&str, &str, &Path) -> Box<dyn Plugin> + Send + Sync>;
#[derive(Debug, Clone)]
pub struct PluginCmdItem {
pub category: String,
pub label: String,
}
pub trait Plugin {
fn id(&self) -> &str;
fn name(&self) -> &str;
fn init(&mut self, ctx: &mut PluginContext) -> Result<(), Box<dyn std::error::Error>>;
fn handle_key(&mut self, _key: KeyEvent) -> bool {
false
}
fn render(&self, _f: &mut Frame, _area: Rect) {}
fn tick(&mut self) {}
fn on_focus(&mut self) {}
fn on_blur(&mut self) {}
fn on_theme_change(&mut self, theme: &Theme) {
let _ = theme;
}
fn on_user_update(&mut self, _user: Option<&User>) {}
fn status_hints(&self) -> Vec<(String, String)> {
vec![]
}
fn commands(&self) -> Vec<PluginCmdItem> {
vec![]
}
fn handle_palette_command(&mut self, _index: usize) {}
fn on_plugin_message(&mut self, _from: &str, _action: &str, _data: &str) {}
fn shutdown(&mut self) {}
fn binary_path(&self) -> Option<&Path> {
None
}
}
pub struct PluginContext {
pub theme: Theme,
pub auth: Option<Arc<dyn AuthHandle>>,
}
impl PluginContext {
pub fn new() -> Self {
PluginContext {
theme: Theme::default(),
auth: None,
}
}
}
impl Default for PluginContext {
fn default() -> Self {
Self::new()
}
}