pub use scarab_protocol::{ModalItem, OverlayStyle};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq)]
pub struct OverlayConfig {
pub x: u16,
pub y: u16,
pub content: String,
pub style: OverlayStyle,
}
impl OverlayConfig {
pub fn new(x: u16, y: u16, content: impl Into<String>) -> Self {
Self {
x,
y,
content: content.into(),
style: OverlayStyle::default(),
}
}
pub fn with_style(mut self, style: OverlayStyle) -> Self {
self.style = style;
self
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct StatusBarItem {
pub label: String,
pub content: String,
pub priority: i32,
}
impl StatusBarItem {
pub fn new(label: impl Into<String>, content: impl Into<String>) -> Self {
Self {
label: label.into(),
content: content.into(),
priority: 0,
}
}
pub fn with_priority(mut self, priority: i32) -> Self {
self.priority = priority;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum JumpDirection {
Up,
Down,
First,
Last,
}
#[derive(Debug, Clone)]
pub enum RemoteCommand {
DrawOverlay {
id: u64,
x: u16,
y: u16,
text: String,
style: OverlayStyle,
},
ClearOverlays {
id: Option<u64>,
},
ShowModal {
title: String,
items: Vec<ModalItem>,
},
PluginLog {
plugin_name: String,
level: crate::context::LogLevel,
message: String,
},
PluginNotify {
title: String,
body: String,
level: crate::context::NotifyLevel,
},
ThemeUpdate {
theme_json: String,
},
NavEnterHintMode {
plugin_name: String,
},
NavExitMode {
plugin_name: String,
},
NavRegisterFocusable {
plugin_name: String,
x: u16,
y: u16,
width: u16,
height: u16,
label: String,
action: scarab_protocol::NavFocusableAction,
},
NavUnregisterFocusable {
plugin_name: String,
focusable_id: u64,
},
SpawnOverlay {
plugin_name: String,
overlay_id: u64,
config: OverlayConfig,
},
RemoveOverlay {
plugin_name: String,
overlay_id: u64,
},
AddStatusItem {
plugin_name: String,
item_id: u64,
item: StatusBarItem,
},
RemoveStatusItem {
plugin_name: String,
item_id: u64,
},
PromptJump {
plugin_name: String,
direction: JumpDirection,
},
ApplyTheme {
plugin_name: String,
theme_name: String,
},
SetPaletteColor {
plugin_name: String,
color_name: String,
value: String,
},
GetCurrentTheme {
plugin_name: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Action {
Continue,
Stop,
Modify(Vec<u8>),
}
impl Action {
pub fn is_modify(&self) -> bool {
matches!(self, Action::Modify(_))
}
pub fn is_stop(&self) -> bool {
matches!(self, Action::Stop)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum HookType {
PreOutput,
PostInput,
PreCommand,
PostCommand,
OnResize,
OnAttach,
OnDetach,
}
impl HookType {
pub fn all() -> &'static [HookType] {
&[
HookType::PreOutput,
HookType::PostInput,
HookType::PreCommand,
HookType::PostCommand,
HookType::OnResize,
HookType::OnAttach,
HookType::OnDetach,
]
}
pub fn name(&self) -> &'static str {
match self {
HookType::PreOutput => "pre-output",
HookType::PostInput => "post-input",
HookType::PreCommand => "pre-command",
HookType::PostCommand => "post-command",
HookType::OnResize => "on-resize",
HookType::OnAttach => "on-attach",
HookType::OnDetach => "on-detach",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginInfo {
pub name: String,
pub version: String,
pub description: String,
pub author: String,
pub homepage: Option<String>,
pub api_version: String,
pub min_scarab_version: String,
pub enabled: bool,
pub failure_count: u32,
#[serde(default)]
pub emoji: Option<String>,
#[serde(default)]
pub color: Option<String>,
#[serde(default)]
pub catchphrase: Option<String>,
}
impl PluginInfo {
pub fn new(
name: impl Into<String>,
version: impl Into<String>,
description: impl Into<String>,
author: impl Into<String>,
) -> Self {
Self {
name: name.into(),
version: version.into(),
description: description.into(),
author: author.into(),
homepage: None,
api_version: crate::API_VERSION.to_string(),
min_scarab_version: "0.1.0".to_string(),
enabled: true,
failure_count: 0,
emoji: None,
color: None,
catchphrase: None,
}
}
pub fn display_name(&self) -> String {
if let Some(emoji) = &self.emoji {
format!("{} {}", emoji, self.name)
} else {
self.name.clone()
}
}
pub fn mood(&self) -> crate::delight::PluginMood {
crate::delight::PluginMood::from_failure_count(self.failure_count, 3, self.enabled)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Cell {
pub c: char,
pub fg: (u8, u8, u8),
pub bg: (u8, u8, u8),
pub bold: bool,
pub italic: bool,
pub underline: bool,
}
impl Default for Cell {
fn default() -> Self {
Self {
c: ' ',
fg: (255, 255, 255),
bg: (0, 0, 0),
bold: false,
italic: false,
underline: false,
}
}
}