diff options
| author | Aram Drevekenin <aram@poor.dev> | 2024-06-14 17:11:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-14 17:11:02 +0200 |
| commit | 1f0ae94f01647eab66cabbd11434ecae1fac8da3 (patch) | |
| tree | b568f9ffc2064f4bdfd9c02c0aa5e581a3d1e750 /zellij-server/src/plugins/unit | |
| parent | docs(readme): add name origin section (#3391) (diff) | |
| download | sl0ppij-1f0ae94f01647eab66cabbd11434ecae1fac8da3.tar.gz sl0ppij-1f0ae94f01647eab66cabbd11434ecae1fac8da3.tar.xz sl0ppij-1f0ae94f01647eab66cabbd11434ecae1fac8da3.zip | |
feat(plugins): rebind keys at runtime (#3422)
* refactor(server): interpret keys on server so they can be rebound
* feat(plugins): allow rebinding keys at runtime
* various cleanups
* add tests
* style(fmt): rustfmt
* fix(tests): address (some) e2e test flakiness
* style(fmt): rustfmt
Diffstat (limited to 'zellij-server/src/plugins/unit')
4 files changed, 96 insertions, 2 deletions
diff --git a/zellij-server/src/plugins/unit/plugin_tests.rs b/zellij-server/src/plugins/unit/plugin_tests.rs index 22a1bf1f..b644fe2f 100644 --- a/zellij-server/src/plugins/unit/plugin_tests.rs +++ b/zellij-server/src/plugins/unit/plugin_tests.rs @@ -6487,6 +6487,87 @@ pub fn disconnect_other_clients_plugins_command() { #[test] #[ignore] +pub fn rebind_keys_plugin_command() { + let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its + // destructor removes the directory + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, server_receiver, screen_receiver, teardown) = + create_plugin_thread_with_server_receiver(Some(plugin_host_folder)); + 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_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); + let received_server_instruction = Arc::new(Mutex::new(vec![])); + let server_thread = log_actions_in_thread!( + received_server_instruction, + ServerInstruction::RebindKeys, + server_receiver, + 1 + ); + + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); + let _ = plugin_thread_sender.send(PluginInstruction::Load( + plugin_should_float, + false, + plugin_title, + run_plugin, + tab_index, + None, + client_id, + size, + None, + false, + )); + std::thread::sleep(std::time::Duration::from_millis(500)); + + let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( + None, + Some(client_id), + Event::Key(KeyWithModifier::new(BareKey::Char('0')).with_ctrl_modifier()), // this triggers the enent in the fixture plugin + )])); + std::thread::sleep(std::time::Duration::from_millis(500)); + teardown(); + server_thread.join().unwrap(); // this might take a while if the cache is cold + let rebind_keys_event = received_server_instruction + .lock() + .unwrap() + .iter() + .rev() + .find_map(|i| { + if let ServerInstruction::RebindKeys(..) = i { + Some(i.clone()) + } else { + None + } + }) + .clone(); + assert_snapshot!(format!("{:#?}", rebind_keys_event)); +} + +#[test] +#[ignore] pub fn run_plugin_in_specific_cwd() { // note that this test might sometimes fail when run alone without the rest of the suite due to // timing issues diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap index 9c3ecd06..465f1088 100644 --- a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/plugins/./unit/plugin_tests.rs -assertion_line: 5307 +assertion_line: 5500 expression: "format!(\"{:#?}\", permissions)" --- Some( @@ -14,5 +14,6 @@ Some( WebAccess, ReadCliPipes, MessageAndLaunchOtherPlugins, + RebindKeys, ], ) diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__rebind_keys_plugin_command.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__rebind_keys_plugin_command.snap new file mode 100644 index 00000000..b5375e96 --- /dev/null +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__rebind_keys_plugin_command.snap @@ -0,0 +1,11 @@ +--- +source: zellij-server/src/plugins/./unit/plugin_tests.rs +assertion_line: 6566 +expression: "format!(\"{:#?}\", rebind_keys_event)" +--- +Some( + RebindKeys( + 1, + "\n keybinds {\n locked {\n bind \"a\" { NewTab; }\n }\n }\n ", + ), +) diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__request_plugin_permissions.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__request_plugin_permissions.snap index 3d9f7cfe..a0fec410 100644 --- a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__request_plugin_permissions.snap +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__request_plugin_permissions.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/plugins/./unit/plugin_tests.rs -assertion_line: 5217 +assertion_line: 5409 expression: "format!(\"{:#?}\", new_tab_event)" --- Some( @@ -16,5 +16,6 @@ Some( WebAccess, ReadCliPipes, MessageAndLaunchOtherPlugins, + RebindKeys, ], ) |
