From c29170e34559e4d1f6731ed59975a6b9d068df71 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Mon, 10 Jul 2017 14:01:38 +0100 Subject: [PATCH] Get the list of file extensions from the Options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The FileExtensions in the FileName is now a reference to the one in the original FileStyle, which gets put there in the options module. This allows the extensions to be derived from the user, somehow, in the future when that part’s done. --- src/info/filetype.rs | 1 + src/options/view.rs | 4 +++- src/output/file_name.rs | 13 ++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/info/filetype.rs b/src/info/filetype.rs index 77a9654..608aff7 100644 --- a/src/info/filetype.rs +++ b/src/info/filetype.rs @@ -7,6 +7,7 @@ use fs::File; +#[derive(Debug)] pub struct FileExtensions; impl FileExtensions { diff --git a/src/options/view.rs b/src/options/view.rs index 24b8eec..03ae3f0 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -2,6 +2,7 @@ use std::env::var_os; use getopts; +use info::filetype::FileExtensions; use output::Colours; use output::{grid, details}; use output::table::{TimeTypes, Environment, SizeFormat, Options as TableOptions}; @@ -373,7 +374,8 @@ impl Colours { impl FileStyle { fn deduce(matches: &getopts::Matches) -> FileStyle { let classify = Classify::deduce(matches); - FileStyle { classify } + let exts = FileExtensions; + FileStyle { classify, exts } } } diff --git a/src/output/file_name.rs b/src/output/file_name.rs index 79628ee..bfb5b31 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -10,22 +10,25 @@ use output::cell::TextCellContents; /// Basically a file name factory. -#[derive(PartialEq, Debug)] +#[derive(Debug)] pub struct FileStyle { /// Whether to append file class characters to file names. pub classify: Classify, + + /// Mapping of file extensions to colours, to highlight regular files. + pub exts: FileExtensions, } impl FileStyle { /// Create a new `FileName` that prints the given file’s name, painting it /// with the remaining arguments. - pub fn for_file<'a, 'dir>(&self, file: &'a File<'dir>, colours: &'a Colours) -> FileName<'a, 'dir> { + pub fn for_file<'a, 'dir>(&'a self, file: &'a File<'dir>, colours: &'a Colours) -> FileName<'a, 'dir> { FileName { file, colours, - exts: FileExtensions, link_style: LinkStyle::JustFilenames, + exts: &self.exts, classify: self.classify, target: if file.is_link() { Some(file.link_target()) } else { None } @@ -90,7 +93,7 @@ pub struct FileName<'a, 'dir: 'a> { classify: Classify, /// Mapping of file extensions to colours, to highlight regular files. - exts: FileExtensions, + exts: &'a FileExtensions, } @@ -142,7 +145,7 @@ impl<'a, 'dir> FileName<'a, 'dir> { target: None, link_style: LinkStyle::FullLinkPaths, classify: Classify::JustFilenames, - exts: FileExtensions, + exts: self.exts, }; for bit in target.coloured_file_name() {