From 017cbd7b4c3e57e1a98fbc595159be39bc97c708 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 8 Jun 2021 09:31:57 +0800 Subject: Print marked items upon exit if these are left in the marked pane Fixes #87 --- src/interactive/widgets/mark.rs | 3 +++ src/main.rs | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index 0b38e99..4e5829a 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -102,6 +102,9 @@ impl MarkPane { pub fn marked(&self) -> &EntryMarkMap { &self.marked } + pub fn into_paths(self) -> impl Iterator { + self.marked.into_iter().map(|(_k, v)| v.path) + } pub fn process_events(mut self, key: Key) -> Option<(Self, Option)> { let action = None; match key { diff --git a/src/main.rs b/src/main.rs index 4c75191..0596458 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,8 +89,18 @@ fn main() -> Result<()> { )? .map(|(keys_rx, mut app)| { let res = app.process_events(&mut terminal, keys_rx.into_iter()); - // Leak app memory to avoid having to wait for the hashmap to deallocate, which causes a noticeable delay shortly before the the - // program exits anyway. + + let res = res.map(|r| { + ( + r, + app.window + .mark_pane + .take() + .map(|marked| marked.into_paths()), + ) + }); + // Leak app memory to avoid having to wait for the hashmap to deallocate, + // which causes a noticeable delay shortly before the the program exits anyway. std::mem::forget(app); res }); @@ -99,7 +109,18 @@ fn main() -> Result<()> { io::stdout().flush().ok(); // Exit 'quickly' to avoid having to not have to deal with slightly different types in the other match branches - std::process::exit(res.transpose()?.map(|e| e.to_exit_code()).unwrap_or(0)); + std::process::exit( + res.transpose()? + .map(|(walk_result, paths)| { + if let Some(paths) = paths { + for path in paths { + println!("{}", path.display()) + } + } + walk_result.to_exit_code() + }) + .unwrap_or(0), + ); } Some(Aggregate { input, -- cgit v1.2.3