chiark / gitweb /
UserListEntry, which was easy
authorSimon Tatham <anakin@pobox.com>
Tue, 26 Dec 2023 09:01:17 +0000 (09:01 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 26 Dec 2023 09:01:17 +0000 (09:01 +0000)
src/text.rs

index 3544315f48a2887678404edf3da44ac53e2b9a94..9e2dd93c4856cd487fe4e646e2d361bfa8daf1b3 100644 (file)
@@ -949,8 +949,36 @@ fn test_notification_log() {
         });
 }
 
+pub struct UserListEntry {
+    account_desc: String,
+}
+
+pub fn user_list_entry(account: &str, nameline: &str)
+    -> Box<dyn TextFragment> {
+    Box::new(UserListEntry {
+            account_desc: format!("{} ({})", nameline, account),
+        })
+}
+
+impl TextFragment for UserListEntry {
+    fn render(&self, width: usize) -> Vec<ColouredString> {
+        let mut para = Paragraph::new().set_indent(0, 2);
+        // FIXME: highlight account_desc if active
+        para.push_text(
+            &ColouredString::uniform(&self.account_desc, ' '), false);
+        para.render(width)
+    }
+}
+
+#[test]
+fn test_user_list_entry() {
+    assert_eq!(user_list_entry("foo@example.com", "Foo Bar").render(80), vec! {
+            ColouredString::general("Foo Bar (foo@example.com)",
+                                    "                         "),
+        });
+}
+
 // TODO:
-// UserListEntry
 // Media
 // FileStatusLine, with priorities
 // MenuKeypressLine