From 404faa64bfc60b9e0696a3ec4b298253569484ad Mon Sep 17 00:00:00 2001 From: sbatial Date: Mon, 2 Oct 2023 20:57:29 +0200 Subject: [PATCH] refactor(file): do not match for numbers and remove single-use fn --- src/output/file_name.rs | 13 ++----------- src/output/grid.rs | 2 +- src/output/grid_details.rs | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/output/file_name.rs b/src/output/file_name.rs index b5ffe461..23220757 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -101,7 +101,7 @@ pub enum ShowIcons { /// Show icons next to file names, with the given number of spaces between /// the icon and the file name. - On(u32), + On(usize), } /// Whether to embed hyperlinks. @@ -182,11 +182,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> { bits.push(style.paint(file_icon)); - match spaces_count { - 1 => bits.push(style.paint(" ")), - 2 => bits.push(style.paint(" ")), - n => bits.push(style.paint(spaces(n))), - } + bits.push(style.paint(" ".repeat(spaces_count))); } if self.file.parent_dir.is_none() { @@ -475,8 +471,3 @@ pub trait Colours: FiletypeColours { fn colour_file(&self, file: &File<'_>) -> Style; } - -/// Generate a string made of `n` spaces. -fn spaces(width: u32) -> String { - (0..width).map(|_| ' ').collect() -} diff --git a/src/output/grid.rs b/src/output/grid.rs index 21d513e1..d84d1ec2 100644 --- a/src/output/grid.rs +++ b/src/output/grid.rs @@ -47,7 +47,7 @@ impl<'a> Render<'a> { let contents = filename.paint(); #[rustfmt::skip] let width = match (filename.options.embed_hyperlinks, filename.options.show_icons) { - (EmbedHyperlinks::On, ShowIcons::On(spacing)) => filename.bare_width() + 1 + (spacing as usize), + (EmbedHyperlinks::On, ShowIcons::On(spacing)) => filename.bare_width() + 1 + spacing, (EmbedHyperlinks::On, ShowIcons::Off) => filename.bare_width(), (EmbedHyperlinks::Off, _) => *contents.width(), }; diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index f73ca724..a666eeaa 100644 --- a/src/output/grid_details.rs +++ b/src/output/grid_details.rs @@ -164,7 +164,7 @@ impl<'a> Render<'a> { let contents = filename.paint(); #[rustfmt::skip] let width = match (filename.options.embed_hyperlinks, filename.options.show_icons) { - (EmbedHyperlinks::On, ShowIcons::On(spacing)) => filename.bare_width() + 1 + (spacing as usize), + (EmbedHyperlinks::On, ShowIcons::On(spacing)) => filename.bare_width() + 1 + spacing, (EmbedHyperlinks::On, ShowIcons::Off) => filename.bare_width(), (EmbedHyperlinks::Off, _) => *contents.width(), };