diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-06-09 22:49:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 22:49:12 +0200 |
commit | 8485b1c2969e7f88feaf2f809b6b405fbe442ba4 (patch) | |
tree | 989148565b8883d9a04e35f795a3f50008c0e1b1 /default-plugins | |
parent | 7f0b87852079f260cc9a834c2dc54eeb002d5879 (diff) |
feat(plugins): extensive plugin api (#2516)
* feat(plugins): add our entire API
* style(fmt): rustfmt
* fix(detach): make it work again
Diffstat (limited to 'default-plugins')
-rw-r--r-- | default-plugins/fixture-plugin-for-tests/src/main.rs | 138 | ||||
-rw-r--r-- | default-plugins/strider/src/search/mod.rs | 14 |
2 files changed, 137 insertions, 15 deletions
diff --git a/default-plugins/fixture-plugin-for-tests/src/main.rs b/default-plugins/fixture-plugin-for-tests/src/main.rs index 7e4139f55..2107137d1 100644 --- a/default-plugins/fixture-plugin-for-tests/src/main.rs +++ b/default-plugins/fixture-plugin-for-tests/src/main.rs @@ -38,10 +38,10 @@ impl ZellijPlugin for State { fn load(&mut self) { subscribe(&[ EventType::InputReceived, + EventType::Key, EventType::SystemClipboardFailure, EventType::CustomMessage, EventType::FileSystemCreate, - EventType::FileSystemRead, EventType::FileSystemUpdate, EventType::FileSystemDelete, ]); @@ -49,6 +49,142 @@ impl ZellijPlugin for State { fn update(&mut self, event: Event) -> bool { match &event { + Event::Key(key) => match key { + Key::Char('a') => { + switch_to_input_mode(&InputMode::Tab); + }, + Key::Char('b') => { + new_tabs_with_layout( + "layout { + tab { + pane + pane + } + tab split_direction=\"vertical\" { + pane + pane + } + }", + ); + }, + Key::Char('c') => new_tab(), + Key::Char('d') => go_to_next_tab(), + Key::Char('e') => go_to_previous_tab(), + Key::Char('f') => { + let resize = Resize::Increase; + resize_focused_pane(resize) + }, + Key::Char('g') => { + let resize = Resize::Increase; + let direction = Direction::Left; + resize_focused_pane_with_direction(resize, direction); + }, + Key::Char('h') => focus_next_pane(), + Key::Char('i') => focus_previous_pane(), + Key::Char('j') => { + let direction = Direction::Left; + move_focus(direction) + }, + Key::Char('k') => { + let direction = Direction::Left; + move_focus_or_tab(direction) + }, + Key::Char('l') => detach(), + Key::Char('m') => edit_scrollback(), + Key::Char('n') => { + let bytes = vec![102, 111, 111]; + write(bytes) + }, + Key::Char('o') => { + let chars = "foo"; + write_chars(chars); + }, + Key::Char('p') => toggle_tab(), + Key::Char('q') => move_pane(), + Key::Char('r') => { + let direction = Direction::Left; + move_pane_with_direction(direction) + }, + Key::Char('s') => clear_screen(), + Key::Char('t') => scroll_up(), + Key::Char('u') => scroll_down(), + Key::Char('v') => scroll_to_top(), + Key::Char('w') => scroll_to_bottom(), + Key::Char('x') => page_scroll_up(), + Key::Char('y') => page_scroll_down(), + Key::Char('z') => toggle_focus_fullscreen(), + Key::Char('1') => toggle_pane_frames(), + Key::Char('2') => toggle_pane_embed_or_eject(), + Key::Char('3') => undo_rename_pane(), + Key::Char('4') => close_focus(), + Key::Char('5') => toggle_active_tab_sync(), + Key::Char('6') => close_focused_tab(), + Key::Char('7') => undo_rename_tab(), + Key::Char('8') => quit_zellij(), + Key::Ctrl('a') => previous_swap_layout(), + Key::Ctrl('b') => next_swap_layout(), + Key::Ctrl('c') => { + let tab_name = "my tab name"; + go_to_tab_name(tab_name) + }, + Key::Ctrl('d') => { + let tab_name = "my tab name"; + focus_or_create_tab(tab_name) + }, + Key::Ctrl('e') => { + let tab_index = 2; + go_to_tab(tab_index) + }, + Key::Ctrl('f') => { + let plugin_url = "file:/path/to/my/plugin.wasm"; + start_or_reload_plugin(plugin_url) + }, + Key::Ctrl('g') => { + open_file(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); + }, + Key::Ctrl('h') => { + open_file_floating(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); + }, + Key::Ctrl('i') => { + open_file_with_line( + std::path::PathBuf::from("/path/to/my/file.rs").as_path(), + 42, + ); + }, + Key::Ctrl('j') => { + open_file_with_line_floating( + std::path::PathBuf::from("/path/to/my/file.rs").as_path(), + 42, + ); + }, + Key::Ctrl('k') => { + open_terminal(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); + }, + Key::Ctrl('l') => { + open_terminal_floating( + std::path::PathBuf::from("/path/to/my/file.rs").as_path(), + ); + }, + Key::Ctrl('m') => { + open_command_pane( + std::path::PathBuf::from("/path/to/my/file.rs").as_path(), + vec!["arg1".to_owned(), "arg2".to_owned()], + ); + }, + Key::Ctrl('n') => { + open_command_pane_floating( + std::path::PathBuf::from("/path/to/my/file.rs").as_path(), + vec!["arg1".to_owned(), "arg2".to_owned()], + ); + }, + Key::Ctrl('o') => { + switch_tab_to(1); + }, + Key::Ctrl('p') => { + hide_self(); + }, + _ => {}, + }, Event::CustomMessage(message, payload) => { if message == "pong" { self.received_payload = Some(payload.clone()); diff --git a/default-plugins/strider/src/search/mod.rs b/default-plugins/strider/src/search/mod.rs index 5aba9c4d9..1a9db2dad 100644 --- a/default-plugins/strider/src/search/mod.rs +++ b/default-plugins/strider/src/search/mod.rs @@ -204,17 +204,7 @@ impl Search { ) -> Vec<SearchResult> { let mut matches = vec![]; for ((file_name, line_number), line_entry) in &self.file_contents { - if line_entry.contains("struct") { - if line_entry.len() < 400 { - eprintln!("matching against: {:?}", line_entry) - } else { - eprintln!("matching again line that has struct but is very long") - } - } if let Some((score, indices)) = matcher.fuzzy_indices(&line_entry, &search_term) { - if line_entry.contains("struct") { - eprintln!("score: {:?}", score) - } matches.push(SearchResult::new_file_line( score, indices, @@ -222,10 +212,6 @@ impl Search { line_entry.clone(), *line_number, )); - } else { - if line_entry.contains("struct") { - eprintln!("no score!") - } } } matches |