From: Simon Tatham Date: Thu, 4 Jan 2024 20:11:26 +0000 (+0000) Subject: Highlight media of a status as well as text. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=52d36fca9d1f26a8c3715b285de8a0a7056019e2;p=mastodonochrome.git Highlight media of a status as well as text. If the status has _only_ media, this will be important! --- diff --git a/src/text.rs b/src/text.rs index 1504386..e268752 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1730,6 +1730,10 @@ impl StatusDisplay { fn push_fragment(lines: &mut Vec, frag: Vec) { lines.extend(frag.iter().map(|line| line.to_owned())); } +fn push_fragment_highlighted(lines: &mut Vec, + frag: Vec) { + lines.extend(frag.iter().map(|line| line.recolour('*'))); +} impl TextFragment for StatusDisplay { fn render_highlighted(&self, width: usize, highlight: Option) @@ -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