From 1fdded129fe766729ac332fa881c0681c9495316 Mon Sep 17 00:00:00 2001 From: Lewis Cook Date: Tue, 13 Jul 2021 10:06:15 +0100 Subject: Make the trash feature optional --- Cargo.toml | 5 +++-- src/interactive/app/handlers.rs | 2 ++ src/interactive/widgets/help.rs | 1 + src/interactive/widgets/mark.rs | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c89614..43cb98c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,12 @@ license = "MIT" include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md", "!**/tests/*"] [features] -default = ["tui-crossplatform"] +default = ["tui-crossplatform", "trash-move"] tui-unix = ["crosstermion/tui-react-termion", "tui-shared"] tui-crossplatform = ["crosstermion/tui-react-crossterm", "tui-shared"] tui-shared = ["tui", "tui-react", "open", "unicode-segmentation"] +trash-move = ["trash"] [dependencies] clap = "3.0.0-beta.2" @@ -27,7 +28,7 @@ num_cpus = "1.10.0" filesize = "0.2.0" anyhow = "1.0.31" colored = "2.0.0" -trash = "2.0.1" +trash = { version = "2.0.1", optional = true } # 'tui' related unicode-segmentation = { version = "1.3.0", optional = true } diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs index 73e7403..d36e5f8 100644 --- a/src/interactive/app/handlers.rs +++ b/src/interactive/app/handlers.rs @@ -229,6 +229,7 @@ impl AppState { self.message = None; res } + #[cfg(feature = "trash-move")] Some(MarkMode::Trash) => { self.message = Some("Trashing entries...".to_string()); let mut entries_trashed = 0; @@ -272,6 +273,7 @@ impl AppState { Ok(entries_deleted) } + #[cfg(feature = "trash-move")] pub fn trash_entry( &mut self, index: TreeIndex, diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs index d410035..769cfda 100644 --- a/src/interactive/widgets/help.rs +++ b/src/interactive/widgets/help.rs @@ -168,6 +168,7 @@ impl HelpPane { "Permanently delete all marked entries without prompt!", Some("This operation cannot be undone!"), ); + #[cfg(feature = "trash-move")] hotkey( "Ctrl + t", "Move all marked entries to the trash bin", diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index d80b311..0cc48f2 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -28,6 +28,7 @@ use unicode_segmentation::UnicodeSegmentation; pub enum MarkMode { Delete, + #[cfg(feature = "trash-move")] Trash, } @@ -110,6 +111,7 @@ impl MarkPane { let action = None; match key { Ctrl('r') => return Some(self.prepare_deletion(MarkMode::Delete)), + #[cfg(feature = "trash-move")] Ctrl('t') => return Some(self.prepare_deletion(MarkMode::Trash)), Char('x') | Char('d') | Char(' ') => { return self.remove_selected().map(|s| (s, action)) @@ -360,6 +362,7 @@ impl MarkPane { sub_modifier: Modifier::empty(), }; Paragraph::new(Text::from(Spans::from(vec![ + #[cfg(feature = "trash-move")] Span::styled( " Ctrl + t", Style { @@ -368,6 +371,7 @@ impl MarkPane { ..default_style }, ), + #[cfg(feature = "trash-move")] Span::styled(" to trash or ", default_style), Span::styled( " Ctrl + r", -- cgit v1.2.3 From ee680b9b82618a1d5ecab1fb2e431fe3ff64d130 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Jul 2021 08:12:45 +0800 Subject: Add checking and testing of new feature toggle --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2172c42..7766ad2 100644 --- a/Makefile +++ b/Makefile @@ -35,11 +35,13 @@ check:## run cargo-check with various features cargo check --all cargo check --all-features cargo check --no-default-features - cargo check --features tui-unix - cargo check --features tui-crossplatform + cargo check --no-default-features --features tui-unix + cargo check --no-default-features --features tui-crossplatform + cargo check --no-default-features --features trash-move unit-tests: ## run all unit tests cargo test --all + cargo test --all --no-default-features --features trash-move continuous-unit-tests: ## run all unit tests whenever something changes watchexec -w src $(MAKE) unit-tests -- cgit v1.2.3 From 6894dd8db51cd6fe8a70ad0c906ef351dc0a720c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Jul 2021 08:27:12 +0800 Subject: refactor --- src/interactive/app/tests/journeys_with_writes.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/interactive/app/tests/journeys_with_writes.rs b/src/interactive/app/tests/journeys_with_writes.rs index 9ea65d6..a4d5c53 100644 --- a/src/interactive/app/tests/journeys_with_writes.rs +++ b/src/interactive/app/tests/journeys_with_writes.rs @@ -18,11 +18,7 @@ fn basic_user_journey_with_deletion() -> Result<()> { "expecting 4 selected entries, the parent dir, and some children" ); - assert_eq!( - fixture.as_ref().is_dir(), - true, - "expecting fixture root to exist" - ); + assert!(fixture.as_ref().is_dir(), "expecting fixture root to exist"); // When selecting the marker window and pressing the combination to delete entries app.process_events( @@ -33,9 +29,8 @@ fn basic_user_journey_with_deletion() -> Result<()> { ] .into_iter(), )?; - assert_eq!( + assert!( app.window.mark_pane.is_none(), - true, "the marker pane is gone as all entries have been removed" ); assert_eq!(app.state.selected, None, "nothing is left to be selected"); @@ -43,9 +38,8 @@ fn basic_user_journey_with_deletion() -> Result<()> { app.state.root, app.traversal.root_index, "the only root left is the top-level" ); - assert_eq!( - fixture.as_ref().is_dir(), - false, + assert!( + !fixture.as_ref().is_dir(), "the directory should have been deleted", ); Ok(()) -- cgit v1.2.3