Skip to content

Commit

Permalink
Print marked items upon exit if these are left in the marked pane
Browse files Browse the repository at this point in the history
Fixes #87
  • Loading branch information
Byron committed Jun 8, 2021
1 parent c8d5650 commit 017cbd7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 24 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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,
Expand Down

0 comments on commit 017cbd7

Please sign in to comment.