use existing display and layout

This commit is contained in:
AJ ONeal 2020-12-10 23:37:06 -07:00 committed by Abin Simon
parent 42c3c8ca62
commit 1cdef5fe96
4 changed files with 23 additions and 34 deletions

View file

@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for `--extensionsort` `-X` from [aldhsu](https://github.com/aldhsu)
- Add support for `--versionsort` `-v` from [zwpaper](https://github.com/zwpaper)
- Add support for config symlink arrow from [zwpaper](https://github.com/zwpaper) [#409](https://github.com/Peltoche/lsd/issues/409)
- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt)
- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt) and [Utah Rust](https://github.com/utah-rust)
### Changed
- Use last sort flag for sort field from [meain](https://github.com/meain)
### Fixed

View file

@ -94,11 +94,9 @@ impl Core {
}
};
match self.flags.display {
Display::DirectoryItself => {
meta_list.push(meta);
}
_ => {
let recurse =
self.flags.layout == Layout::Tree || self.flags.display != Display::DirectoryItself;
if recurse {
match meta.recurse_into(depth, &self.flags) {
Ok(content) => {
meta.content = content;
@ -109,7 +107,8 @@ impl Core {
continue;
}
};
}
} else {
meta_list.push(meta);
};
}
if self.flags.total_size.0 {

View file

@ -15,7 +15,6 @@ pub enum Display {
AlmostAll,
DirectoryItself,
DisplayOnlyVisible,
TreeD,
}
impl Display {
@ -46,11 +45,7 @@ impl Configurable<Self> for Display {
} else if matches.is_present("almost-all") {
Some(Self::AlmostAll)
} else if matches.is_present("directory-only") {
if matches.is_present("tree") {
Some(Self::TreeD)
} else {
Some(Self::DirectoryItself)
}
} else {
None
}
@ -128,13 +123,6 @@ mod test {
);
}
#[test]
fn test_from_arg_matches_display_only_directories() {
let argv = vec!["lsd", "--tree", "-d"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
assert_eq!(Some(Display::TreeD), Display::from_arg_matches(&matches));
}
#[test]
fn test_from_config_none() {
assert_eq!(None, Display::from_config(&Config::with_none()));

View file

@ -54,7 +54,7 @@ impl Meta {
return Ok(None);
}
if flags.display == Display::DirectoryItself {
if flags.display == Display::DirectoryItself && flags.layout != Layout::Tree {
return Ok(None);
}
@ -118,11 +118,13 @@ impl Meta {
};
// skip files for --tree -d
if let Display::TreeD = flags.display {
if flags.layout == Layout::Tree {
if let Display::DirectoryItself = flags.display {
if !entry.file_type()?.is_dir() {
continue;
}
}
}
match entry_meta.recurse_into(depth - 1, &flags) {
Ok(content) => entry_meta.content = content,