diff options
52 files changed, 3066 insertions, 1250 deletions
diff --git a/Cargo.lock b/Cargo.lock index 33c762962..b410d17f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,11 +75,11 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "async-channel" -version = "1.6.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" dependencies = [ - "concurrent-queue", + "concurrent-queue 2.2.0", "event-listener", "futures-core", ] @@ -91,7 +91,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" dependencies = [ "async-task", - "concurrent-queue", + "concurrent-queue 1.2.2", "fastrand", "futures-lite", "once_cell", @@ -119,7 +119,7 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5e18f61464ae81cde0a23e713ae8fd299580c54d697a35820cfd0625b8b0e07" dependencies = [ - "concurrent-queue", + "concurrent-queue 1.2.2", "futures-lite", "libc", "log", @@ -502,6 +502,15 @@ dependencies = [ ] [[package]] +name = "concurrent-queue" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +dependencies = [ + "crossbeam-utils", +] + +[[package]] name = "console" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -679,12 +688,11 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ "cfg-if 1.0.0", - "lazy_static", ] [[package]] @@ -1009,6 +1017,18 @@ dependencies = [ ] [[package]] +name = "filetime" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "windows-sys 0.48.0", +] + +[[package]] name = "finl_unicode" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1046,6 +1066,15 @@ dependencies = [ ] [[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] name = "futures-channel" version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1278,6 +1307,26 @@ dependencies = [ ] [[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] name = "insta" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1392,6 +1441,26 @@ dependencies = [ ] [[package]] +name = "kqueue" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8fc60ba15bf51257aa9807a48a61013db043fcf3a78cb0d916e8e396dcad98" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] name = "kv-log-macro" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1664,6 +1733,18 @@ dependencies = [ ] [[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.45.0", +] + +[[package]] name = "miow" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1733,6 +1814,24 @@ dependencies = [ ] [[package]] +name = "notify" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d9ba6c734de18ca27c8cef5cd7058aa4ac9f63596131e4c7e41e579319032a2" +dependencies = [ + "bitflags", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "mio 0.8.6", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] name = "ntapi" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2838,6 +2937,7 @@ dependencies = [ "pretty-bytes", "serde", "serde_json", + "strip-ansi-escapes", "unicode-width", "walkdir", "zellij-tile", @@ -4243,7 +4343,7 @@ version = "0.37.0" dependencies = [ "insta", "log", - "mio", + "mio 0.7.14", "serde", "serde_json", "serde_yaml", @@ -4306,6 +4406,7 @@ name = "zellij-utils" version = "0.37.0" dependencies = [ "anyhow", + "async-channel", "async-std", "backtrace", "clap", @@ -4323,6 +4424,7 @@ dependencies = [ "log4rs", "miette", "nix 0.23.1", + "notify", "once_cell", "percent-encoding", "regex", diff --git a/default-plugins/fixture-plugin-for-tests/src/main.rs b/default-plugins/fixture-plugin-for-tests/src/main.rs index 124b2dc75..7e4139f55 100644 --- a/default-plugins/fixture-plugin-for-tests/src/main.rs +++ b/default-plugins/fixture-plugin-for-tests/src/main.rs @@ -32,7 +32,7 @@ impl<'de> ZellijWorker<'de> for TestWorker { } register_plugin!(State); -register_worker!(TestWorker, test_worker); +register_worker!(TestWorker, test_worker, TEST_WORKER); impl ZellijPlugin for State { fn load(&mut self) { @@ -40,6 +40,10 @@ impl ZellijPlugin for State { EventType::InputReceived, EventType::SystemClipboardFailure, EventType::CustomMessage, + EventType::FileSystemCreate, + EventType::FileSystemRead, + EventType::FileSystemUpdate, + EventType::FileSystemDelete, ]); } diff --git a/default-plugins/strider/Cargo.toml b/default-plugins/strider/Cargo.toml index d45a8ff21..65b5d23e9 100644 --- a/default-plugins/strider/Cargo.toml +++ b/default-plugins/strider/Cargo.toml @@ -16,3 +16,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" unicode-width = "0.1.8" ansi_term = "0.12.1" +strip-ansi-escapes = "0.1.1" diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs index 4f299c508..966b53a4f 100644 --- a/default-plugins/strider/src/main.rs +++ b/default-plugins/strider/src/main.rs @@ -2,26 +2,45 @@ mod search; mod state; use colored::*; -use search::{ResultsOfSearch, SearchWorker}; +use search::{FileContentsWorker, FileNameWorker, MessageToSearch, ResultsOfSearch}; +use serde::{Deserialize, Serialize}; use serde_json; -use state::{refresh_directory, FsEntry, State, CURRENT_SEARCH_TERM}; +use state::{refresh_directory, FsEntry, State}; use std::{cmp::min, time::Instant}; use zellij_tile::prelude::*; register_plugin!(State); -register_worker!(SearchWorker, search_worker); +register_worker!(FileNameWorker, file_name_search_worker, FILE_NAME_WORKER); +register_worker!( + FileContentsWorker, + file_contents_search_worker, + FILE_CONTENTS_WORKER +); impl ZellijPlugin for State { fn load(&mut self) { refresh_directory(self); - self.loading = true; + self.search_state.loading = true; subscribe(&[ EventType::Key, EventType::Mouse, EventType::CustomMessage, EventType::Timer, + EventType::FileSystemCreate, + EventType::FileSystemUpdate, + EventType::FileSystemDelete, ]); - post_message_to("search", String::from("scan_folder"), String::new()); + post_message_to( + "file_name_search", + serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), + "".to_owned(), + ); + post_message_to( + "file_contents_search", + serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), + "".to_owned(), + ); + self.search_state.loading = true; set_timeout(0.5); // for displaying loading animation } @@ -35,57 +54,43 @@ impl ZellijPlugin for State { self.ev_history.push_back((event.clone(), Instant::now())); match event { Event::Timer(_elapsed) => { - should_render = true; - if self.loading { + if self.search_state.loading { set_timeout(0.5); - if self.loading_animation_offset == u8::MAX { - self.loading_animation_offset = 0; - } else { - self.loading_animation_offset = - self.loading_animation_offset.saturating_add(1); - } + self.search_state.progress_animation(); + should_render = true; } }, - Event::CustomMessage(message, payload) => match message.as_str() { - "update_search_results" => { - if let Ok(mut results_of_search) = - serde_json::from_str::<ResultsOfSearch>(&payload) + Event::CustomMessage(message, payload) => match serde_json::from_str(&message) { + Ok(MessageToPlugin::UpdateFileNameSearchResults) => { + if let Ok(results_of_search) = serde_json::from_str::<ResultsOfSearch>(&payload) { - if Some(results_of_search.search_term) == self.search_term { - self.search_results = - results_of_search.search_results.drain(..).collect(); - should_render = true; - } + self.search_state + .update_file_name_search_results(results_of_search); + should_render = true; + } + }, + Ok(MessageToPlugin::UpdateFileContentsSearchResults) => { + if let Ok(results_of_search) = serde_json::from_str::<ResultsOfSearch>(&payload) + { + self.search_state + .update_file_contents_search_results(results_of_search); + should_render = true; } }, - "done_scanning_folder" => { - self.loading = false; + Ok(MessageToPlugin::DoneScanningFolder) => { + self.search_state.loading = false; should_render = true; }, - _ => {}, + Err(e) => eprintln!("Failed to deserialize custom message: {:?}", e), }, Event::Key(key) => match key { - // modes: - // 1. typing_search_term - // 2. exploring_search_results - // 3. normal - Key::Esc | Key::Char('\n') if self.typing_search_term() => { - self.accept_search_term(); - }, - _ if self.typing_search_term() => { - self.append_to_search_term(key); - if let Some(search_term) = self.search_term.as_ref() { - std::fs::write(CURRENT_SEARCH_TERM, search_term.as_bytes()).unwrap(); - post_message_to( - "search", - String::from("search"), - String::from(&self.search_term.clone().unwrap()), - ); - } + Key::Esc if self.typing_search_term() => { + self.stop_typing_search_term(); + self.search_state.handle_key(key); should_render = true; }, - Key::Esc if self.exploring_search_results() => { - self.stop_exploring_search_results(); + _ if self.typing_search_term() => { + self.search_state.handle_key(key); should_render = true; }, Key::Char('/') => { @@ -94,40 +99,27 @@ im |