aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/plugin_command.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-02-08 17:35:55 +0100
committerGitHub <noreply@github.com>2024-02-08 17:35:55 +0100
commit326c8cd3c6566e8fa4acd3a9369c718ce96f6625 (patch)
tree805ded9e78a35e9cd1ae91594358c8888a53abe2 /zellij-utils/src/plugin_api/plugin_command.rs
parentdocs(changelog): cwd fixes (diff)
downloadsl0ppij-326c8cd3c6566e8fa4acd3a9369c718ce96f6625.tar.gz
sl0ppij-326c8cd3c6566e8fa4acd3a9369c718ce96f6625.tar.xz
sl0ppij-326c8cd3c6566e8fa4acd3a9369c718ce96f6625.zip
feat(panes): allow specifying coordinates for a new floating pane through the CLI or plugins (#3122)
* working * add tests * add coordinates to all the places * refactor: move things around: * style(fmt): rustfmt * style(code): cleanups
Diffstat (limited to 'zellij-utils/src/plugin_api/plugin_command.rs')
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs187
1 files changed, 158 insertions, 29 deletions
diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs
index a5272d42..e2fce1d0 100644
--- a/zellij-utils/src/plugin_api/plugin_command.rs
+++ b/zellij-utils/src/plugin_api/plugin_command.rs
@@ -4,10 +4,13 @@ pub use super::generated_api::api::{
input_mode::InputMode as ProtobufInputMode,
plugin_command::{
plugin_command::Payload, CliPipeOutputPayload, CommandName, ContextItem, EnvVariable,
- ExecCmdPayload, HttpVerb as ProtobufHttpVerb, IdAndNewName, KillSessionsPayload,
- MessageToPluginPayload, MovePayload, NewPluginArgs as ProtobufNewPluginArgs,
- OpenCommandPanePayload, OpenFilePayload, PaneId as ProtobufPaneId,
- PaneType as ProtobufPaneType, PluginCommand as ProtobufPluginCommand, PluginMessagePayload,
+ ExecCmdPayload, FixedOrPercent as ProtobufFixedOrPercent,
+ FixedOrPercentValue as ProtobufFixedOrPercentValue,
+ FloatingPaneCoordinates as ProtobufFloatingPaneCoordinates, HttpVerb as ProtobufHttpVerb,
+ IdAndNewName, KillSessionsPayload, MessageToPluginPayload, MovePayload,
+ NewPluginArgs as ProtobufNewPluginArgs, OpenCommandPanePayload, OpenFilePayload,
+ PaneId as ProtobufPaneId, PaneType as ProtobufPaneType,
+ PluginCommand as ProtobufPluginCommand, PluginMessagePayload,
RequestPluginPermissionPayload, ResizePayload, RunCommandPayload, SetTimeoutPayload,
SubscribePayload, SwitchSessionPayload, SwitchTabToPayload, UnsubscribePayload,
WebRequestPayload,
@@ -17,14 +20,113 @@ pub use super::generated_api::api::{
};
use crate::data::{
- ConnectToSession, HttpVerb, MessageToPlugin, NewPluginArgs, PaneId, PermissionType,
- PluginCommand,
+ ConnectToSession, FloatingPaneCoordinates, HttpVerb, MessageToPlugin, NewPluginArgs, PaneId,
+ PermissionType, PluginCommand,
};
+use crate::input::layout::SplitSize;
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::path::PathBuf;
+impl Into<FloatingPaneCoordinates> for ProtobufFloatingPaneCoordinates {
+ fn into(self) -> FloatingPaneCoordinates {
+ FloatingPaneCoordinates {
+ x: self
+ .x
+ .and_then(|x| match ProtobufFixedOrPercent::from_i32(x.r#type) {
+ Some(ProtobufFixedOrPercent::Percent) => {
+ Some(SplitSize::Percent(x.value as usize))
+ },
+ Some(ProtobufFixedOrPercent::Fixed) => Some(SplitSize::Fixed(x.value as usize)),
+ None => None,
+ }),
+ y: self
+ .y
+ .and_then(|y| match ProtobufFixedOrPercent::from_i32(y.r#type) {
+ Some(ProtobufFixedOrPercent::Percent) => {
+ Some(SplitSize::Percent(y.value as usize))
+ },
+ Some(ProtobufFixedOrPercent::Fixed) => Some(SplitSize::Fixed(y.value as usize)),
+ None => None,
+ }),
+ width: self.width.and_then(|width| {
+ match ProtobufFixedOrPercent::from_i32(width.r#type) {
+ Some(ProtobufFixedOrPercent::Percent) => {
+ Some(SplitSize::Percent(width.value as usize))
+ },
+ Some(ProtobufFixedOrPercent::Fixed) => {
+ Some(SplitSize::Fixed(width.value as usize))
+ },
+ None => None,
+ }
+ }),
+ height: self.height.and_then(|height| {
+ match ProtobufFixedOrPercent::from_i32(height.r#type) {
+ Some(ProtobufFixedOrPercent::Percent) => {
+ Some(SplitSize::Percent(height.value as usize))
+ },
+ Some(ProtobufFixedOrPercent::Fixed) => {
+ Some(SplitSize::Fixed(height.value as usize))
+ },
+ None => None,
+ }
+ }),
+ }
+ }
+}
+
+impl Into<ProtobufFloatingPaneCoordinates> for FloatingPaneCoordinates {
+ fn into(self) -> ProtobufFloatingPaneCoordinates {
+ ProtobufFloatingPaneCoordinates {
+ x: match self.x {
+ Some(SplitSize::Percent(percent)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Percent as i32,
+ value: percent as u32,
+ }),
+ Some(SplitSize::Fixed(fixed)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Fixed as i32,
+ value: fixed as u32,
+ }),
+ None => None,
+ },
+ y: match self.y {
+ Some(SplitSize::Percent(percent)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Percent as i32,
+ value: percent as u32,
+ }),
+ Some(SplitSize::Fixed(fixed)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Fixed as i32,
+ value: fixed as u32,
+ }),
+ None => None,
+ },
+ width: match self.width {
+ Some(SplitSize::Percent(percent)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Percent as i32,
+ value: percent as u32,
+ }),
+ Some(SplitSize::Fixed(fixed)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Fixed as i32,
+ value: fixed as u32,
+ }),
+ None => None,
+ },
+ height: match self.height {
+ Some(SplitSize::Percent(percent)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Percent as i32,
+ value: percent as u32,
+ }),
+ Some(SplitSize::Fixed(fixed)) => Some(ProtobufFixedOrPercentValue {
+ r#type: ProtobufFixedOrPercent::Fixed as i32,
+ value: fixed as u32,
+ }),
+ None => None,
+ },
+ }
+ }
+}
+
impl Into<HttpVerb> for ProtobufHttpVerb {
fn into(self) -> HttpVerb {
match self {
@@ -133,10 +235,14 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
},
Some(CommandName::OpenFileFloating) => match protobuf_plugin_command.payload {
Some(Payload::OpenFileFloatingPayload(file_to_open_payload)) => {
+ let floating_pane_coordinates = file_to_open_payload
+ .floating_pane_coordinates
+ .map(|f| f.into());
match file_to_open_payload.file_to_open {
- Some(file_to_open) => {
- Ok(PluginCommand::OpenFileFloating(file_to_open.try_into()?))
- },
+ Some(file_to_open) => Ok(PluginCommand::OpenFileFloating(
+ file_to_open.try_into()?,
+ floating_pane_coordinates,
+ )),
None => Err("Malformed open file payload"),
}
},
@@ -155,9 +261,13 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
},
Some(CommandName::OpenTerminalFloating) => match protobuf_plugin_command.payload {
Some(Payload::OpenTerminalFloatingPayload(file_to_open_payload)) => {
+ let floating_pane_coordinates = file_to_open_payload
+ .floating_pane_coordinates
+ .map(|f| f.into());
match file_to_open_payload.file_to_open {
Some(file_to_open) => Ok(PluginCommand::OpenTerminalFloating(
file_to_open.try_into()?,
+ floating_pane_coordinates,
)),
None => Err("Malformed open terminal floating payload"),
}
@@ -177,9 +287,13 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
},
Some(CommandName::OpenCommandPaneFloating) => match protobuf_plugin_command.payload {
Some(Payload::OpenCommandPaneFloatingPayload(command_to_run_payload)) => {
+ let floating_pane_coordinates = command_to_run_payload
+ .floating_pane_coordinates
+ .map(|f| f.into());
match command_to_run_payload.command_to_run {
Some(command_to_run) => Ok(PluginCommand::OpenCommandPaneFloating(
command_to_run.try_into()?,
+ floating_pane_coordinates,
)),
None => Err("Malformed open command pane floating payload"),
}
@@ -783,40 +897,52 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
name: CommandName::OpenFile as i32,
payload: Some(Payload::OpenFilePayload(OpenFilePayload {
file_to_open: Some(file_to_open.try_into()?),
+ floating_pane_coordinates: None,
})),
}),
- PluginCommand::OpenFileFloating(file_to_open) => Ok(ProtobufPluginCommand {
- name: CommandName::OpenFileFloating as i32,
- payload: Some(Payload::OpenFileFloatingPayload(OpenFilePayload {
- file_to_open: Some(file_to_open.try_into()?),
- })),
- }),
+ PluginCommand::OpenFileFloating(file_to_open, floating_pane_coordinates) => {
+ Ok(ProtobufPluginCommand {
+ name: CommandName::OpenFileFloating as i32,
+ payload: Some(Payload::OpenFileFloatingPayload(OpenFilePayload {
+ file_to_open: Some(file_to_open.try_into()?),
+ floating_pane_coordinates: floating_pane_coordinates.map(|f| f.into()),
+ })),
+ })
+ },
PluginCommand::OpenTerminal(cwd) => Ok(ProtobufPluginCommand {
name: CommandName::OpenTerminal as i32,
payload: Some(Payload::OpenTerminalPayload(OpenFilePayload {
file_to_open: Some(cwd.try_into()?),
+ floating_pane_coordinates: None,
})),
}),
- PluginCommand::OpenTerminalFloating(cwd) => Ok(ProtobufPluginCommand {
- name: CommandName::OpenTerminalFloating as i32,
- payload: Some(Payload::OpenTerminalFloatingPayload(OpenFilePayload {
- file_to_open: Some(cwd.try_into()?),
- })),
- }),
+ PluginCommand::OpenTerminalFloating(cwd, floating_pane_coordinates) => {
+ Ok(ProtobufPluginCommand {
+ name: CommandName::OpenTerminalFloating as i32,
+ payload: Some(Payload::OpenTerminalFloatingPayload(OpenFilePayload {
+ file_to_open: Some(cwd.try_into()?),
+ floating_pane_coordinates: floating_pane_coordinates.map(|f| f.into()),
+ })),
+ })
+ },
PluginCommand::OpenCommandPane(command_to_run) => Ok(ProtobufPluginCommand {
name: CommandName::OpenCommandPane as i32,
payload: Some(Payload::OpenCommandPanePayload(OpenCommandPanePayload {
command_to_run: Some(command_to_run.try_into()?),
+ floating_pane_coordinates: None,
})),
}),
- PluginCommand::OpenCommandPaneFloating(command_to_run) => Ok(ProtobufPluginCommand {
- name: CommandName::OpenCommandPaneFloating as i32,
- payload: Some(Payload::OpenCommandPaneFloatingPayload(
- OpenCommandPanePayload {
- command_to_run: Some(command_to_run.try_into()?),
- },
- )),
- }),
+ PluginCommand::OpenCommandPaneFloating(command_to_run, floating_pane_coordinates) => {
+ Ok(ProtobufPluginCommand {
+ name: CommandName::OpenCommandPaneFloating as i32,
+ payload: Some(Payload::OpenCommandPaneFloatingPayload(
+ OpenCommandPanePayload {
+ command_to_run: Some(command_to_run.try_into()?),
+ floating_pane_coordinates: floating_pane_coordinates.map(|f| f.into()),
+ },
+ )),
+ })
+ },
PluginCommand::SwitchTabTo(tab_index) => Ok(ProtobufPluginCommand {
name: CommandName::SwitchTabTo as i32,
payload: Some(Payload::SwitchTabToPayload(SwitchTabToPayload {
@@ -1100,12 +1226,14 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
name: CommandName::OpenTerminalInPlace as i32,
payload: Some(Payload::OpenTerminalInPlacePayload(OpenFilePayload {
file_to_open: Some(cwd.try_into()?),
+ floating_pane_coordinates: None,
})),
}),
PluginCommand::OpenFileInPlace(file_to_open) => Ok(ProtobufPluginCommand {
name: CommandName::OpenFileInPlace as i32,
payload: Some(Payload::OpenFileInPlacePayload(OpenFilePayload {
file_to_open: Some(file_to_open.try_into()?),
+ floating_pane_coordinates: None,
})),
}),
PluginCommand::OpenCommandPaneInPlace(command_to_run) => Ok(ProtobufPluginCommand {
@@ -1113,6 +1241,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
payload: Some(Payload::OpenCommandPaneInPlacePayload(
OpenCommandPanePayload {
command_to_run: Some(command_to_run.try_into()?),
+ floating_pane_coordinates: None,
},
)),
}),