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

This commit is contained in:
sbatial 2023-10-02 20:57:29 +02:00
parent 43dd047c56
commit 404faa64bf
3 changed files with 4 additions and 13 deletions

View file

@ -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()
}

View file

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

View file

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