aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/plugins
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2026-03-05 21:13:02 +0100
committerGitHub <noreply@github.com>2026-03-05 21:13:02 +0100
commit903cdf5d32476a8d6cc208d2c418a1f2c67e5a53 (patch)
tree9a4647d9dc3efcdea8149fd78fdfa956b3c8d8cb /zellij-server/src/plugins
parentbuild: make test mirror build command for plugins (#4801) (diff)
downloadsl0ppij-903cdf5d32476a8d6cc208d2c418a1f2c67e5a53.tar.gz
sl0ppij-903cdf5d32476a8d6cc208d2c418a1f2c67e5a53.tar.xz
sl0ppij-903cdf5d32476a8d6cc208d2c418a1f2c67e5a53.zip
Click file paths to open in editor, allow plugins to change styles and hover of viewport (#4802)
* initial implementation * implement hover * add styles and foreground/background emphases, fix upsert hover collisions * initial implementation of link plugin * suppress highlighting + clicks on unfocused and mouse mode panes * also make italic * fix env var and ~ expansions * fix regex issues and add defensive validations * fix tests and add plugin assets * add tests * refactor all the things * add pr
Diffstat (limited to 'zellij-server/src/plugins')
-rw-r--r--zellij-server/src/plugins/mod.rs26
-rw-r--r--zellij-server/src/plugins/unit/plugin_tests.rs271
-rw-r--r--zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__highlight_clicked_event_delivered_to_plugin.snap7
-rw-r--r--zellij-server/src/plugins/wasm_bridge.rs5
-rw-r--r--zellij-server/src/plugins/zellij_exports.rs41
5 files changed, 348 insertions, 2 deletions
diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs
index d26fb7d2..4bd4a82e 100644
--- a/zellij-server/src/plugins/mod.rs
+++ b/zellij-server/src/plugins/mod.rs
@@ -212,6 +212,14 @@ pub enum PluginInstruction {
response_channel: crossbeam::channel::Sender<Option<u64>>,
},
DetectPluginConfigChanges(PluginAliases),
+ HighlightClicked {
+ plugin_id: u32,
+ client_id: ClientId,
+ pane_id: PaneId,
+ pattern: String,
+ matched_string: String,
+ context: BTreeMap<String, String>,
+ },
Exit,
}
@@ -275,6 +283,7 @@ impl From<&PluginInstruction> for PluginContext {
PluginInstruction::DetectPluginConfigChanges(..) => {
PluginContext::DetectPluginConfigChanges
},
+ PluginInstruction::HighlightClicked { .. } => PluginContext::HighlightClicked,
}
}
}
@@ -1232,6 +1241,23 @@ pub(crate) fn plugin_thread_main(
wasm_bridge
.detect_and_notify_plugin_config_changes(&new_plugins, shutdown_send.clone())?;
},
+ PluginInstruction::HighlightClicked {
+ plugin_id,
+ client_id,
+ pane_id,
+ pattern,
+ matched_string,
+ context,
+ } => {
+ let event = Event::HighlightClicked {
+ pane_id: pane_id.into(),
+ pattern,
+ matched_string,
+ context,
+ };
+ let updates = vec![(Some(plugin_id), Some(client_id), event)];
+ wasm_bridge.update_plugins(updates, shutdown_send.clone())?;
+ },
PluginInstruction::Exit => {
break;
},
diff --git a/zellij-server/src/plugins/unit/plugin_tests.rs b/zellij-server/src/plugins/unit/plugin_tests.rs
index a5f2e420..4e2ad047 100644
--- a/zellij-server/src/plugins/unit/plugin_tests.rs
+++ b/zellij-server/src/plugins/unit/plugin_tests.rs
@@ -12323,3 +12323,274 @@ pub fn get_session_environment_variables_plugin_command() {
});
assert_snapshot!(format!("{:#?}", plugin_bytes_event));
}
+
+// =====================================================================
+// Plugin Highlight API Integration Tests
+// =====================================================================
+
+use crate::panes::PaneId;
+use zellij_utils::data::{HighlightStyle, RegexHighlight};
+
+#[test]
+#[ignore]
+pub fn set_pane_regex_highlights_via_plugin() {
+ let temp_folder = tempdir().unwrap();
+ let plugin_host_folder = PathBuf::from(temp_folder.path());
+ let cache_path = plugin_host_folder.join("permissions_test.kdl");
+ let (plugin_thread_sender, screen_receiver, teardown) = create_plugin_thread(None, None);
+ let plugin_should_float = Some(false);
+ let plugin_title = Some("test_plugin".to_owned());
+ let run_plugin = RunPluginOrAlias::RunPlugin(RunPlugin {
+ _allow_exec_host_cmd: false,
+ location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)),
+ configuration: Default::default(),
+ ..Default::default()
+ });
+ let tab_index = 1;
+ let client_id = 1;
+ let size = Size {
+ cols: 121,
+ rows: 20,
+ };
+ let received_screen_instructions = Arc::new(Mutex::new(vec![]));
+ let screen_thread = grant_permissions_and_log_actions_in_thread_struct_variant!(
+ received_screen_instructions,
+ ScreenInstruction::SetPluginRegexHighlights,
+ screen_receiver,
+ 1,
+ &PermissionType::ChangeApplicationState,
+ cache_path,
+ plugin_thread_sender,
+ client_id
+ );
+
+ let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id));
+ let _ = plugin_thread_sender.send(PluginInstruction::Load(
+ plugin_should_float,
+ false,
+ false, // close_replaced_pane
+ plugin_title,
+ run_plugin,
+ Some(tab_index),
+ None,
+ client_id,
+ size,
+ None,
+ None,
+ false,
+ None,
+ None,
+ None,
+ ));
+ std::thread::sleep(std::time::Duration::from_millis(500));
+
+ // Send Super+g key event to trigger set_pane_regex_highlights in the fixture plugin
+ let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
+ None,
+ Some(client_id),
+ Event::Key(KeyWithModifier::new(BareKey::Char('g')).with_super_modifier()),
+ )]));
+
+ screen_thread.join().unwrap();
+ teardown();
+
+ let highlight_instruction = received_screen_instructions
+ .lock()
+ .unwrap()
+ .iter()
+ .find_map(|i| {
+ if let ScreenInstruction::SetPluginRegexHighlights {
+ pane_id,
+ plugin_id,
+ highlights,
+ } = i
+ {
+ Some((*pane_id, *plugin_id, highlights.clone()))
+ } else {
+ None
+ }
+ });
+
+ assert!(
+ highlight_instruction.is_some(),
+ "Expected SetPluginRegexHighlights instruction"
+ );
+ let (pane_id, _plugin_id, highlights) = highlight_instruction.unwrap();
+ assert_eq!(pane_id, PaneId::Terminal(1));
+ assert_eq!(highlights.len(), 1);
+ assert_eq!(highlights[0].pattern, "test_pattern");
+ assert!(highlights[0].italic);
+ assert!(highlights[0].underline);
+}
+
+#[test]
+#[ignore]
+pub fn clear_pane_highlights_via_plugin() {
+ let temp_folder = tempdir().unwrap();
+ let plugin_host_folder = PathBuf::from(temp_folder.path());
+ let cache_path = plugin_host_folder.join("permissions_test.kdl");
+ let (plugin_thread_sender, screen_receiver, teardown) = create_plugin_thread(None, None);
+ let plugin_should_float = Some(false);
+ let plugin_title = Some("test_plugin".to_owned());
+ let run_plugin = RunPluginOrAlias::RunPlugin(RunPlugin {
+ _allow_exec_host_cmd: false,
+ location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)),
+ configuration: Default::default(),
+ ..Default::default()
+ });
+ let tab_index = 1;
+ let client_id = 1;
+ let size = Size {
+ cols: 121,
+ rows: 20,
+ };
+ let received_screen_instructions = Arc::new(Mutex::new(vec![]));
+ let screen_thread = grant_permissions_and_log_actions_in_thread_struct_variant!(
+ received_screen_instructions,
+ ScreenInstruction::ClearPluginHighlights,
+ screen_receiver,
+ 1,
+ &PermissionType::ChangeApplicationState,
+ cache_path,
+ plugin_thread_sender,
+ client_id
+ );
+
+ let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id));
+ let _ = plugin_thread_sender.send(PluginInstruction::Load(
+ plugin_should_float,
+ false,
+ false, // close_replaced_pane
+ plugin_title,
+ run_plugin,
+ Some(tab_index),
+ None,
+ client_id,
+ size,
+ None,
+ None,
+ false,
+ None,
+ None,
+ None,
+ ));
+ std::thread::sleep(std::time::Duration::from_millis(500));
+
+ // Send Super+h key event to trigger clear_pane_highlights in the fixture plugin
+ let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
+ None,
+ Some(client_id),
+ Event::Key(KeyWithModifier::new(BareKey::Char('h')).with_super_modifier()),
+ )]));
+
+ screen_thread.join().unwrap();
+ teardown();
+
+ let clear_instruction = received_screen_instructions
+ .lock()
+ .unwrap()
+ .iter()
+ .find_map(|i| {
+ if let ScreenInstruction::ClearPluginHighlights { pane_id, plugin_id } = i {
+ Some((*pane_id, *plugin_id))
+ } else {
+ None
+ }
+ });
+
+ assert!(
+ clear_instruction.is_some(),
+ "Expected ClearPluginHighlights instruction"
+ );
+ let (pane_id, _plugin_id) = clear_instruction.unwrap();
+ assert_eq!(pane_id, PaneId::Terminal(1));
+}
+
+#[test]
+#[ignore]
+pub fn highlight_clicked_event_delivered_to_plugin() {
+ let temp_folder = tempdir().unwrap();
+ let plugin_host_folder = PathBuf::from(temp_folder.path());
+ let cache_path = plugin_host_folder.join("permissions_test.kdl");
+ let (plugin_thread_sender, screen_receiver, teardown) = create_plugin_thread(None, None);
+ let plugin_should_float = Some(false);
+ let plugin_title = Some("test_plugin".to_owned());
+ let run_plugin = RunPluginOrAlias::RunPlugin(RunPlugin {
+ _allow_exec_host_cmd: false,
+ location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)),
+ configuration: Default::default(),
+ ..Default::default()
+ });
+ let tab_index = 1;
+ let client_id = 1;
+ let size = Size {
+ cols: 121,
+ rows: 20,
+ };
+ let received_screen_instructions = Arc::new(Mutex::new(vec![]));
+ let screen_thread = grant_permissions_and_log_actions_in_thread!(
+ received_screen_instructions,
+ ScreenInstruction::PluginBytes,
+ screen_receiver,
+ 2,
+ &PermissionType::ChangeApplicationState,
+ cache_path,
+ plugin_thread_sender,
+ client_id
+ );
+
+ let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id));
+ let _ = plugin_thread_sender.send(PluginInstruction::Load(
+ plugin_should_float,
+ false,
+ false, // close_replaced_pane
+ plugin_title,
+ run_plugin,
+ Some(tab_index),
+ None,
+ client_id,
+ size,
+ None,
+ None,
+ false,
+ None,
+ None,
+ None,
+ ));
+ std::thread::sleep(std::time::Duration::from_millis(500));
+
+ // Send a HighlightClicked event directly to the plugin
+ let _ = plugin_thread_sender.send(PluginInstruction::HighlightClicked {
+ plugin_id: 0,
+ client_id,
+ pane_id: PaneId::Terminal(1),
+ pattern: "test".into(),
+ matched_string: "test_match".into(),
+ context: BTreeMap::new(),
+ });
+
+ screen_thread.join().unwrap();
+ teardown();
+
+ let plugin_bytes_event = received_screen_instructions
+ .lock()
+ .unwrap()
+ .iter()
+ .find_map(|i| {
+ if let ScreenInstruction::PluginBytes(plugin_render_assets) = i {
+ for plugin_render_asset in plugin_render_assets {
+ let plugin_bytes = plugin_render_asset.bytes.clone();
+ let plugin_bytes = String::from_utf8_lossy(plugin_bytes.as_slice()).to_string();
+ if plugin_bytes.contains("HighlightClicked") {
+ return Some(plugin_bytes);
+ }
+ }
+ }
+ None
+ });
+ assert!(
+ plugin_bytes_event.is_some(),
+ "Expected PluginBytes containing 'HighlightClicked'"
+ );
+ assert_snapshot!(format!("{:#?}", plugin_bytes_event));
+}
diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__highlight_clicked_event_delivered_to_plugin.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__highlight_clicked_event_delivered_to_plugin.snap
new file mode 100644
index 00000000..f331b82a
--- /dev/null
+++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__highlight_clicked_event_delivered_to_plugin.snap
@@ -0,0 +1,7 @@
+---
+source: zellij-server/src/plugins/./unit/plugin_tests.rs
+expression: "format!(\"{:#?}\", plugin_bytes_event)"
+---
+Some(
+ "Rows: 20, Cols: 121, Received events: [HighlightClicked { pane_id: Terminal(1), pattern: \"test\", matched_string: \"test_match\", context: {} }]\n\r",
+)
diff --git a/zellij-server/src/plugins/wasm_bridge.rs b/zellij-server/src/plugins/wasm_bridge.rs
index d82705ef..1c928eb1 100644
--- a/zellij-server/src/plugins/wasm_bridge.rs
+++ b/zellij-server/src/plugins/wasm_bridge.rs
@@ -514,6 +514,10 @@ impl WasmBridge {
.senders
.send_to_screen(ScreenInstruction::ClearKeyPressesIntercepts(client_id));
}
+ // Clear any regex highlights this plugin registered across all panes
+ let _ = self
+ .senders
+ .send_to_screen(ScreenInstruction::ClearAllPluginHighlights(plugin_id));
// Send worker exit messages
for (_worker_name, worker_sender) in workers {
@@ -2010,6 +2014,7 @@ fn check_event_permission(
| Event::CwdChanged(..)
| Event::AvailableLayoutInfo(..)
| Event::PluginConfigurationChanged(..)
+ | Event::HighlightClicked { .. }
| Event::InputReceived => PermissionType::ReadApplicationState,
Event::WebServerStatus(..) => PermissionType::StartWebServer,
Event::PaneRenderReport(..) => PermissionType::ReadPaneContents,
diff --git a/zellij-server/src/plugins/zellij_exports.rs b/zellij-server/src/plugins/zellij_exports.rs
index dd323977..d48a80b9 100644
--- a/zellij-server/src/plugins/zellij_exports.rs
+++ b/zellij-server/src/plugins/zellij_exports.rs
@@ -37,7 +37,7 @@ use zellij_utils::data::{
OpenTerminalInPlaceOfPluginResponse, OpenTerminalInPlaceResponse,
OpenTerminalNearPluginResponse, OpenTerminalPaneInPlaceOfPaneIdResponse, OpenTerminalResponse,
OriginatingPlugin, PaneScrollbackResponse, PermissionStatus, PermissionType, PluginPermission,
- RenameLayoutResponse, SaveLayoutResponse, TabMetadata,
+ RegexHighlight, RenameLayoutResponse, SaveLayoutResponse, TabMetadata,
};
use zellij_utils::home::default_layout_dir;
use zellij_utils::input::permission::PermissionCache;
@@ -739,6 +739,12 @@ fn host_run_plugin_command(mut caller: Caller<'_, PluginEnv>) {
),
PluginCommand::ShowFloatingPanes { tab_id } => show_floating_panes(env, tab_id),
PluginCommand::HideFloatingPanes { tab_id } => hide_floating_panes(env, tab_id),
+ PluginCommand::SetPaneRegexHighlights(pane_id, highlights) => {
+ set_pane_regex_highlights(env, pane_id, highlights)
+ },
+ PluginCommand::ClearPaneHighlights(pane_id) => {
+ clear_pane_highlights(env, pane_id)
+ },
},
(PermissionStatus::Denied, permission) => {
log::error!(
@@ -3387,6 +3393,35 @@ fn hide_floating_panes(env: &PluginEnv, tab_id: Option<usize>) {
let _ = wasi_write_object(env, &response.encode_to_vec());
}
+fn set_pane_regex_highlights(
+ env: &PluginEnv,
+ pane_id: zellij_utils::data::PaneId,
+ highlights: Vec<RegexHighlight>,
+) {
+ let err_context = || "failed to set pane regex highlights".to_string();
+ let pane_id: PaneId = pane_id.into();
+ env.senders
+ .send_to_screen(ScreenInstruction::SetPluginRegexHighlights {
+ pane_id,
+ plugin_id: env.plugin_id,
+ highlights,
+ })
+ .with_context(err_context)
+ .non_fatal();
+}
+
+fn clear_pane_highlights(env: &PluginEnv, pane_id: zellij_utils::data::PaneId) {
+ let err_context = || "failed to clear pane highlights".to_string();
+ let pane_id: PaneId = pane_id.into();
+ env.senders
+ .send_to_screen(ScreenInstruction::ClearPluginHighlights {
+ pane_id,
+ plugin_id: env.plugin_id,
+ })
+ .with_context(err_context)
+ .non_fatal();
+}
+
fn current_session_last_saved_time(env: &PluginEnv) {
use zellij_utils::plugin_api::plugin_command::ProtobufCurrentSessionLastSavedTimeResponse;
@@ -5086,7 +5121,9 @@ fn check_command_permission(
| PluginCommand::RenameLayout { .. }
| PluginCommand::EditLayout { .. }
| PluginCommand::ShowFloatingPanes { .. }
- | PluginCommand::HideFloatingPanes { .. } => PermissionType::ChangeApplicationState,
+ | PluginCommand::HideFloatingPanes { .. }
+ | PluginCommand::SetPaneRegexHighlights(..)
+ | PluginCommand::ClearPaneHighlights(..) => PermissionType::ChangeApplicationState,
PluginCommand::UnblockCliPipeInput(..)
| PluginCommand::BlockCliPipeInput(..)
| PluginCommand::CliPipeOutput(..) => PermissionType::ReadCliPipes,