Re-structure

This commit is contained in:
sharkdp 2017-05-12 23:23:57 +02:00
parent b4a252a391
commit 3e5d9d81e7
1 changed files with 16 additions and 13 deletions

View File

@ -27,7 +27,12 @@ struct FdOptions {
} }
/// Print a search result to the console. /// Print a search result to the console.
fn print_entry(entry: &DirEntry, path_str: &str, config: &FdOptions) { fn print_entry(entry: &DirEntry, path_rel: &Path, config: &FdOptions) {
let path_str = match path_rel.to_str() {
Some(p) => p,
None => return
};
if config.colored { if config.colored {
let style = match entry { let style = match entry {
e if e.path_is_symbolic_link() => Colour::Purple, e if e.path_is_symbolic_link() => Colour::Purple,
@ -65,20 +70,18 @@ fn scan(root: &Path, pattern: &Regex, config: &FdOptions) {
Err(_) => continue Err(_) => continue
}; };
if let Some(path_str) = path_rel.to_str() { let search_str =
let res = if config.search_full_path {
if config.search_full_path { path_rel.to_str()
pattern.find(path_str) } else {
} else { if !path_rel.is_file() { continue }
if !path_rel.is_file() { continue }
path_rel.file_name() path_rel.file_name()
.and_then(OsStr::to_str) .and_then(OsStr::to_str)
.and_then(|s| pattern.find(s)) };
};
res.map(|_| print_entry(&entry, path_str, &config)); search_str.and_then(|s| pattern.find(s))
} .map(|_| print_entry(&entry, path_rel, &config));
} }
} }