From: Simon Tatham Date: Tue, 26 Dec 2023 09:01:17 +0000 (+0000) Subject: UserListEntry, which was easy X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=36ead622bfbfbf7a355a45a9ae74eefa026322a8;p=mastodonochrome.git UserListEntry, which was easy --- diff --git a/src/text.rs b/src/text.rs index 3544315..9e2dd93 100644 --- a/src/text.rs +++ b/src/text.rs @@ -949,8 +949,36 @@ fn test_notification_log() { }); } +pub struct UserListEntry { + account_desc: String, +} + +pub fn user_list_entry(account: &str, nameline: &str) + -> Box { + Box::new(UserListEntry { + account_desc: format!("{} ({})", nameline, account), + }) +} + +impl TextFragment for UserListEntry { + fn render(&self, width: usize) -> Vec { + 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