1use crate::auth::{AuthHandle, User};
2use crate::theme::Theme;
3use crossterm::event::KeyEvent;
4use ratatui::layout::Rect;
5use ratatui::Frame;
6use std::path::{Path, PathBuf};
7use std::sync::Arc;
8
9pub type PluginFactory = Arc<dyn Fn(&str, &str, &Path) -> Box<dyn Plugin + Send> + Send + Sync>;
12
13#[derive(Debug, Clone)]
15pub struct PluginCmdItem {
16 pub category: String,
17 pub label: String,
18}
19
20pub trait Plugin: Send {
21 fn id(&self) -> &str;
22 fn name(&self) -> &str;
23 fn init(&mut self, ctx: &mut PluginContext) -> Result<(), Box<dyn std::error::Error>>;
24 fn handle_key(&mut self, _key: KeyEvent) -> bool {
25 false
26 }
27 fn render(&self, _f: &mut Frame, _area: Rect) {}
28 fn tick(&mut self) {}
29 fn on_focus(&mut self) {}
30 fn on_blur(&mut self) {}
31 fn on_theme_change(&mut self, theme: &Theme) {
32 let _ = theme;
33 }
34 fn on_user_update(&mut self, _user: Option<&User>) {}
35 fn status_hints(&self) -> Vec<(String, String)> {
36 vec![]
37 }
38 fn commands(&self) -> Vec<PluginCmdItem> {
40 vec![]
41 }
42 fn handle_palette_command(&mut self, _index: usize) {}
45
46 fn on_plugin_message(&mut self, _from: &str, _action: &str, _data: &str) {}
48
49 fn shutdown(&mut self) {}
54
55 fn binary_path(&self) -> Option<&Path> {
59 None
60 }
61}
62
63pub struct PluginContext {
64 pub theme: Theme,
65 pub auth: Option<Arc<dyn AuthHandle>>,
66 pub data_dir: PathBuf,
70}
71
72impl PluginContext {
73 pub fn new() -> Self {
74 PluginContext {
75 theme: Theme::default(),
76 auth: None,
77 data_dir: PathBuf::new(),
78 }
79 }
80}
81
82impl Default for PluginContext {
83 fn default() -> Self {
84 Self::new()
85 }
86}