aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-tile
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2025-10-09 11:29:55 +0200
committerGitHub <noreply@github.com>2025-10-09 11:29:55 +0200
commit7e66ae3125bf5031b6c013dee8038c838b42bbc5 (patch)
tree061c2311461cbe52b40b8ad433023085cfae67bf /zellij-tile
parentbuild(cargo): Update Rust toolchain to 1.90.0 (#4457) (diff)
downloadsl0ppij-7e66ae3125bf5031b6c013dee8038c838b42bbc5.tar.gz
sl0ppij-7e66ae3125bf5031b6c013dee8038c838b42bbc5.tar.xz
sl0ppij-7e66ae3125bf5031b6c013dee8038c838b42bbc5.zip
Give plugins the ability to read pane contents (#4465)
* initial implementation * add Selection and better types * event to plugins * only send viewport diff * simplify data structure sent over the wire * cleanups * rustfmt * remove dead code and fix tests * commit tests * get pane scrollback plugin command without implementation * add lines above and lines below to pane contents * implement get scrollback plugin command * selection => selected_text * add convenience method to get the selected text * move Selection back to zellij-server * rustfmt * bring back client id to get contents command * rustfmt * add pr
Diffstat (limited to 'zellij-tile')
-rw-r--r--zellij-tile/src/shim.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs
index 7afe0186..6030dcc7 100644
--- a/zellij-tile/src/shim.rs
+++ b/zellij-tile/src/shim.rs
@@ -8,6 +8,7 @@ use zellij_utils::data::*;
use zellij_utils::errors::prelude::*;
use zellij_utils::input::actions::Action;
pub use zellij_utils::plugin_api;
+use zellij_utils::plugin_api::event::ProtobufPaneScrollbackResponse;
use zellij_utils::plugin_api::plugin_command::{
CreateTokenResponse, ListTokensResponse, ProtobufPluginCommand, RenameWebTokenResponse,
RevokeAllWebTokensResponse, RevokeTokenResponse,
@@ -1045,6 +1046,46 @@ pub fn edit_scrollback_for_pane_with_id(pane_id: PaneId) {
unsafe { host_run_plugin_command() };
}
+/// Retrieves the scrollback contents from the specified pane
+///
+/// # Arguments
+/// * `pane_id` - The ID of the pane to get scrollback from
+/// * `get_full_scrollback` - Whether to retrieve the full scrollback buffer (including lines above and below viewport)
+///
+/// # Returns
+/// * `Ok(PaneContents)` - The pane contents if successful
+/// * `Err(String)` - An error message if the pane was not found, timed out, or another error occurred
+pub fn get_pane_scrollback(
+ pane_id: PaneId,
+ get_full_scrollback: bool,
+) -> Result<PaneContents, String> {
+ let plugin_command = PluginCommand::GetPaneScrollback {
+ pane_id,
+ get_full_scrollback,
+ };
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
+
+ // Read response from stdin
+ let response_bytes =
+ bytes_from_stdin().map_err(|e| format!("Failed to read response from stdin: {:?}", e))?;
+
+ // Decode protobuf response
+ let protobuf_response = ProtobufPaneScrollbackResponse::decode(response_bytes.as_slice())
+ .map_err(|e| format!("Failed to decode protobuf response: {}", e))?;
+
+ // Convert to Rust type
+ let response = PaneScrollbackResponse::try_from(protobuf_response)
+ .map_err(|e| format!("Failed to convert protobuf response: {}", e))?;
+
+ // Convert Result enum to actual Result type
+ match response {
+ PaneScrollbackResponse::Ok(contents) => Ok(contents),
+ PaneScrollbackResponse::Err(error_msg) => Err(error_msg),
+ }
+}
+
/// Write bytes to the `STDIN` of the specified pane
pub fn write_to_pane_id(bytes: Vec<u8>, pane_id: PaneId) {
let plugin_command = PluginCommand::WriteToPaneId(bytes, pane_id);