Fix Clippy lints

Update display.rs

Update color.rs

Update date.rs

Update date.rs

Update mod.rs

Update display.rs
This commit is contained in:
auronandace 2021-08-17 14:17:21 +01:00 committed by Wei Zh
parent 0246531e7f
commit 9bd7690af8
6 changed files with 37 additions and 40 deletions

View file

@ -134,9 +134,9 @@ impl Core {
fn display(&self, metas: &[Meta]) { fn display(&self, metas: &[Meta]) {
let output = if self.flags.layout == Layout::Tree { let output = if self.flags.layout == Layout::Tree {
display::tree(&metas, &self.flags, &self.colors, &self.icons) display::tree(metas, &self.flags, &self.colors, &self.icons)
} else { } else {
display::grid(&metas, &self.flags, &self.colors, &self.icons) display::grid(metas, &self.flags, &self.colors, &self.icons)
}; };
print_output!("{}", output); print_output!("{}", output);

View file

@ -15,15 +15,12 @@ const CORNER: &str = "\u{2514}\u{2500}\u{2500}"; // "└──"
const BLANK: &str = " "; const BLANK: &str = " ";
pub fn grid(metas: &[Meta], flags: &Flags, colors: &Colors, icons: &Icons) -> String { pub fn grid(metas: &[Meta], flags: &Flags, colors: &Colors, icons: &Icons) -> String {
let term_width = match terminal_size() { let term_width = terminal_size().map(|(w, _)| w.0 as usize);
Some((w, _)) => Some(w.0 as usize),
None => None,
};
inner_display_grid( inner_display_grid(
&DisplayOption::None, &DisplayOption::None,
metas, metas,
&flags, flags,
colors, colors,
icons, icons,
0, 0,
@ -37,7 +34,7 @@ pub fn tree(metas: &[Meta], flags: &Flags, colors: &Colors, icons: &Icons) -> St
direction: Direction::LeftToRight, direction: Direction::LeftToRight,
}); });
let padding_rules = get_padding_rules(&metas, flags); let padding_rules = get_padding_rules(metas, flags);
let mut index = 0; let mut index = 0;
for (i, block) in flags.blocks.0.iter().enumerate() { for (i, block) in flags.blocks.0.iter().enumerate() {
if let Block::Name = block { if let Block::Name = block {
@ -46,7 +43,7 @@ pub fn tree(metas: &[Meta], flags: &Flags, colors: &Colors, icons: &Icons) -> St
} }
} }
for cell in inner_display_tree(metas, &flags, colors, icons, (0, ""), &padding_rules, index) { for cell in inner_display_tree(metas, flags, colors, icons, (0, ""), &padding_rules, index) {
grid.add(cell); grid.add(cell);
} }
@ -64,7 +61,7 @@ fn inner_display_grid(
) -> String { ) -> String {
let mut output = String::new(); let mut output = String::new();
let padding_rules = get_padding_rules(&metas, flags); let padding_rules = get_padding_rules(metas, flags);
let mut grid = match flags.layout { let mut grid = match flags.layout {
Layout::OneLine => Grid::new(GridOptions { Layout::OneLine => Grid::new(GridOptions {
filling: Filling::Spaces(1), filling: Filling::Spaces(1),
@ -93,11 +90,11 @@ fn inner_display_grid(
} }
let blocks = get_output( let blocks = get_output(
&meta, meta,
&colors, colors,
&icons, icons,
&flags, flags,
&display_option, display_option,
&padding_rules, &padding_rules,
(0, ""), (0, ""),
); );
@ -129,13 +126,13 @@ fn inner_display_grid(
output += &grid.fit_into_columns(flags.blocks.0.len()).to_string(); output += &grid.fit_into_columns(flags.blocks.0.len()).to_string();
} }
let should_display_folder_path = should_display_folder_path(depth, &metas, &flags); let should_display_folder_path = should_display_folder_path(depth, metas, flags);
// print the folder content // print the folder content
for meta in metas { for meta in metas {
if meta.content.is_some() { if meta.content.is_some() {
if should_display_folder_path { if should_display_folder_path {
output += &display_folder_path(&meta); output += &display_folder_path(meta);
} }
let display_option = DisplayOption::Relative { let display_option = DisplayOption::Relative {
@ -145,7 +142,7 @@ fn inner_display_grid(
output += &inner_display_grid( output += &inner_display_grid(
&display_option, &display_option,
meta.content.as_ref().unwrap(), meta.content.as_ref().unwrap(),
&flags, flags,
colors, colors,
icons, icons,
depth + 1, depth + 1,
@ -182,12 +179,12 @@ fn inner_display_tree(
}; };
for block in get_output( for block in get_output(
&meta, meta,
&colors, colors,
&icons, icons,
&flags, flags,
&DisplayOption::FileName, &DisplayOption::FileName,
&padding_rules, padding_rules,
(tree_index, &current_prefix), (tree_index, &current_prefix),
) { ) {
let block_str = block.to_string(); let block_str = block.to_string();
@ -211,8 +208,8 @@ fn inner_display_tree(
}; };
cells.extend(inner_display_tree( cells.extend(inner_display_tree(
&meta.content.as_ref().unwrap(), meta.content.as_ref().unwrap(),
&flags, flags,
colors, colors,
icons, icons,
(tree_depth_prefix.0 + 1, &new_prefix), (tree_depth_prefix.0 + 1, &new_prefix),
@ -287,17 +284,17 @@ fn get_output<'a>(
} else { } else {
Some(padding_rules[&Block::SizeValue]) Some(padding_rules[&Block::SizeValue])
}; };
block_vec.push(meta.size.render(colors, &flags, pad)) block_vec.push(meta.size.render(colors, flags, pad))
} }
Block::SizeValue => block_vec.push(meta.size.render_value(colors, flags)), Block::SizeValue => block_vec.push(meta.size.render_value(colors, flags)),
Block::Date => block_vec.push(meta.date.render(colors, &flags)), Block::Date => block_vec.push(meta.date.render(colors, flags)),
Block::Name => { Block::Name => {
block_vec.extend(vec![ block_vec.extend(vec![
meta.name.render(colors, icons, &display_option), meta.name.render(colors, icons, display_option),
meta.indicator.render(&flags), meta.indicator.render(flags),
]); ]);
if !(flags.no_symlink.0 || flags.dereference.0 || flags.layout == Layout::Grid) { if !(flags.no_symlink.0 || flags.dereference.0 || flags.layout == Layout::Grid) {
block_vec.push(meta.symlink.render(colors, &flags)) block_vec.push(meta.symlink.render(colors, flags))
} }
} }
}; };
@ -334,7 +331,7 @@ fn detect_size_lengths(metas: &[Meta], flags: &Flags) -> usize {
if Layout::Tree == flags.layout { if Layout::Tree == flags.layout {
if let Some(subs) = &meta.content { if let Some(subs) = &meta.content {
let sub_length = detect_size_lengths(&subs, flags); let sub_length = detect_size_lengths(subs, flags);
if sub_length > max_value_length { if sub_length > max_value_length {
max_value_length = sub_length; max_value_length = sub_length;
} }
@ -349,7 +346,7 @@ fn get_padding_rules(metas: &[Meta], flags: &Flags) -> HashMap<Block, usize> {
let mut padding_rules: HashMap<Block, usize> = HashMap::new(); let mut padding_rules: HashMap<Block, usize> = HashMap::new();
if flags.blocks.0.contains(&Block::Size) { if flags.blocks.0.contains(&Block::Size) {
let size_val = detect_size_lengths(&metas, &flags); let size_val = detect_size_lengths(metas, flags);
padding_rules.insert(Block::SizeValue, size_val); padding_rules.insert(Block::SizeValue, size_val);
} }

View file

@ -64,7 +64,7 @@ impl Configurable<Self> for ColorOption {
Some(Self::Never) Some(Self::Never)
} else if matches.occurrences_of("color") > 0 { } else if matches.occurrences_of("color") > 0 {
if let Some(color) = matches.values_of("color")?.last() { if let Some(color) = matches.values_of("color")?.last() {
Self::from_str(&color) Self::from_str(color)
} else { } else {
panic!("Bad color args. This should not be reachable!"); panic!("Bad color args. This should not be reachable!");
} }

View file

@ -21,7 +21,7 @@ pub enum DateFlag {
impl DateFlag { impl DateFlag {
/// Get a value from a date format string /// Get a value from a date format string
fn from_format_string(value: &str) -> Option<Self> { fn from_format_string(value: &str) -> Option<Self> {
match app::validate_time_format(&value) { match app::validate_time_format(value) {
Ok(()) => Some(Self::Formatted(value[1..].to_string())), Ok(()) => Some(Self::Formatted(value[1..].to_string())),
_ => { _ => {
print_error!("Not a valid date format: {}.", value); print_error!("Not a valid date format: {}.", value);
@ -35,7 +35,7 @@ impl DateFlag {
match value { match value {
"date" => Some(Self::Date), "date" => Some(Self::Date),
"relative" => Some(Self::Relative), "relative" => Some(Self::Relative),
_ if value.starts_with('+') => Self::from_format_string(&value), _ if value.starts_with('+') => Self::from_format_string(value),
_ => { _ => {
print_error!("Not a valid date value: {}.", value); print_error!("Not a valid date value: {}.", value);
None None
@ -79,7 +79,7 @@ impl Configurable<Self> for DateFlag {
} }
if let Some(date) = &config.date { if let Some(date) = &config.date {
Self::from_str(&date) Self::from_str(date)
} else { } else {
None None
} }

View file

@ -29,7 +29,7 @@ impl Date {
Elem::Older Elem::Older
}; };
colors.colorize(self.date_string(&flags), &elem) colors.colorize(self.date_string(flags), &elem)
} }
pub fn date_string(&self, flags: &Flags) -> String { pub fn date_string(&self, flags: &Flags) -> String {
@ -45,7 +45,7 @@ impl Date {
self.0.format("%F").to_string() self.0.format("%F").to_string()
} }
} }
DateFlag::Formatted(format) => self.0.format(&format).to_string(), DateFlag::Formatted(format) => self.0.format(format).to_string(),
} }
} }
} }

View file

@ -129,7 +129,7 @@ impl Meta {
} }
} }
match entry_meta.recurse_into(depth - 1, &flags) { match entry_meta.recurse_into(depth - 1, flags) {
Ok(content) => entry_meta.content = content, Ok(content) => entry_meta.content = content,
Err(err) => { Err(err) => {
print_error!("{}: {}.", path.display(), err); print_error!("{}: {}.", path.display(), err);
@ -228,7 +228,7 @@ impl Meta {
let (owner, permissions) = windows_utils::get_file_data(&path)?; let (owner, permissions) = windows_utils::get_file_data(&path)?;
let file_type = FileType::new(&metadata, symlink_meta.as_ref(), &permissions); let file_type = FileType::new(&metadata, symlink_meta.as_ref(), &permissions);
let name = Name::new(&path, file_type); let name = Name::new(path, file_type);
let inode = INode::from(&metadata); let inode = INode::from(&metadata);
let links = Links::from(&metadata); let links = Links::from(&metadata);