remove redundent edits

This commit is contained in:
dvvvvvv 2020-02-04 13:49:04 +09:00 committed by Abin Simon
parent 3141278c65
commit 08133b4ebb
4 changed files with 33 additions and 42 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -13,13 +13,36 @@ pub enum DisplayOption<'a> {
#[derive(Clone, Debug, Eq)]
pub struct Name {
pub name: String,
path: PathBuf,
extension: Option<String>,
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<Ordering> {
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())
}
}