From 25720962a29a451f38f5a212cd71ba42a6373d3c Mon Sep 17 00:00:00 2001 From: Kyohei Uto Date: Sun, 21 Jan 2024 06:06:57 +0900 Subject: Use Option<&str> for targeted file path --- src/run.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/run.rs b/src/run.rs index 7be01ec..a442f1e 100644 --- a/src/run.rs +++ b/src/run.rs @@ -110,13 +110,10 @@ pub fn run(arg: PathBuf, log: bool, choosefiles_path: Option) -> Result } } else if let Some(parent) = arg.clone().parent() { file_selected = { - let name = arg.file_name().map(|name| name.to_str()); - match name { - Some(name) => name.map(|name| name.to_string()), - None => None, - } + arg.file_name().map(|name| name.to_str()).unwrap_or_else(|| None) }; if cfg!(not(windows)) { + // Same as when is_dir() parent.canonicalize()? } else { parent.to_path_buf() @@ -161,7 +158,7 @@ pub fn run(arg: PathBuf, log: bool, choosefiles_path: Option) -> Result fn _run( mut state: State, session_path: PathBuf, - file_selected: Option, + file_selected: Option<&str>, ) -> Result<(), FxError> { //Enter the alternate screen with crossterm let mut screen = stdout(); @@ -184,6 +181,7 @@ fn _run( state.reload(BEGINNING_ROW)?; } + // If file path is set as argument, point to that file. if let Some(p) = file_selected { if let Some(target) = state.list.iter().position(|x| x.file_name == p) { state.layout.nums.skip = target as u16; -- cgit v1.2.3