From 08133b4ebbfd8518a5091465834669350f5f22e4 Mon Sep 17 00:00:00 2001 From: dvvvvvv Date: Tue, 4 Feb 2020 13:49:04 +0900 Subject: [PATCH] remove redundent edits --- src/core.rs | 7 +----- src/display.rs | 2 +- src/meta/mod.rs | 7 +++--- src/meta/name.rs | 59 +++++++++++++++++++++++------------------------- 4 files changed, 33 insertions(+), 42 deletions(-) diff --git a/src/core.rs b/src/core.rs index b5ab63b..16aaf8f 100644 --- a/src/core.rs +++ b/src/core.rs @@ -95,12 +95,7 @@ impl Core { meta_list.push(meta); } _ => { - match meta.recurse_into( - base_path, - depth, - self.flags.display, - &self.flags.ignore_globs, - ) { + match meta.recurse_into(depth, self.flags.display, &self.flags.ignore_globs) { Ok(content) => { meta.content = content; meta_list.push(meta); diff --git a/src/display.rs b/src/display.rs index 27d30a3..10d75e3 100644 --- a/src/display.rs +++ b/src/display.rs @@ -68,7 +68,7 @@ fn inner_display_grid( let skip_dirs = (depth == 0) && (flags.display != Display::DisplayDirectoryItself); // print the files first. - for meta in metas.iter() { + for meta in metas { // Maybe skip showing the directory meta now; show its contents later. if let (true, FileType::Directory { .. }) = (skip_dirs, meta.file_type) { continue; diff --git a/src/meta/mod.rs b/src/meta/mod.rs index d96d45a..b02e491 100644 --- a/src/meta/mod.rs +++ b/src/meta/mod.rs @@ -49,7 +49,6 @@ pub struct Meta { impl Meta { pub fn recurse_into( &self, - base_path: &Path, depth: usize, display: Display, ignore_globs: &GlobSet, @@ -88,10 +87,10 @@ impl Meta { }; current_meta = self.clone(); - current_meta.name.display_name = ".".to_owned(); + current_meta.name.name = ".".to_owned(); parent_meta = Self::from_path(&parent_path)?; - parent_meta.name.display_name = "..".to_owned(); + parent_meta.name.name = "..".to_owned(); content.push(current_meta); content.push(parent_meta); @@ -122,7 +121,7 @@ impl Meta { } }; - match entry_meta.recurse_into(base_path, depth - 1, display, ignore_globs) { + match entry_meta.recurse_into(depth - 1, display, ignore_globs) { Ok(content) => entry_meta.content = content, Err(err) => { print_error!("lsd: {}: {}\n", path.display(), err); diff --git a/src/meta/name.rs b/src/meta/name.rs index 080c9c6..7d70532 100644 --- a/src/meta/name.rs +++ b/src/meta/name.rs @@ -13,13 +13,36 @@ pub enum DisplayOption<'a> { #[derive(Clone, Debug, Eq)] pub struct Name { + pub name: String, path: PathBuf, extension: Option, - pub display_name: String, file_type: FileType, } impl Name { + pub fn new(path: &Path, file_type: FileType) -> Self { + let name = match path.file_name() { + Some(name) => name.to_string_lossy().to_string(), + None => path.to_string_lossy().to_string(), + }; + + let mut extension = None; + if let Some(res) = path.extension() { + extension = Some( + res.to_str() + .expect("failed to encode file name") + .to_string(), + ); + } + + Self { + name, + path: PathBuf::from(path), + extension, + file_type, + } + } + pub fn file_name(&self) -> &str { self.path.file_name().and_then(OsStr::to_str).unwrap() } @@ -63,28 +86,6 @@ impl Name { .collect() } - pub fn new(path: &Path, file_type: FileType) -> Self { - let mut extension = None; - if let Some(res) = path.extension() { - extension = Some( - res.to_str() - .expect("failed to encode file name") - .to_string(), - ); - } - - Self { - path: PathBuf::from(path), - extension, - display_name: path - .file_name() - .and_then(OsStr::to_str) - .unwrap_or("?") - .to_owned(), - file_type, - } - } - pub fn render( &self, colors: &Colors, @@ -125,25 +126,21 @@ impl Name { impl Ord for Name { fn cmp(&self, other: &Self) -> Ordering { - self.display_name - .to_lowercase() - .cmp(&other.display_name.to_lowercase()) + self.name.to_lowercase().cmp(&other.name.to_lowercase()) } } impl PartialOrd for Name { fn partial_cmp(&self, other: &Self) -> Option { - self.display_name + self.name .to_lowercase() - .partial_cmp(&other.display_name.to_lowercase()) + .partial_cmp(&other.name.to_lowercase()) } } impl PartialEq for Name { fn eq(&self, other: &Self) -> bool { - self.display_name - .to_lowercase() - .eq(&other.display_name.to_lowercase()) + self.name.eq_ignore_ascii_case(&other.name.to_lowercase()) } }