Skip to content

Commit

Permalink
Use Option<&str> for targeted file path
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoheiu committed Jan 20, 2024
1 parent bf4e0ec commit 2572096
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,10 @@ pub fn run(arg: PathBuf, log: bool, choosefiles_path: Option<PathBuf>) -> 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()
Expand Down Expand Up @@ -161,7 +158,7 @@ pub fn run(arg: PathBuf, log: bool, choosefiles_path: Option<PathBuf>) -> Result
fn _run(
mut state: State,
session_path: PathBuf,
file_selected: Option<String>,
file_selected: Option<&str>,
) -> Result<(), FxError> {
//Enter the alternate screen with crossterm
let mut screen = stdout();
Expand All @@ -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;
Expand Down

0 comments on commit 2572096

Please sign in to comment.