added icons for video/audio/images

remove unnecessary clone
This commit is contained in:
Alex Soderman 2018-03-27 13:00:38 -04:00
parent fd553227f0
commit c448b3747f
2 changed files with 38 additions and 5 deletions

View File

@ -8,6 +8,7 @@ use ansi_term::Style;
use fs::File; use fs::File;
use output::file_name::FileColours; use output::file_name::FileColours;
use output::icons::FileIcon;
#[derive(Debug, Default, PartialEq)] #[derive(Debug, Default, PartialEq)]
@ -115,3 +116,16 @@ impl FileColours for FileExtensions {
}) })
} }
} }
impl FileIcon for FileExtensions {
fn icon_file(&self, file: &File) -> Option<char> {
use output::icons::Icons;
Some(match file {
f if self.is_music(f) || self.is_lossless(f) => Icons::Audio.value(),
f if self.is_image(f) => Icons::Image.value(),
f if self.is_video(f) => Icons::Video.value(),
_ => return None,
})
}
}

View File

@ -1,7 +1,28 @@
use ansi_term::Style; use ansi_term::Style;
use fs::File; use fs::File;
use info::filetype::FileExtensions;
use output::file_name::FileStyle; use output::file_name::FileStyle;
pub trait FileIcon {
fn icon_file(&self, file: &File) -> Option<char>;
}
pub enum Icons {
Audio,
Image,
Video,
}
impl Icons {
pub fn value(&self) -> char {
match *self {
Icons::Audio => '\u{f001}',
Icons::Image => '\u{f1c5}',
Icons::Video => '\u{f03d}',
}
}
}
pub fn painted_icon(file: &File, style: &FileStyle) -> String { pub fn painted_icon(file: &File, style: &FileStyle) -> String {
let file_icon = icon(&file).to_string(); let file_icon = icon(&file).to_string();
let painted = style.exts let painted = style.exts
@ -21,15 +42,15 @@ pub fn painted_icon(file: &File, style: &FileStyle) -> String {
} }
fn icon(file: &File) -> char { fn icon(file: &File) -> char {
let extensions = Box::new(FileExtensions);
if file.is_directory() { '\u{f115}' } if file.is_directory() { '\u{f115}' }
else if let Some(icon) = extensions.icon_file(file) { icon }
else { else {
// possible unnecessary clone if let Some(ext) = file.ext.as_ref() {
if let Some(ext) = file.ext.clone() {
match ext.as_str() { match ext.as_str() {
"ai" => '\u{e7b4}', "ai" => '\u{e7b4}',
"android" => '\u{e70e}', "android" => '\u{e70e}',
"apple" => '\u{f179}', "apple" => '\u{f179}',
"audio" => '\u{f001}',
"avro" => '\u{e60b}', "avro" => '\u{e60b}',
"c" => '\u{e61e}', "c" => '\u{e61e}',
"clj" => '\u{e768}', "clj" => '\u{e768}',
@ -52,7 +73,6 @@ fn icon(file: &File) -> char {
"go" => '\u{e626}', "go" => '\u{e626}',
"hs" => '\u{e777}', "hs" => '\u{e777}',
"html" => '\u{f13b}', "html" => '\u{f13b}',
"image" => '\u{f1c5}',
"iml" => '\u{e7b5}', "iml" => '\u{e7b5}',
"java" => '\u{e204}', "java" => '\u{e204}',
"js" => '\u{e74e}', "js" => '\u{e74e}',
@ -87,7 +107,6 @@ fn icon(file: &File) -> char {
"txt" => '\u{f15c}', "txt" => '\u{f15c}',
"video" => '\u{f03d}', "video" => '\u{f03d}',
"vim" => '\u{e62b}', "vim" => '\u{e62b}',
"windows" => '\u{f17a}',
"xls" => '\u{f1c3}', "xls" => '\u{f1c3}',
"xml" => '\u{e619}', "xml" => '\u{e619}',
"yml" => '\u{f481}', "yml" => '\u{f481}',