diff options
Diffstat (limited to 'src/output/file_name.rs')
-rw-r--r-- | src/output/file_name.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/output/file_name.rs b/src/output/file_name.rs index ff61035..bcd4b47 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -18,7 +18,7 @@ pub struct Options { pub classify: Classify, /// Whether to prepend icon characters before file names. - pub icons: bool, + pub show_icons: ShowIcons, } impl Options { @@ -72,6 +72,19 @@ impl Default for Classify { } +/// Whether and how to show icons. +#[derive(PartialEq, Debug, Copy, Clone)] +pub enum ShowIcons { + + /// Don’t show icons at all. + Off, + + /// Show icons next to file names, with the given number of spaces between + /// the icon and the file name. + On(u32), +} + + /// A **file name** holds all the information necessary to display the name /// of the given file. This is used in all of the views. pub struct FileName<'a, 'dir, C> { @@ -112,12 +125,17 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> { pub fn paint(&self) -> TextCellContents { let mut bits = Vec::new(); - if self.options.icons { + if let ShowIcons::On(spaces_count) = self.options.show_icons { let style = iconify_style(self.style()); let file_icon = icon_for_file(self.file).to_string(); bits.push(style.paint(file_icon)); - bits.push(Style::default().paint(" ")); + + match spaces_count { + 1 => bits.push(Style::default().paint(" ")), + 2 => bits.push(Style::default().paint(" ")), + n => bits.push(Style::default().paint(spaces(n))), + } } if self.file.parent_dir.is_none() { @@ -152,7 +170,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> { if ! target.name.is_empty() { let target_options = Options { classify: Classify::JustFilenames, - icons: false, + show_icons: ShowIcons::Off, }; let target = FileName { @@ -320,3 +338,9 @@ 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).into_iter().map(|_| ' ').collect() +} |