diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-06-08 09:31:57 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-06-08 09:31:57 +0800 |
commit | 017cbd7b4c3e57e1a98fbc595159be39bc97c708 (patch) | |
tree | 5a52c5d8fca5011a23ab7f3394388fea61bf8fed | |
parent | c8d5650be77e000801b282c4c0a3861e710de6d8 (diff) |
Print marked items upon exit if these are left in the marked pane
Fixes #87
-rw-r--r-- | src/interactive/widgets/mark.rs | 3 | ||||
-rw-r--r-- | 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<Item = PathBuf> { + self.marked.into_iter().map(|(_k, v)| v.path) + } pub fn process_events(mut self, key: Key) -> Option<(Self, Option<MarkMode>)> { 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, |