summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-05-07 17:18:59 +0200
committerCanop <cano.petrole@gmail.com>2021-05-07 17:18:59 +0200
commitccf6da2d2ed5e30355e2c9e3fd445f6297c9493b (patch)
tree6ca4c5145224a8d6c0be6fe95adaa5b205c2dc62 /src/display
parent8593028c16d899b5b69dec45ac860d252d18af66 (diff)
apply a different style to the subpath before the filename
This style is visible when searching on subpath
Diffstat (limited to 'src/display')
-rw-r--r--src/display/displayable_tree.rs40
-rw-r--r--src/display/matched_string.rs28
2 files changed, 56 insertions, 12 deletions
diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs
index 5834adc..ca8e9ab 100644
--- a/src/display/displayable_tree.rs
+++ b/src/display/displayable_tree.rs
@@ -285,19 +285,35 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
cw.queue_char(style, ' ')?;
cw.queue_char(style, ' ')?;
}
- let label = if pattern_object.subpath {
- &line.subpath
+ if pattern_object.subpath && line.unlisted == 0 {
+ let name_match = self.tree.options.pattern.pattern
+ .search_string(&line.subpath);
+ let mut path_ms = MatchedString::new(
+ name_match,
+ &line.subpath,
+ &style,
+ &char_match_style,
+ );
+ let name_ms = path_ms.split_on_last('/');
+ cond_bg!(parent_style, self, selected, self.skin.parent);
+ if name_ms.is_some() {
+ path_ms.base_style = &parent_style;
+ }
+ path_ms.queue_on(cw)?;
+ if let Some(name_ms) = name_ms {
+ name_ms.queue_on(cw)?;
+ }
} else {
- &line.name
- };
- let name_match = self.tree.options.pattern.pattern.search_string(label);
- let matched_string = MatchedString::new(
- name_match,
- label,
- &style,
- &char_match_style,
- );
- matched_string.queue_on(cw)?;
+ let name_match = self.tree.options.pattern.pattern
+ .search_string(&line.name);
+ let matched_string = MatchedString::new(
+ name_match,
+ &line.name,
+ &style,
+ &char_match_style,
+ );
+ matched_string.queue_on(cw)?;
+ }
match &line.line_type {
TreeLineType::Dir => {
if line.unlisted > 0 {
diff --git a/src/display/matched_string.rs b/src/display/matched_string.rs
index 68b4dc9..45becfb 100644
--- a/src/display/matched_string.rs
+++ b/src/display/matched_string.rs
@@ -30,6 +30,34 @@ impl<'a, 'w> MatchedString<'a> {
align: Alignment::Left,
}
}
+ /// If the string contains sep, then cut the tail of this matched
+ /// string and return it.
+ /// Note: a non none display_width currently prevents splitting
+ /// (i.e. it's not yet implemented and would involve compute width)
+ pub fn split_on_last(&mut self, sep: char) -> Option<Self> {
+ if self.display_width.is_some() {
+ // the proper algo would need measuring the left part I guess
+ None
+ } else {
+ self.string
+ .rfind(sep)
+ .map(|sep_idx| {
+ let right = &self.string[sep_idx+1..];
+ self.string = &self.string[..sep_idx+1];
+ let left_chars_count = self.string.chars().count();
+ let right_name_match = self.name_match.as_mut()
+ .map(|nm| nm.cut_after(left_chars_count));
+ MatchedString {
+ name_match: right_name_match,
+ string: right,
+ base_style: self.base_style,
+ match_style: self.match_style,
+ display_width: None,
+ align: self.align,
+ }
+ })
+ }
+ }
pub fn fill(&mut self, width: usize, align: Alignment) {
self.display_width = Some(width);
self.align = align;