-use chrono::{DateTime,Utc,Local};
-use core::cmp::max;
+use chrono::{DateTime, Utc, Local};
+use core::cmp::{max, min};
use std::collections::{HashMap, BTreeSet};
use super::html;
// 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>;
+
+ fn as_extendable_indicator(&self) -> Option<&ExtendableIndicator> { None }
}
pub struct BlankLine {}
});
}
+pub struct ExtendableIndicator {}
+
+pub fn extendable_indicator() -> Box<dyn TextFragment> {
+ Box::new(ExtendableIndicator{})
+}
+
+impl TextFragment for ExtendableIndicator {
+ fn render(&self, width: usize) -> Vec<ColouredString> {
+ // FIXME: decide how to make this message change when it's primed
+ let message = ColouredString::general(
+ "Press [0] at top of file to extend",
+ "HHHHHHHKHHHHHHHHHHHHHHHHHHHHHHHHHH");
+ let msgtrunc = message.truncate(width);
+ let space = width - min(msgtrunc.width() + 1, width);
+ let left = space / 2;
+ let msgpad = ColouredString::plain(" ").repeat(left) + msgtrunc;
+ vec! {
+ ColouredString::plain(""),
+ msgpad,
+ ColouredString::plain(""),
+ }
+ }
+
+ // FIXME: get rid of this silly trait method if I turn out not to need it
+ fn as_extendable_indicator(&self) -> Option<&ExtendableIndicator> {
+ Some(self)
+ }
+}
+
+#[test]
+fn test_extendable() {
+ assert_eq!(extendable_indicator().render(40), vec! {
+ ColouredString::plain(""),
+ ColouredString::general(
+ " Press [0] at top of file to extend",
+ " HHHHHHHKHHHHHHHHHHHHHHHHHHHHHHHHHH"),
+ ColouredString::plain(""),
+ });
+}
+
// TODO:
-// ExtendableIndicator at file header (with an 'active' flag)
// InReplyToLine, with first line of included paragraph
// NotificationLog, also with included toot
// UserListEntry