diff options
author | _ <a@b.co> | 2020-11-06 18:32:29 +0530 |
---|---|---|
committer | _ <a@b.co> | 2020-11-08 19:48:24 +0530 |
commit | 8b43d85d07d5f86bbaa896f74baa3f43fcb4c460 (patch) | |
tree | fca68e4bdf6681dcccd74fabc894175211089ee1 /src/tree | |
parent | e47ce676b0fe285f782d3a5282b8658b9b3568e5 (diff) |
Add support for icons
Diffstat (limited to 'src/tree')
-rw-r--r-- | src/tree/tree_line.rs | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/tree/tree_line.rs b/src/tree/tree_line.rs index 906f891..e30cf4d 100644 --- a/src/tree/tree_line.rs +++ b/src/tree/tree_line.rs @@ -1,6 +1,7 @@ use { super::*, crate::{ + app::AppContext, app::{Selection, SelectionType}, file_sum::FileSum, git::LineGitStatus, @@ -38,9 +39,42 @@ pub struct TreeLine { } impl TreeLine { - pub fn make_displayable_name(name: &str) -> String { - name.replace('\n', "") + pub fn make_displayable_name( + name: &str, + path: &std::path::PathBuf, + tree_line_type: &TreeLineType, + con: &AppContext, + + ) -> String { + let newline_replaced_name = name.replace('\n', ""); + + match &con.icon_plugin + { + None => newline_replaced_name, + Some( icon_plugin ) => + { + let extension = Self::extension_from_name( name ); + let icon = &icon_plugin.get_icon( + tree_line_type, + path, + &name, + Some( "" ), + extension, + ); + + String::with_capacity( name.len() + 2 ) + + &icon.to_string() + " " + &newline_replaced_name + } + } + } + + pub fn extension_from_name( name: &str ) -> Option<&str> { + regex!(r"\.([^.]+)$") + .captures(&name) + .and_then(|c| c.get(1)) + .map(|e| e.as_str()) } + pub fn is_selectable(&self) -> bool { !matches!(&self.line_type, TreeLineType::Pruning) } @@ -62,10 +96,7 @@ impl TreeLine { } } pub fn extension(&self) -> Option<&str> { - regex!(r"\.([^.]+)$") - .captures(&self.name) - .and_then(|c| c.get(1)) - .map(|e| e.as_str()) + Self::extension_from_name( &self.name ) } pub fn selection_type(&self) -> SelectionType { use TreeLineType::*; |