diff options
author | Piotr Wach <pwach@bloomberg.net> | 2024-01-07 09:44:10 +0000 |
---|---|---|
committer | Piotr Wach <pwach@bloomberg.net> | 2024-01-07 09:44:10 +0000 |
commit | 13c381bebc6a64e553ec11793ec8880f868e712c (patch) | |
tree | 23a8504e298dc8b0bb75926587b5d1a0a3ddf87e /src/main.rs | |
parent | e53036ad84b71e1121588929fe4653a7ababbf67 (diff) |
Clean-up init function
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/src/main.rs b/src/main.rs index 7694cf1..e579aad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,46 +68,41 @@ fn main() -> Result<()> { ) .with_context(|| "Could not instantiate terminal")?; + // TODO: use + // extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?, + let keys_rx = input_channel(); - let res = TerminalApp::initialize( - &mut terminal, - byte_format, - extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?, - keys_rx, - )? - .map(|(keys_rx, mut app)| { - let res = app.process_events(&mut terminal, keys_rx.into_iter()); - - 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 + let mut app = TerminalApp::initialize(&mut terminal, byte_format)?; + + let res = app.process_events(&mut terminal, keys_rx.into_iter()); + + 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); drop(terminal); io::stderr().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(|(walk_result, paths)| { - if let Some(paths) = paths { - for path in paths { - println!("{}", path.display()) - } + res.map(|(walk_result, paths)| { + if let Some(paths) = paths { + for path in paths { + println!("{}", path.display()) } - walk_result.to_exit_code() - }) - .unwrap_or(0), + } + walk_result.to_exit_code() + }) + .unwrap_or(0), ); } Some(Aggregate { |