فهرست منبع

refactor(file): do not match for numbers and remove single-use fn

sbatial 2 سال پیش
والد
کامیت
404faa64bf
3فایلهای تغییر یافته به همراه4 افزوده شده و 13 حذف شده
  1. 2 11
      src/output/file_name.rs
  2. 1 1
      src/output/grid.rs
  3. 1 1
      src/output/grid_details.rs

+ 2 - 11
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()
-}

+ 1 - 1
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(),
             };

+ 1 - 1
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(),
                 };