diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-07-14 08:35:06 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-07-14 08:35:06 +0800 |
commit | b12b98a07935c839a11af08cfa9dc872b5a127e8 (patch) | |
tree | 898b0962b75eb87af194c288e24de20df2ea0c70 | |
parent | 64175e028965958d0c22f8ffe55cab2fc01f9fc8 (diff) | |
parent | 6894dd8db51cd6fe8a70ad0c906ef351dc0a720c (diff) |
Merge branch 'optional-trash'
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | src/interactive/app/handlers.rs | 2 | ||||
-rw-r--r-- | src/interactive/app/tests/journeys_with_writes.rs | 14 | ||||
-rw-r--r-- | src/interactive/widgets/help.rs | 1 | ||||
-rw-r--r-- | src/interactive/widgets/mark.rs | 4 |
6 files changed, 18 insertions, 14 deletions
@@ -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 } @@ -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 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/app/tests/journeys_with_writes.rs b/src/interactive/app/tests/journeys_with_writes.rs index d55b368..6e411f3 100644 --- a/src/interactive/app/tests/journeys_with_writes.rs +++ b/src/interactive/app/tests/journeys_with_writes.rs @@ -19,11 +19,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( @@ -34,9 +30,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"); @@ -44,9 +39,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(()) 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", |