chiark / gitweb /
Support highlighting the user name in a UserListEntry.
authorSimon Tatham <anakin@pobox.com>
Fri, 5 Jan 2024 09:50:03 +0000 (09:50 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 5 Jan 2024 09:57:51 +0000 (09:57 +0000)
So you can look at a list of followers/favers/boosters and go to
Examine User from there.

src/text.rs

index 0c3976b95861e1e3294ef07b5a3e31a4599f7dfc..e2b9b96997c8335726a36efb3cc89b0f849d1786 100644 (file)
@@ -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<Highlight>)
+    fn render_highlighted(&self, width: usize, highlight: Option<Highlight>)
                           -> Vec<ColouredString>
     {
         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<Highlight>) -> Option<String> {
+        match highlight {
+            Some(Highlight(HighlightType::User, 0)) =>
+                Some(self.account_id.clone()),
+            _ => None,
+        }
+    }
 }
 
 #[test]