// 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_mut(&mut self)
- -> Option<&mut ExtendableIndicator> {
- None
- }
- fn as_menu_keypress_mut(&mut self) -> Option<&mut MenuKeypressLine> {
- None
- }
}
pub struct BlankLine {}
impl BlankLine {
- pub fn new() -> Box<dyn TextFragment> {
- Box::new(BlankLine{})
+ pub fn new() -> Self {
+ BlankLine{}
}
}
timestamp: Option<DateTime<Utc>>,
favourited: bool,
boosted: bool,
- ) -> Box<dyn TextFragment> {
- Box::new(SeparatorLine {
- timestamp,
- favourited,
- boosted,
- })
+ ) -> Self {
+ SeparatorLine {
+ timestamp,
+ favourited,
+ boosted,
+ }
}
}
pub struct EditorHeaderSeparator {}
impl EditorHeaderSeparator {
- pub fn new() -> Box<dyn TextFragment> {
- Box::new(EditorHeaderSeparator{})
+ pub fn new() -> Self {
+ EditorHeaderSeparator{}
}
}
}
impl UsernameHeader {
- pub fn from(account: &str, nameline: &str) -> Box<dyn TextFragment> {
- Box::new(UsernameHeader{
+ pub fn from(account: &str, nameline: &str) -> Self {
+ UsernameHeader{
header: "From".to_owned(),
colour: 'F',
account: account.to_owned(),
nameline: nameline.to_owned(),
- })
+ }
}
- pub fn via(account: &str, nameline: &str) -> Box<dyn TextFragment> {
- Box::new(UsernameHeader{
- header: "Via".to_owned(),
- colour: 'f',
- account: account.to_owned(),
- nameline: nameline.to_owned(),
- })
+ pub fn via(account: &str, nameline: &str) -> Self {
+ UsernameHeader{
+ header: "Via".to_owned(),
+ colour: 'f',
+ account: account.to_owned(),
+ nameline: nameline.to_owned(),
+ }
}
}
self.words.splice(start..first_non_mention, vec!{});
}
- pub fn into_box(self) -> Box<dyn TextFragment> { Box::new(self) }
-
pub fn is_empty(&self) -> bool {
match self.words.first() {
None => true,
#[test]
fn test_para_wrap() {
let p = Paragraph::new().add(&ColouredString::plain(
- "the quick brown fox jumps over the lazy dog")).into_box();
+ "the quick brown fox jumps over the lazy dog"));
assert_eq!(p.render(15), vec! {
ColouredString::plain("the quick brown"),
ColouredString::plain("fox jumps over"),
});
let p = Paragraph::new().add(&ColouredString::plain(
- " one supercalifragilisticexpialidocious word")).into_box();
+ " one supercalifragilisticexpialidocious word"));
assert_eq!(p.render(15), vec! {
ColouredString::plain(" one"),
ColouredString::plain("supercalifragilisticexpialidocious"),
});
let p = Paragraph::new().add(&ColouredString::plain(
- " supercalifragilisticexpialidocious word")).into_box();
+ " supercalifragilisticexpialidocious word"));
assert_eq!(p.render(15), vec! {
ColouredString::plain(" supercalifragilisticexpialidocious"),
ColouredString::plain("word"),
let p = Paragraph::new().add(&ColouredString::plain(
"the quick brown fox jumps over the lazy dog"))
- .set_wrap(false).into_box();
+ .set_wrap(false);
assert_eq!(p.render(15), vec! {
ColouredString::plain("the quick brown fox jumps over the lazy dog"),
});
let p = Paragraph::new().add(&ColouredString::plain(
"the quick brown fox jumps over the lazy dog"))
- .set_indent(4, 2).into_box();
+ .set_indent(4, 2);
assert_eq!(p.render(15), vec! {
ColouredString::plain(" the quick"),
ColouredString::plain(" brown fox"),
}
impl FileHeader {
- pub fn new(text: ColouredString) -> Box<dyn TextFragment> {
- Box::new(FileHeader{
- text: text,
- })
+ pub fn new(text: ColouredString) -> Self {
+ FileHeader{
+ text: text,
+ }
}
}
}
impl ExtendableIndicator {
- pub fn new() -> Box<dyn TextFragment> {
- Box::new(ExtendableIndicator{
- primed: false
- })
+ pub fn new() -> Self {
+ ExtendableIndicator{
+ primed: false
+ }
}
pub fn set_primed(&mut self, primed: bool) { self.primed = primed; }
ColouredString::plain(""),
}
}
-
- fn as_extendable_indicator_mut(&mut self)
- -> Option<&mut ExtendableIndicator> {
- Some(self)
- }
}
#[test]
ColouredString::plain(""),
});
- ei.as_extendable_indicator_mut().unwrap().set_primed(true);
+ ei.set_primed(true);
assert_eq!(ei.render(40), vec! {
ColouredString::plain(""),
}
impl InReplyToLine {
- pub fn new(post: &Vec<Paragraph>) -> Box<dyn TextFragment> {
+ pub fn new(post: &Vec<Paragraph>) -> Self {
let mut para = Paragraph::new().add(&ColouredString::plain("Re: "));
let currlen = para.words.len();
for cpara in post {
para.push_para(cpara);
}
para.delete_mention_words_from(currlen);
- Box::new(InReplyToLine {
- para: para
- })
+ InReplyToLine {
+ para: para
+ }
}
}
pub fn new(
timestamp: DateTime<Utc>, account: &str, nameline: &str,
ntype: NotificationLogType, post: Option<&Vec<Paragraph>>)
- -> Box<dyn TextFragment> {
+ -> Self {
let mut para = Paragraph::new();
para.delete_mention_words_from(currlen);
}
- Box::new(NotificationLog {
- timestamp: timestamp,
- account_desc: format!("{} ({})", nameline, account),
- para: para,
- })
+ NotificationLog {
+ timestamp: timestamp,
+ account_desc: format!("{} ({})", nameline, account),
+ para: para,
+ }
}
}
impl UserListEntry {
pub fn new(account: &str, nameline: &str)
- -> Box<dyn TextFragment> {
- Box::new(UserListEntry {
- account_desc: format!("{} ({})", nameline, account),
- })
+ -> Self {
+ UserListEntry {
+ account_desc: format!("{} ({})", nameline, account),
+ }
}
}
impl Media {
pub fn new(url: &str, description: &str)
- -> Box<dyn TextFragment> {
+ -> Self {
let mut paras = description
.split('\n')
.map(|x| Paragraph::new()
.add(&ColouredString::uniform(x, 'm')))
.collect();
trim_para_list(&mut paras);
- Box::new(Media {
- url: url.to_owned(),
- description: paras,
- })
+ Media {
+ url: url.to_owned(),
+ description: paras,
+ }
}
}
message: Option<String>,
}
-struct FileStatusLineFinal {
+pub struct FileStatusLineFinal {
fs: FileStatusLine,
priwidth: Vec<(usize, usize)>, // min priority, total width of those keys
}
self
}
- fn finalise(self) -> FileStatusLineFinal {
+ pub fn finalise(self) -> FileStatusLineFinal {
let mut bypri = BTreeMap::new();
for (kp, pri) in &self.keypresses {
// [key]:desc
priwidth: priwidth
}
}
-
- pub fn into_box(self) -> Box<dyn TextFragment> {
- Box::new(self.finalise())
- }
}
#[test]
.add(OurKey::Pr('b'), "Badger", 10)
.add(OurKey::Pr('c'), "Critical", 1000)
.add(OurKey::Pr('d'), "Dull", 1)
- .into_box();
+ .finalise();
assert_eq!(fs.render(80), vec! {
ColouredString::general(
let fs = FileStatusLine::new()
.set_proportion(1, 11)
.add(OurKey::Pr('K'), "Keypress", 10)
- .into_box();
+ .finalise();
assert_eq!(fs.render(19), vec! {
ColouredString::general(
let fs = FileStatusLine::new()
.message("weasel")
.add(OurKey::Pr('K'), "Keypress", 10)
- .into_box();
+ .finalise();
assert_eq!(fs.render(21), vec! {
ColouredString::general(
impl MenuKeypressLine {
pub fn new(key: OurKey, description: ColouredString)
- -> Box<dyn TextFragment> {
+ -> Self {
// +2 for [] around the key name
let lwid = UnicodeWidthStr::width(&key_to_string(key) as &str) + 2;
let rwid = description.width();
- Box::new(MenuKeypressLine {
- keypress: Keypress {
- key: key,
- description: description,
- },
- lwid: lwid,
- lmaxwid: lwid,
- rmaxwid: rwid,
- })
+ MenuKeypressLine {
+ keypress: Keypress {
+ key: key,
+ description: description,
+ },
+ lwid: lwid,
+ lmaxwid: lwid,
+ rmaxwid: rwid,
+ }
}
pub fn get_widths(&self) -> (usize, usize) { (self.lmaxwid, self.rmaxwid) }
line.truncate(width).to_owned()
}
}
-
- fn as_menu_keypress_mut(&mut self) -> Option<&mut MenuKeypressLine> {
- Some(self)
- }
}
#[test]
" k K "),
});
- mk.as_menu_keypress_mut().unwrap().ensure_widths(5, 0);
+ mk.ensure_widths(5, 0);
assert_eq!(mk.render(40), vec! {
ColouredString::general(