use super::coloured_string::ColouredString;
pub trait TextFragment {
+ // FIXME: we will also need ...
+ // Some indication of how many usernames are in here and how many statuses
+ // Some means of passing a flag to render() that says which username or
+ // status is to be highlighted
fn render(&self, width: usize) -> Vec<ColouredString>;
}
pub struct BlankLine {}
-impl BlankLine {
- pub fn newbox() -> Box<dyn TextFragment> {
- Box::new(BlankLine{})
- }
+pub fn blank() -> Box<dyn TextFragment> {
+ Box::new(BlankLine{})
}
impl TextFragment for BlankLine {
boosted: bool,
}
-impl SeparatorLine {
- pub fn newbox(
- timestamp: Option<DateTime<Utc>>,
- favourited: bool,
- boosted: bool,
+pub fn separator(
+ timestamp: Option<DateTime<Utc>>,
+ favourited: bool,
+ boosted: bool,
) -> Box<dyn TextFragment> {
- Box::new(SeparatorLine {
+ Box::new(SeparatorLine {
timestamp,
favourited,
boosted,
})
- }
}
impl TextFragment for SeparatorLine {
pub struct EditorHeaderSeparator {}
-impl EditorHeaderSeparator {
- pub fn newbox() -> Box<dyn TextFragment> {
- Box::new(EditorHeaderSeparator{})
- }
+pub fn editorsep() -> Box<dyn TextFragment> {
+ Box::new(EditorHeaderSeparator{})
}
impl TextFragment for EditorHeaderSeparator {
}
}
+pub struct UsernameHeader {
+ header: String,
+ colour: char,
+ account: String,
+ nameline: String,
+}
+
+pub fn fromline(account: &str, nameline: &str) -> Box<dyn TextFragment> {
+ Box::new(UsernameHeader{
+ header: "From".to_string(),
+ colour: 'F',
+ account: account.to_string(),
+ nameline: nameline.to_string(),
+ })
+}
+
+pub fn boosterline(account: &str, nameline: &str) -> Box<dyn TextFragment> {
+ Box::new(UsernameHeader{
+ header: "Via".to_string(),
+ colour: 'f',
+ account: account.to_string(),
+ nameline: nameline.to_string(),
+ })
+}
+
+impl TextFragment for UsernameHeader {
+ fn render(&self, _width: usize) -> Vec<ColouredString> {
+ let header = ColouredString::plain(&format!("{}: ", self.header));
+ let body = ColouredString::uniform(
+ &format!("{} ({})", self.nameline, self.account), self.colour);
+ vec! {
+ header + body,
+ }
+ }
+}
+
#[test]
-fn blank() {
- assert_eq!(BlankLine::newbox().render(40), vec! {
+fn test_blank() {
+ assert_eq!(blank().render(40), vec! {
ColouredString::plain("")
});
}
#[test]
-fn separator() {
+fn test_separator() {
// Would be nice to test time formatting here, but I'd have to
// think of a way to test it independently of TZ
- assert_eq!(SeparatorLine::newbox(None, true, false)
+ assert_eq!(separator(None, true, false)
.render(60), vec! {
ColouredString::general(
"------------------------------------------------------[F]--",
}
#[test]
-fn editorsep() {
- assert_eq!(EditorHeaderSeparator::newbox().render(5), vec! {
+fn test_editorsep() {
+ assert_eq!(editorsep().render(5), vec! {
ColouredString::general(
"---|",
"----",
)
});
}
+
+#[test]
+fn test_userheader() {
+ assert_eq!(fromline("stoat@example.com", "Some Person").render(80), vec! {
+ ColouredString::general(
+ "From: Some Person (stoat@example.com)",
+ " FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
+ )
+ });
+ assert_eq!(boosterline("stoat@example.com", "Some Person")
+ .render(80), vec! {
+ ColouredString::general(
+ "Via: Some Person (stoat@example.com)",
+ " fffffffffffffffffffffffffffffff",
+ )
+ });
+}