diff options
author | Ben S <ogham@bsago.me> | 2015-05-09 16:10:26 +0100 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-05-09 16:10:26 +0100 |
commit | da49b80c3525db7f0a0aae0fe2ac3e0a9a574cd3 (patch) | |
tree | 8d7b562460bc7c692a81511b2da4e67c12b7d00c /src/file.rs | |
parent | 662aed302a8894d751bdbd437cf439ef5c9a66ce (diff) |
Clean up filetype-detecting code
Diffstat (limited to 'src/file.rs')
-rw-r--r-- | src/file.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/file.rs b/src/file.rs index 4069a73..bae78f6 100644 --- a/src/file.rs +++ b/src/file.rs @@ -25,7 +25,7 @@ use datetime::format::{DateFormat}; use column::{Column, Cell}; use column::Column::*; use dir::Dir; -use filetype::HasType; +use filetype::file_type; use options::{SizeFormat, TimeType}; use output::details::UserLocale; use feature::Attribute; @@ -112,12 +112,6 @@ impl<'a> File<'a> { self.name.starts_with(".") } - /// Whether this file is a temporary file or not. - pub fn is_tmpfile(&self) -> bool { - let name = &self.name; - name.ends_with("~") || (name.starts_with("#") && name.ends_with("#")) - } - /// Get the data for a column, formatted as a coloured string. pub fn display<U: Users>(&self, column: &Column, users_cache: &mut U, locale: &UserLocale) -> Cell { match *column { @@ -207,7 +201,7 @@ impl<'a> File<'a> { /// The `ansi_term::Style` that this file's name should be painted. pub fn file_colour(&self) -> Style { - self.get_type().style() + file_type(&self).style() } /// The Unicode 'display width' of the filename. @@ -472,6 +466,17 @@ impl<'a> File<'a> { } } + pub fn extension_is_one_of(&self, choices: &[&str]) -> bool { + match self.ext { + Some(ref ext) => choices.contains(&&ext[..]), + None => false, + } + } + + pub fn name_is_one_of(&self, choices: &[&str]) -> bool { + choices.contains(&&self.name[..]) + } + fn git_status(&self) -> Cell { let status = match self.dir { None => GREY.paint("--").to_string(), |