From: Simon Tatham Date: Mon, 1 Jan 2024 10:23:16 +0000 (+0000) Subject: Start of an actual Examine User display. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=b75610ce78b68d0151d06dd1c664df9766374f8f;p=mastodonochrome.git Start of an actual Examine User display. Doesn't contain most of the information yet, but we have the Account struct in hand and can start filling it in. --- diff --git a/src/file.rs b/src/file.rs index cf38202..c9794d7 100644 --- a/src/file.rs +++ b/src/file.rs @@ -63,11 +63,17 @@ impl FileDataSource for FeedSource { fn extendable(&self) -> bool { true } } -struct SingletonSource {} +struct SingletonSource { + id: String, +} + +impl SingletonSource { + fn new(id: String) -> Self { SingletonSource { id } } +} impl FileDataSource for SingletonSource { fn get(&self, _client: &mut Client) -> (Vec, isize) { - (vec! { "".to_owned() }, 0) + (vec! { self.id.clone() }, 0) } fn init(&self, _client: &mut Client) -> Result<(), ClientError> { Ok(()) } fn try_extend(&self, _client: &mut Client) -> Result { @@ -122,17 +128,6 @@ impl FileType for EgoNotificationFeedType { } } -struct ExamineUserFileType {} -impl FileType for ExamineUserFileType { - type Item = EditorHeaderSeparator; // FIXME - - fn get_from_client(_id: &str, _client: &mut Client) -> - Result - { - Ok(EditorHeaderSeparator::new()) - } -} - struct FileContents { source: Source, header: FileHeader, @@ -628,10 +623,27 @@ pub fn ego_log(client: &mut Client) -> Ok(Box::new(file)) } +struct ExamineUserFileType {} +impl FileType for ExamineUserFileType { + type Item = ExamineUserDisplay; + + fn get_from_client(id: &str, client: &mut Client) -> + Result + { + let ac = client.account_by_id(id)?; + Ok(ExamineUserDisplay::new(ac, client)?) + } +} + pub fn examine_user(client: &mut Client, account_id: &str) -> Result, ClientError> { + let ac = client.account_by_id(account_id)?; + let username = client.fq(&ac.acct); + let title = ColouredString::uniform( + &format!("Information about user {username}"), 'H'); + let file = File::::new( - client, SingletonSource{}, ColouredString::uniform(account_id, '!'))?; + client, SingletonSource::new(ac.id), title)?; Ok(Box::new(file)) } diff --git a/src/text.rs b/src/text.rs index a6084b7..d5ca242 100644 --- a/src/text.rs +++ b/src/text.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use unicode_width::UnicodeWidthStr; use super::html; -use super::client::Client; +use super::client::{Client, ClientError}; use super::types::*; use super::tui::OurKey; use super::coloured_string::{ColouredString, ColouredStringSlice}; @@ -1465,3 +1465,29 @@ impl TextFragment for StatusDisplay { lines } } + +pub struct ExamineUserDisplay { + name: Paragraph, +} + +impl ExamineUserDisplay { + pub fn new(ac: Account, client: &mut Client) -> Result { + let name = Paragraph::new() + .add(&ColouredString::plain("Account name: ")) + .add(&ColouredString::uniform(&client.fq(&ac.acct), 'f')); + + Ok(ExamineUserDisplay { + name, + }) + } +} + +impl TextFragment for ExamineUserDisplay { + fn render(&self, width: usize) -> Vec { + let mut lines = Vec::new(); + + push_fragment(&mut lines, self.name.render(width)); + + lines + } +}