From: Simon Tatham Date: Fri, 5 Jan 2024 09:50:03 +0000 (+0000) Subject: Support highlighting the user name in a UserListEntry. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=5ea817105d5cd7561577a18d9530f0055f6b38ca;p=mastodonochrome.git Support highlighting the user name in a UserListEntry. So you can look at a list of followers/favers/boosters and go to Examine User from there. --- diff --git a/src/text.rs b/src/text.rs index 0c3976b..e2b9b96 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1161,31 +1161,54 @@ fn test_notification_log() { pub struct UserListEntry { account_desc: String, + account_id: String, } impl UserListEntry { - pub fn new(account: &str, nameline: &str) - -> Self { + pub fn new(account: &str, nameline: &str, account_id: &str) -> Self { UserListEntry { account_desc: format!("{} ({})", nameline, account), + account_id: account_id.to_owned(), } } pub fn from_account(ac: &Account, client: &mut Client) -> Self { - Self::new(&client.fq(&ac.acct), &ac.display_name) + Self::new(&client.fq(&ac.acct), &ac.display_name, &ac.id) } } impl TextFragment for UserListEntry { - fn render_highlighted(&self, width: usize, _highlight: Option) + fn render_highlighted(&self, width: usize, highlight: Option) -> Vec { let mut para = Paragraph::new().set_indent(0, 2); - // FIXME: highlight account_desc if active + let colour = match highlight { + Some(Highlight(HighlightType::User, 0)) => '*', + _ => ' ', + }; para.push_text( - &ColouredString::uniform(&self.account_desc, ' '), false); + &ColouredString::uniform(&self.account_desc, colour), false); para.render(width) } + + fn can_highlight(htype: HighlightType) -> bool where Self : Sized { + htype == HighlightType::User + } + + fn count_highlightables(&self, htype: HighlightType) -> usize { + match htype { + HighlightType::User => 1, + _ => 0, + } + } + + fn highlighted_id(&self, highlight: Option) -> Option { + match highlight { + Some(Highlight(HighlightType::User, 0)) => + Some(self.account_id.clone()), + _ => None, + } + } } #[test]