mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-13 13:42:34 +00:00
use existing display and layout
This commit is contained in:
parent
42c3c8ca62
commit
1cdef5fe96
4 changed files with 23 additions and 34 deletions
|
@ -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
|
||||
|
|
31
src/core.rs
31
src/core.rs
|
@ -94,22 +94,21 @@ impl Core {
|
|||
}
|
||||
};
|
||||
|
||||
match self.flags.display {
|
||||
Display::DirectoryItself => {
|
||||
meta_list.push(meta);
|
||||
}
|
||||
_ => {
|
||||
match meta.recurse_into(depth, &self.flags) {
|
||||
Ok(content) => {
|
||||
meta.content = content;
|
||||
meta_list.push(meta);
|
||||
}
|
||||
Err(err) => {
|
||||
print_error!("lsd: {}: {}\n", path.display(), err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
}
|
||||
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;
|
||||
meta_list.push(meta);
|
||||
}
|
||||
Err(err) => {
|
||||
print_error!("lsd: {}: {}\n", path.display(), err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
meta_list.push(meta);
|
||||
};
|
||||
}
|
||||
if self.flags.total_size.0 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
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()));
|
||||
|
|
|
@ -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,9 +118,11 @@ impl Meta {
|
|||
};
|
||||
|
||||
// skip files for --tree -d
|
||||
if let Display::TreeD = flags.display {
|
||||
if !entry.file_type()?.is_dir() {
|
||||
continue;
|
||||
if flags.layout == Layout::Tree {
|
||||
if let Display::DirectoryItself = flags.display {
|
||||
if !entry.file_type()?.is_dir() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue