chiark / gitweb /
Highlight media of a status as well as text.
authorSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 20:11:26 +0000 (20:11 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 20:11:26 +0000 (20:11 +0000)
If the status has _only_ media, this will be important!

src/text.rs

index 150438615a922f4799265842cfe9d3cdd9d7888a..e268752af60bbb09f03bc60124993e1dba7e0f21 100644 (file)
@@ -1730,6 +1730,10 @@ impl StatusDisplay {
 fn push_fragment(lines: &mut Vec<ColouredString>, frag: Vec<ColouredString>) {
     lines.extend(frag.iter().map(|line| line.to_owned()));
 }
+fn push_fragment_highlighted(lines: &mut Vec<ColouredString>,
+                             frag: Vec<ColouredString>) {
+    lines.extend(frag.iter().map(|line| line.recolour('*')));
+}
 
 impl TextFragment for StatusDisplay {
     fn render_highlighted(&self, width: usize, highlight: Option<Highlight>)
@@ -1738,6 +1742,15 @@ impl TextFragment for StatusDisplay {
         let mut lines = Vec::new();
         let mut highlight = highlight;
 
+        let highlighting_this_status =
+            highlight.consume(HighlightType::Status, 1) == Some(0) ||
+            highlight.consume(HighlightType::WholeStatus, 1) == Some(0);
+        let push_fragment_opt_highlight = if highlighting_this_status {
+            push_fragment_highlighted
+        } else {
+            push_fragment
+        };
+
         push_fragment(&mut lines, self.sep.render(width));
         push_fragment(&mut lines, self.from.render_highlighted_update(
             width, &mut highlight));
@@ -1745,21 +1758,15 @@ impl TextFragment for StatusDisplay {
             width, &mut highlight));
         push_fragment(&mut lines, self.irt.render(width));
         push_fragment(&mut lines, self.blank.render(width));
-        let mut rendered_content = self.content.render(width);
-        if highlight.consume(HighlightType::Status, 1) == Some(0) ||
-            highlight.consume(HighlightType::WholeStatus, 1) == Some(0)
-        {
-            rendered_content = rendered_content.iter()
-                .map(|s| s.recolour('*')).collect();
-        }
+        let rendered_content = self.content.render(width);
         let content_empty = rendered_content.len() == 0;
-        push_fragment(&mut lines, rendered_content);
+        push_fragment_opt_highlight(&mut lines, rendered_content);
         if !content_empty {
             push_fragment(&mut lines, self.blank.render(width));
         }
         for m in &self.media {
-            push_fragment(&mut lines, m.render(width));
-            push_fragment(&mut lines, self.blank.render(width));
+            push_fragment_opt_highlight(&mut lines, m.render(width));
+            push_fragment_opt_highlight(&mut lines, self.blank.render(width));
         }
 
         lines