Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add The cwd and Process ID to PaneInfo for use by Plugins #3765

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions zellij-utils/assets/prost/api.event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ pub struct PaneInfo {
pub plugin_url: ::core::option::Option<::prost::alloc::string::String>,
#[prost(bool, tag = "22")]
pub is_selectable: bool,
#[prost(string, optional, tag = "23")]
pub cwd: ::core::option::Option<::prost::alloc::string::String>,
#[prost(uint32, optional, tag = "24")]
pub pid: ::core::option::Option<u32>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
44 changes: 22 additions & 22 deletions zellij-utils/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
//
// [1]: https://github.com/zellij-org/zellij/pull/2711#issuecomment-1695015818

//use prost_build;
//use std::fs;
use prost_build;
use std::fs;

fn main() {
//let mut prost_build = prost_build::Config::new();
//let out_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/prost");
//let out_dir = std::path::Path::new(out_dir);
let mut prost_build = prost_build::Config::new();
let out_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/prost");
let out_dir = std::path::Path::new(out_dir);

//std::fs::create_dir_all(out_dir).unwrap();
//prost_build.out_dir(out_dir);
//prost_build.include_file("generated_plugin_api.rs");
//let mut proto_files = vec![];
//for entry in fs::read_dir("src/plugin_api").unwrap() {
// let entry_path = entry.unwrap().path();
// if entry_path.is_file() {
// if let Some(extension) = entry_path.extension() {
// if extension == "proto" {
// proto_files.push(entry_path.display().to_string())
// }
// }
// }
//}
//prost_build
// .compile_protos(&proto_files, &["src/plugin_api"])
// .unwrap();
std::fs::create_dir_all(out_dir).unwrap();
prost_build.out_dir(out_dir);
prost_build.include_file("generated_plugin_api.rs");
let mut proto_files = vec![];
for entry in fs::read_dir("src/plugin_api").unwrap() {
let entry_path = entry.unwrap().path();
if entry_path.is_file() {
if let Some(extension) = entry_path.extension() {
if extension == "proto" {
proto_files.push(entry_path.display().to_string())
}
}
}
}
prost_build
.compile_protos(&proto_files, &["src/plugin_api"])
.unwrap();
}
2 changes: 2 additions & 0 deletions zellij-utils/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,8 @@ pub struct PaneInfo {
/// Unselectable panes are often used for UI elements that do not have direct user interaction
/// (eg. the default `status-bar` or `tab-bar`).
pub is_selectable: bool,
pub cwd: Option<PathBuf>,
pub pid: Option<usize>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ClientInfo {
Expand Down
3 changes: 3 additions & 0 deletions zellij-utils/src/input/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// place.
// If plugins should be able to depend on the layout system
// then [`zellij-utils`] could be a proper place.

#![allow(clippy::derived_hash_with_manual_eq)]

#[cfg(not(target_family = "wasm"))]
use crate::downloader::Downloader;
use crate::{
Expand Down
14 changes: 14 additions & 0 deletions zellij-utils/src/kdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4440,6 +4440,8 @@ impl PaneInfo {
let terminal_command = optional_string_node!("terminal_command");
let plugin_url = optional_string_node!("plugin_url");
let is_selectable = bool_node!("is_selectable");
let cwd = optional_string_node!("cwd").map(PathBuf::from);
let pid = optional_int_node!("pid", usize);

let pane_info = PaneInfo {
id,
Expand All @@ -4464,6 +4466,8 @@ impl PaneInfo {
terminal_command,
plugin_url,
is_selectable,
cwd,
pid,
};
Ok((tab_position, pane_info))
}
Expand Down Expand Up @@ -4524,6 +4528,12 @@ impl PaneInfo {
string_node!("plugin_url", plugin_url.to_string());
}
bool_node!("is_selectable", self.is_selectable);
if let Some(cwd) = &self.cwd {
string_node!("cwd", cwd.display().to_string())
}
if let Some(pid) = self.pid {
int_node!("pid", pid)
}
kdl_doucment
}
}
Expand Down Expand Up @@ -4611,6 +4621,8 @@ fn serialize_and_deserialize_session_info_with_data() {
terminal_command: Some("foo".to_owned()),
plugin_url: None,
is_selectable: true,
cwd: Some("/some/directory/".into()),
pid: Some(69),
},
PaneInfo {
id: 1,
Expand All @@ -4635,6 +4647,8 @@ fn serialize_and_deserialize_session_info_with_data() {
terminal_command: None,
plugin_url: Some("i_am_a_fake_plugin".to_owned()),
is_selectable: true,
cwd: None,
pid: None,
},
];
let mut panes = HashMap::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: zellij-utils/src/kdl/mod.rs
assertion_line: 2552
assertion_line: 4697
expression: serialized
---
name "my session name"
Expand Down Expand Up @@ -51,6 +51,8 @@ panes {
cursor_coordinates_in_pane 0 0
terminal_command "foo"
is_selectable true
cwd "/some/directory/"
pid 69
tab_position 0
}
pane {
Expand Down
2 changes: 2 additions & 0 deletions zellij-utils/src/plugin_api/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ message PaneInfo {
optional string terminal_command = 20;
optional string plugin_url = 21;
bool is_selectable = 22;
optional string cwd = 23;
optional uint32 pid = 24;
}

message TabInfo {
Expand Down
8 changes: 8 additions & 0 deletions zellij-utils/src/plugin_api/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,8 @@ impl TryFrom<ProtobufPaneInfo> for PaneInfo {
terminal_command: protobuf_pane_info.terminal_command,
plugin_url: protobuf_pane_info.plugin_url,
is_selectable: protobuf_pane_info.is_selectable,
cwd: protobuf_pane_info.cwd.map(|cwd| cwd.into()),
pid: protobuf_pane_info.pid.map(|pid| pid as usize),
})
}
}
Expand Down Expand Up @@ -1018,6 +1020,8 @@ impl TryFrom<PaneInfo> for ProtobufPaneInfo {
terminal_command: pane_info.terminal_command,
plugin_url: pane_info.plugin_url,
is_selectable: pane_info.is_selectable,
cwd: pane_info.cwd.map(|cwd| cwd.display().to_string()),
pid: pane_info.pid.map(|pid| pid as u32),
})
}
}
Expand Down Expand Up @@ -1760,6 +1764,8 @@ fn serialize_session_update_event_with_non_default_values() {
terminal_command: Some("foo".to_owned()),
plugin_url: None,
is_selectable: true,
cwd: Some("/some/path".into()),
pid: Some(69),
},
PaneInfo {
id: 1,
Expand All @@ -1784,6 +1790,8 @@ fn serialize_session_update_event_with_non_default_values() {
terminal_command: None,
plugin_url: Some("i_am_a_fake_plugin".to_owned()),
is_selectable: true,
cwd: None,
pid: None,
},
];
panes.insert(0, panes_list);
Expand Down