chiark / gitweb /
Start of an actual Examine User display.
authorSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 10:23:16 +0000 (10:23 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 10:23:16 +0000 (10:23 +0000)
Doesn't contain most of the information yet, but we have the Account
struct in hand and can start filling it in.

src/file.rs
src/text.rs

index cf38202f5a7a33cdd78f9eae9150baa4f2331f46..c9794d75155f7b5bd83c2cf2039eebe830db6293 100644 (file)
@@ -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<String>, 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<bool, ClientError> {
@@ -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<Self::Item, ClientError>
-    {
-        Ok(EditorHeaderSeparator::new())
-    }
-}
-
 struct FileContents<Type: FileType, Source: FileDataSource> {
     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<Self::Item, ClientError>
+    {
+        let ac = client.account_by_id(id)?;
+        Ok(ExamineUserDisplay::new(ac, client)?)
+    }
+}
+
 pub fn examine_user(client: &mut Client, account_id: &str) ->
     Result<Box<dyn ActivityState>, 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::<ExamineUserFileType, _>::new(
-        client, SingletonSource{}, ColouredString::uniform(account_id, '!'))?;
+        client, SingletonSource::new(ac.id), title)?;
     Ok(Box::new(file))
 }
index a6084b73da9e8521d7e636b5faa4fad026e3620c..d5ca2422d360772deac33a918b59180d8eaea08c 100644 (file)
@@ -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<Self, ClientError> {
+        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<ColouredString> {
+        let mut lines = Vec::new();
+
+        push_fragment(&mut lines, self.name.render(width));
+
+        lines
+    }
+}