summaryrefslogtreecommitdiffstats
path: root/src/tree
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-11-17 15:51:14 +0100
committerCanop <cano.petrole@gmail.com>2020-11-17 15:51:14 +0100
commit3128dacc5c2066392a53f91718a7db438706b4c2 (patch)
tree6eb39e9f9fea6202e416fccdb7b782cff85505b9 /src/tree
parent75e76656a55209efc627c9f8bf3840b56e75d794 (diff)
parent36f4c05a3162f747d45d7edd0664cf954cfcab32 (diff)
Merge branch 'icon' of https://github.com/asdf8dfafjk/broot into icons
Diffstat (limited to 'src/tree')
-rw-r--r--src/tree/tree_line.rs52
1 files changed, 46 insertions, 6 deletions
diff --git a/src/tree/tree_line.rs b/src/tree/tree_line.rs
index 906f891..3e9d361 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,51 @@ 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 double_extension = Self::double_extension_from_name( name );
+
+ let icon = &icon_plugin.get_icon(
+ tree_line_type,
+ path,
+ &name,
+ double_extension,
+ extension,
+ );
+
+ String::with_capacity( name.len() + 2 )
+ + &icon.to_string() + " " + &newline_replaced_name
+ }
+ }
+ }
+
+ pub fn double_extension_from_name( name: &str ) -> Option<&str> {
+ regex!( r"\.([^.]+\.[^.]+)" )
+ .captures(&name)
+ .and_then(|c| c.get(1))
+ .map(|e| e.as_str())
}
+
+ 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 +105,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::*;