use crate::input::actions::Action;
use crate::input::config::ConversionError;
use clap::ArgEnum;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use strum_macros::{Display, EnumDiscriminants, EnumIter, EnumString, ToString};
pub type ClientId = u16; pub fn client_id_to_colors(
client_id: ClientId,
colors: Palette,
) -> Option<(PaletteColor, PaletteColor)> {
match client_id {
1 => Some((colors.magenta, colors.black)),
2 => Some((colors.blue, colors.black)),
3 => Some((colors.purple, colors.black)),
4 => Some((colors.yellow, colors.black)),
5 => Some((colors.cyan, colors.black)),
6 => Some((colors.gold, colors.black)),
7 => Some((colors.red, colors.black)),
8 => Some((colors.silver, colors.black)),
9 => Some((colors.pink, colors.black)),
10 => Some((colors.brown, colors.black)),
_ => None,
}
}
pub fn single_client_color(colors: Palette) -> (PaletteColor, PaletteColor) {
(colors.green, colors.black)
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
pub enum Key {
PageDown,
PageUp,
Left,
Down,
Up,
Right,
Home,
End,
Backspace,
Delete,
Insert,
F(u8),
Char(char),
Alt(CharOrArrow),
Ctrl(char),
BackTab,
Null,
Esc,
}
impl FromStr for Key {
type Err = Box<dyn std::error::Error>;
fn from_str(key_str: &str) -> Result<Self, Self::Err> {
let mut modifier: Option<&str> = None;
let mut main_key: Option<&str> = None;
for (index, part) in key_str.split_ascii_whitespace().enumerate() {
if index == 0 && (part == "Ctrl" || part == "Alt") {
modifier = Some(part);
} else if main_key.is_none() {
main_key = Some(part)
}
}
match (modifier, main_key) {
(Some("Ctrl"), Some(main_key)) => {
let mut key_chars = main_key.chars();
let key_count = main_key.chars().count();
if key_count == 1 {
let key_char = key_chars.next().unwrap();
Ok(Key::Ctrl(key_char))
} else {
Err(format!("Failed to parse key: {}", key_str).into())
}
},
(Some("Alt"), Some(main_key)) => {
match main_key {
"Left" => Ok(Key::Alt(CharOrArrow::Direction(Direction::Left))),
"Right" => Ok(Key::Alt(CharOrArrow::Direction(Direction::Right))),
"Up" => Ok(Key::Alt(CharOrArrow::Direction(Direction::Up))),
"Down" => Ok(Key::Alt(CharOrArrow::Direction(Direction::Down))),
_ => {
let mut key_chars = main_key.chars();
let key_count = main_key.chars().count();
if key_count == 1 {
let key_char = key_chars.next().unwrap();
Ok(Key::Alt(CharOrArrow::Char(key_char)))
} else {
Err(format!("Failed to parse key: {}", key_str).into())
}
},
}
},
(None, Some(main_key)) => match main_key {
"Backspace" => Ok(Key::Backspace),
"Left" => Ok(Key::Left),
"Right" => Ok(Key::Right),
"Up" => Ok(Key::Up),
"Down" => Ok(Key::Down),
"Home" => Ok(Key::Home),
"End" => Ok(Key::End),
"PageUp" => Ok(Key::PageUp),
"PageDown" => Ok(Key::PageDown),
"Tab" => Ok(Key::BackTab),
"Delete" => Ok(Key::Delete),
"Insert" => Ok(Key::Insert),
"Space" => Ok(Key::Char(' ')),
"Enter" => Ok(Key::Char('\n')),
"Esc" => Ok(Key::Esc),
_ => {
let mut key_chars = main_key.chars();
let key_count = main_key.chars().count();
if key_count == 1 {
let key_char = key_chars.next().unwrap();
Ok(Key::Char(key_char))
} else if key_count > 1 {
if let Some(first_char) = key_chars.next() {
if first_char == 'F' {
let f_index: String = key_chars.collect();
let f_index: u8 = f_index
.parse()
.map_err(|e| format!("Failed to parse F index: {}", e))?;
if f_index >= 1 && f_index <= 12 {
return Ok(Key::F(f_index));
}
}
}
Err(format!("Failed to parse key: {}", key_str).into())
} else {
Err(format!("Failed to parse key: {}", key_str).into())
}
},
},
_ => Err(format!("Failed to parse key: {}", key_str).into()),
}
}
}
impl fmt::Display for Key {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Key::Backspace => write!(f, "BACKSPACE"),
Key::Left => write!(f, "{}", Direction::Left),
Key::Right => write!(f, "{}", Direction::Right),
Key::Up => write!(f, "{}", Direction::Up),
Key::Down => write!(f, "{}", Direction::Down),
Key::Home => write!(f, "HOME"),
Key::End => write!(f, "END"),
Key::PageUp => write!(f, "PgUp"),
Key::PageDown => write!(f, "PgDn"),
Key::BackTab => write!(f, "TAB"),
Key::Delete => write!(f, "DEL"),
Key::Insert => write!(f, "INS"),
Key::F(n) => write!(f, "F{}", n),
Key::Char(c) => match c {
'\n' => write!(f, "ENTER"),
'\t' => write!(f, "TAB"),
' ' => write!(f, "SPACE"),
_ => write!(f, "{}", c),
},
Key::Alt(c) => write!(f, "Alt+{}", c),
Key::Ctrl(c) => write!(f, "Ctrl+{}", Key::Char(*c)),
Key::Null => write!(f, "NULL"),
Key::Esc => write!(f, "ESC"),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
#[serde(untagged)]
pub enum CharOrArrow {
Char(char),
Direction(Direction),
}
impl fmt::Display for CharOrArrow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CharOrArrow::Char(c) => write!(f, "{}", Key::Char(*c)),
CharOrArrow::Direction(d) => write!(f, "{}", d),
}
}
}
#[derive(Eq, Clone, Copy, Debug, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub enum Direction {
Left,
Right,
Up,
Down,
}
impl Direction {
pub fn invert(&self) -> Direction {
match *self {
Direction::Left => Direction::Right,
Direction::Down => Direction::Up,
Direction::Up => Direction::Down,
Direction::Right => Direction::Left,
}
}
pub fn is_horizontal(&self) -> bool {
matches!(self, Direction::Left | Direction::Right)
}
pub fn is_vertical(&self) -> bool {
matches!(self, Direction::Down | Direction::Up)
}
}
impl fmt::Display for Direction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Direction::Left => write!(f, "←"),
Direction::Right => write!(f, "→"),
Direction::Up => write!(f, "↑"),
Direction::Down => write!(f, "↓"),
}
}
}
impl FromStr for Direction {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Left" | "left" => Ok(Direction::Left),
"Right" | "right" => Ok(Direction::Right),
"Up" | "up" => Ok(Direction::Up),
"Down" | "down" => Ok(Direction::Down),
_ => Err(format!(
"Failed to parse Direction. Unknown Direction: {}",
s
)),
}
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize, Serialize)]
pub enum Resize {
Increase,
Decrease,
}
impl Resize {
pub fn invert(&self) -> Self {
match self {
Resize::Increase => Resize::Decrease,
Resize::Decrease => Resize::Increase,
}
}
}
impl fmt::Display for Resize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Resize::Increase => write!(f, "+"),
Resize::Decrease => write!(f, "-"),
}
}
}
impl FromStr for Resize {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Increase" | "increase" | "+" => Ok(Resize::Increase),
"Decrease" | "decrease" | "-" => Ok(Resize::Decrease),
_ => Err(format!(
"failed to parse resize type. Unknown specifier '{}'",
s
)),
}
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize, Serialize)]
pub struct ResizeStrategy {
pub resize: Resize,
pub direction: Option<Direction>,
pub invert_on_boundaries: bool,
}
impl From<Direction> for ResizeStrategy {
fn from(direction: Direction) -> Self {
ResizeStrategy::new(Resize::Increase, Some(direction))
}
}
impl From<Resize> for ResizeStrategy {
fn from(resize: Resize) -> Self {
ResizeStrategy::new(resize, None)
}
}
impl ResizeStrategy {
pub fn new(resize: Resize, direction: Option<Direction>) -> Self {
ResizeStrategy {
resize,
direction,
invert_on_boundaries: true,
}
}
pub fn invert(&self) -> ResizeStrategy {
let resize = match self.resize {
Resize::Increase => Resize::Decrease,
Resize::Decrease => Resize::Increase,
};
let direction = match self.direction {
Some(direction) => Some(direction.invert()),
None => None,
};
ResizeStrategy::new(resize, direction)
}
pub fn resize_type(&self) -> Resize {
self.resize
}
pub fn direction(&self) -> Option<Direction> {
self.direction
}
pub fn direction_horizontal(&self) -> bool {
matches!(
self.direction,
Some(Direction::Left) | Some(Direction::Right)
)
}
pub fn direction_vertical(&self) -> bool {
matches!(self.direction, Some(Direction::Up) | Some(Direction::Down))
}
pub fn resize_increase(&self) -> bool {
self.resize == Resize::Increase
}
pub fn resize_decrease(&self) -> bool {
self.resize == Resize::Decrease
}
pub fn move_left_border_left(&self) -> bool {
(self.resize == Resize::Increase) && (self.direction == Some(Direction::Left))
}
pub fn move_left_border_right(&self) -> bool {
(self.resize == Resize::Decrease) && (self.direction == Some(Direction::Left))
}
pub fn move_lower_border_down(&self) -> bool {
(self.resize == Resize::Increase) && (self.direction == Some(Direction::Down))
}
pub fn move_lower_border_up(&self) -> bool {
(self.resize == Resize::Decrease) && (self.direction == Some(Direction::Down))
}
pub fn move_upper_border_up(&self) -> bool {
(self.resize == Resize::Increase) && (self.direction == Some(Direction::Up))
}
pub fn move_upper_border_down(&self) -> bool {
(self.resize == Resize::Decrease) && (self.direction == Some(Direction::Up))
}
pub fn move_right_border_right(&self) -> bool {
(self.resize == Resize::Increase) && (self.direction == Some(Direction::Right))
}
pub fn move_right_border_left(&self) -> bool {
(self.resize == Resize::Decrease) && (self.direction == Some(Direction::Right))
}
pub fn move_all_borders_out(&self) -> bool {
(self.resize == Resize::Increase) && (self.direction == None)
}
pub fn move_all_borders_in(&self) -> bool {
(self.resize == Resize::Decrease) && (self.direction == None)
}
}
impl fmt::Display for ResizeStrategy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let resize = match self.resize {
Resize::Increase => "increase",
Resize::Decrease => "decrease",
};
let border = match self.direction {
Some(Direction::Left) => "left",
Some(Direction::Down) => "bottom",
Some(Direction::Up) => "top",
Some(Direction::Right) => "right",
None => "every",
};
write!(f, "{} size on {} border", resize, border)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Mouse {
ScrollUp(usize), ScrollDown(usize), LeftClick(isize, usize), RightClick(isize, usize), Hold(isize, usize), Release(isize, usize), }
#[derive(Debug, Clone, PartialEq, EnumDiscriminants, ToString, Serialize, Deserialize)]
#[strum_discriminants(derive(EnumString, Hash, Serialize, Deserialize))]
#[strum_discriminants(name(EventType))]
#[non_exhaustive]
pub enum Event {
ModeUpdate(ModeInfo),
TabUpdate(Vec<TabInfo>),
PaneUpdate(PaneManifest),
Key(Key),
Mouse(Mouse),
Timer(f64),
CopyToClipboard(CopyDestination),
SystemClipboardFailure,
InputReceived,
Visible(bool),
CustomMessage(
String, String, ),
FileSystemCreate(Vec<PathBuf>),
FileSystemRead(Vec<PathBuf>),
FileSystemUpdate(Vec<PathBuf>),
FileSystemDelete(Vec<PathBuf>),
PermissionRequestResult(PermissionStatus),
SessionUpdate(Vec<SessionInfo>),
}
#[derive(
Debug,
PartialEq,
Eq,
Hash,
Copy,
Clone,
EnumDiscriminants,
ToString,
Serialize,
Deserialize,
PartialOrd,
Ord,
)]
#[strum_discriminants(derive(EnumString, Hash, Serialize, Deserialize, Display, PartialOrd, Ord))]
#[strum_discriminants(name(PermissionType))]
#[non_exhaustive]
pub enum Permission {
ReadApplicationState,
ChangeApplicationState,
OpenFiles,
RunCommands,
OpenTerminalsOrPlugins,
WriteToStdin,
}
impl PermissionType {
pub fn display_name(&self) -> String {
match self {
PermissionType::ReadApplicationState => {
"Access Zellij state (Panes, Tabs and UI)".to_owned()
},
PermissionType::ChangeApplicationState => {
"Change Zellij state (Panes, Tabs and UI)".to_owned()
},
PermissionType::OpenFiles => "Open files (eg. for editing)".to_owned(),
PermissionType::RunCommands => "Run commands".to_owned(),
PermissionType::OpenTerminalsOrPlugins => "Start new terminals and plugins".to_owned(),
PermissionType::WriteToStdin => "Write to standard input (STDIN)".to_owned(),
}
}
}
#[derive(Debug, Clone)]
pub struct PluginPermission {
pub name: String,
pub permissions: Vec<PermissionType>,
}
impl PluginPermission {
pub fn new(name: String, permissions: Vec<PermissionType>) -> Self {
PluginPermission { name, permissions }
}
}
#[derive(
Debug,
PartialEq,
Eq,
Hash,
Copy,
Clone,
EnumIter,
Serialize,
Deserialize,
ArgEnum,
PartialOrd,
Ord,
)]
pub enum InputMode {
#[serde(alias = "normal")]
Normal,
#[serde(alias = "locked")]
Locked,
#[serde(alias = "resize")]
Resize,
#[serde(alias = "pane")]
Pane,
#[serde(alias = "tab")]
Tab,
#[serde(alias = "scroll")]
Scroll,
#[serde(alias = "entersearch")]
EnterSearch,
#[serde(alias = "search")]
Search,
#[serde(alias = "renametab")]
RenameTab,
#[serde(alias = "renamepane")]
RenamePane,
#[serde(alias = "session")]
Session,
#[serde(alias = "move")]
Move,
#[serde(alias = "prompt")]
Prompt,
#[serde(alias = "tmux")]
Tmux,
}
impl Default for InputMode {
fn default() -> InputMode {
InputMode::Normal
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum ThemeHue {
Light,
Dark,
}
impl Default for ThemeHue {
fn default() -> ThemeHue {
ThemeHue::Dark
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum PaletteColor {
Rgb((u8, u8, u8)),
EightBit(u8),
}
impl Default for PaletteColor {
fn default() -> PaletteColor {
PaletteColor::EightBit(0)
}
}
impl FromStr for InputMode {
type Err = ConversionError;
fn from_str(s: &str) -> Result<Self, ConversionError> {
match s {
"normal" | "Normal" => Ok(InputMode::Normal),
"locked" | "Locked" => Ok(InputMode::Locked),
"resize" | "Resize" => Ok(InputMode::Resize),
"pane" | "Pane" => Ok(InputMode::Pane),
"tab" | "Tab" => Ok(InputMode::Tab),
"search" | "Search" => Ok(InputMode::Search),
"scroll" | "Scroll" => Ok(InputMode::Scroll),
"renametab" | "RenameTab" => Ok(InputMode::RenameTab),
"renamepane" | "RenamePane" => Ok(InputMode::RenamePane),
"session" | "Session" => Ok(InputMode::Session),
"move" | "Move" => Ok(InputMode::Move),
"prompt" | "Prompt" => Ok(InputMode::Prompt),
"tmux" | "Tmux" => Ok(InputMode::Tmux),
"entersearch" | "Entersearch" | "EnterSearch" => Ok(InputMode::EnterSearch),
e => Err(ConversionError::UnknownInputMode(e.into())),
}
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum PaletteSource {
Default,
Xresources,
}
impl Default for PaletteSource {
fn default() -> PaletteSource {
PaletteSource::Default
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
pub struct Palette {
pub source: PaletteSource,
pub theme_hue: ThemeHue,
pub fg: PaletteColor,
pub bg: PaletteColor,
pub black: PaletteColor,
pub red: PaletteColor,
pub green: PaletteColor,
pub yellow: PaletteColor,
pub blue: PaletteColor,
pub magenta: PaletteColor,
pub cyan: PaletteColor,
pub white: PaletteColor,
pub orange: PaletteColor,
pub gray: PaletteColor,
pub purple: PaletteColor,
pub gold: PaletteColor,
pub silver: PaletteColor,
pub pink: PaletteColor,
pub brown: PaletteColor,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub struct Style {
pub colors: Palette,
pub rounded_corners: bool,
pub hide_session_name: bool,
}
pub type KeybindsVec = Vec<(InputMode, Vec<(Key, Vec<Action>)>)>;
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ModeInfo {
pub mode: InputMode,
pub keybinds: KeybindsVec,
pub style: Style,
pub capabilities: PluginCapabilities,
pub session_name: Option<String>,
}
impl ModeInfo {
pub fn get_mode_keybinds(&self) -> Vec<(Key, Vec<Action>)> {
self.get_keybinds_for_mode(self.mode)
}
pub fn get_keybinds_for_mode(&self, mode: InputMode) -> Vec<(Key, Vec<Action>)> {
for (vec_mode, map) in &self.keybinds {
if mode == *vec_mode {
return map.to_vec();
}
}
vec![]
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct SessionInfo {
pub name: String,
pub tabs: Vec<TabInfo>,
pub panes: PaneManifest,
pub connected_clients: usize,
pub is_current_session: bool,
}
use std::hash::{Hash, Hasher};
#[allow(clippy::derive_hash_xor_eq)]
impl Hash for SessionInfo {
fn hash<H: Hasher>(&self, state: &mut H) {
self.name.hash(state);
}
}
impl SessionInfo {
pub fn new(name: String) -> Self {
SessionInfo {
name,
..Default::default()
}
}
pub fn update_tab_info(&mut self, new_tab_info: Vec<TabInfo>) {
self.tabs = new_tab_info;
}
pub fn update_pane_info(&mut self, new_pane_info: PaneManifest) {
self.panes = new_pane_info;
}
pub fn update_connected_clients(&mut self, new_connected_clients: usize) {
self.connected_clients = new_connected_clients;
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct TabInfo {
pub position: usize,
pub name: String,
pub active: bool,
pub panes_to_hide: usize,
pub is_fullscreen_active: bool,
pub is_sync_panes_active: bool,
pub are_floating_panes_visible: bool,
pub other_focused_clients: Vec<ClientId>,
pub active_swap_layout_name: Option<String>,
pub is_swap_layout_dirty: bool,
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct PaneManifest {
pub panes: HashMap<usize, Vec<PaneInfo>>, }
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct PaneInfo {
pub id: u32,
pub is_plugin: bool,
pub is_focused: bool,
pub is_fullscreen: bool,
pub is_floating: bool,
pub is_suppressed: bool,
pub title: String,
pub exited: bool,
pub exit_status: Option<i32>,
pub is_held: bool,
pub pane_x: usize,
pub pane_content_x: usize,
pub pane_y: usize,
pub pane_content_y: usize,
pub pane_rows: usize,
pub pane_content_rows: usize,
pub pane_columns: usize,
pub pane_content_columns: usize,
pub cursor_coordinates_in_pane: Option<(usize, usize)>, pub terminal_command: Option<String>,
pub plugin_url: Option<String>,
pub is_selectable: bool,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct PluginIds {
pub plugin_id: u32,
pub zellij_pid: u32,
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct PluginTag(String);
impl PluginTag {
pub fn new(url: impl Into<String>) -> Self {
PluginTag(url.into())
}
}
impl From<PluginTag> for String {
fn from(tag: PluginTag) -> Self {
tag.0
}
}
impl fmt::Display for PluginTag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct PluginCapabilities {
pub arrow_fonts: bool,
}
impl Default for PluginCapabilities {
fn default() -> PluginCapabilities {
PluginCapabilities { arrow_fonts: true }
}
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub enum CopyDestination {
Command,
Primary,
System,
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub enum PermissionStatus {
Granted,
Denied,
}
#[derive(Debug, Default, Clone)]
pub struct FileToOpen {
pub path: PathBuf,
pub line_number: Option<usize>,
pub cwd: Option<PathBuf>,
}
impl FileToOpen {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
FileToOpen {
path: path.as_ref().to_path_buf(),
..Default::default()
}
}
pub fn with_line_number(mut self, line_number: usize) -> Self {
self.line_number = Some(line_number);
self
}
pub fn with_cwd(mut self, cwd: PathBuf) -> Self {
self.cwd = Some(cwd);
self
}
}
#[derive(Debug, Default, Clone)]
pub struct CommandToRun {
pub path: PathBuf,
pub args: Vec<String>,
pub cwd: Option<PathBuf>,
}
impl CommandToRun {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
CommandToRun {
path: path.as_ref().to_path_buf(),
..Default::default()
}
}
pub fn new_with_args<P: AsRef<Path>, A: AsRef<str>>(path: P, args: Vec<A>) -> Self {
CommandToRun {
path: path.as_ref().to_path_buf(),
args: args.into_iter().map(|a| a.as_ref().to_owned()).collect(),
..Default::default()
}
}
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct ConnectToSession {
pub name: Option<String>,
pub tab_position: Option<usize>,
pub pane_id: Option<(u32, bool)>, }
#[derive(Debug, Default, Clone)]
pub struct PluginMessage {
pub name: String,
pub payload: String,
pub worker_name: Option<String>,
}
impl PluginMessage {
pub fn new_to_worker(worker_name: &str, message: &str, payload: &str) -> Self {
PluginMessage {
name: message.to_owned(),
payload: payload.to_owned(),
worker_name: Some(worker_name.to_owned()),
}
}
pub fn new_to_plugin(message: &str, payload: &str) -> Self {
PluginMessage {
name: message.to_owned(),
payload: payload.to_owned(),
worker_name: None,
}
}
}
#[derive(Debug, Clone, EnumDiscriminants, ToString)]
#[strum_discriminants(derive(EnumString, Hash, Serialize, Deserialize))]
#[strum_discriminants(name(CommandType))]
pub enum PluginCommand {
Subscribe(HashSet<EventType>),
Unsubscribe(HashSet<EventType>),
SetSelectable(bool),
GetPluginIds,
GetZellijVersion,
OpenFile(FileToOpen),
OpenFileFloating(FileToOpen),
OpenTerminal(FileToOpen), OpenTerminalFloating(FileToOpen), OpenCommandPane(CommandToRun),
OpenCommandPaneFloating(CommandToRun),
SwitchTabTo(u32), SetTimeout(f64), ExecCmd(Vec<String>),
PostMessageTo(PluginMessage),
PostMessageToPlugin(PluginMessage),
HideSelf,
ShowSelf(bool), SwitchToMode(InputMode),
NewTabsWithLayout(String), NewTab,
GoToNextTab,
GoToPreviousTab,
Resize(Resize),
ResizeWithDirection(ResizeStrategy),
FocusNextPane,
FocusPreviousPane,
MoveFocus(Direction),
MoveFocusOrTab(Direction),
Detach,
EditScrollback,
Write(Vec<u8>), WriteChars(String),
ToggleTab,
MovePane,
MovePaneWithDirection(Direction),
ClearScreen,
ScrollUp,
ScrollDown,
ScrollToTop,
ScrollToBottom,
PageScrollUp,
PageScrollDown,
ToggleFocusFullscreen,
TogglePaneFrames,
TogglePaneEmbedOrEject,
UndoRenamePane,
CloseFocus,
ToggleActiveTabSync,
CloseFocusedTab,
UndoRenameTab,
QuitZellij,
PreviousSwapLayout,
NextSwapLayout,
GoToTabName(String),
FocusOrCreateTab(String),
GoToTab(u32), StartOrReloadPlugin(String), CloseTerminalPane(u32), ClosePluginPane(u32), FocusTerminalPane(u32, bool), FocusPluginPane(u32, bool), RenameTerminalPane(u32, String), RenamePluginPane(u32, String), RenameTab(u32, String), ReportPanic(String), RequestPluginPermissions(Vec<PermissionType>),
SwitchSession(ConnectToSession),
}