From 780ccc569fee0eeb21069575bd88dd8f94aeb424 Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 17 Nov 2017 00:50:11 -0800 Subject: fix rendering issues with events, support End key also disable rendering of delete events --- src/display/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/display') diff --git a/src/display/mod.rs b/src/display/mod.rs index 2b0bed0..954ed38 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -213,7 +213,7 @@ pub fn paint(tweeter: &mut ::tw::TwitterCache) -> Result<(), std::io::Error> { lines.into_iter().rev().collect() }, Infos::Event(e) => { - let pre_split = e.clone().render(tweeter); + let pre_split = e.clone().render(tweeter, width); let total_length: usize = pre_split.iter().map(|x| x.len()).sum(); let wrapped = if total_length <= 1024 { into_display_lines(pre_split, width) @@ -282,11 +282,11 @@ fn color_for(handle: &String) -> termion::color::Fg<&color::Color> { } pub trait Render { - fn render(self, tweeter: &mut ::tw::TwitterCache) -> Vec; + fn render(self, tweeter: &mut ::tw::TwitterCache, width: u16) -> Vec; } impl Render for tw::events::Event { - fn render(self, tweeter: &mut ::tw::TwitterCache) -> Vec { + fn render(self, tweeter: &mut ::tw::TwitterCache, width: u16) -> Vec { let mut result = Vec::new(); match self { tw::events::Event::Quoted { user_id, twete_id } => { @@ -295,13 +295,13 @@ impl Render for tw::events::Event { let user = tweeter.retrieve_user(&user_id).unwrap(); result.push(format!(" quoted_tweet : {} (@{})", user.name, user.handle)); } - render_twete(&TweetId::Twitter(twete_id), tweeter, None); + render_twete(&TweetId::Twitter(twete_id), tweeter, Some(width)); } tw::events::Event::Deleted { user_id, twete_id } => { if let Some(handle) = tweeter.retrieve_user(&user_id).map(|x| &x.handle).map(|x| x.clone()) { if let Some(_tweet) = tweeter.retrieve_tweet(&TweetId::Twitter(twete_id.to_owned())).map(|x| x.clone()) { result.push(format!("-------------DELETED------------------")); - result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, None)); + result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, Some(width))); result.push(format!("-------------DELETED------------------")); } else { result.push(format!("dunno what, but do know who: {} - {}", user_id, handle)); @@ -316,7 +316,7 @@ impl Render for tw::events::Event { let user = tweeter.retrieve_user(&user_id).unwrap(); result.push(format!(" +rt_rt : {} (@{})", user.name, user.handle)); } - result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, None)); + result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, Some(width))); }, tw::events::Event::Fav_RT { user_id, twete_id } => { result.push("---------------------------------".to_string()); @@ -325,7 +325,7 @@ impl Render for tw::events::Event { } else { result.push(format!(" +rt_fav but don't know who {} is", user_id)); } - result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, None)); + result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, Some(width))); }, tw::events::Event::Fav { user_id, twete_id } => { result.push("---------------------------------".to_string()); @@ -333,7 +333,7 @@ impl Render for tw::events::Event { let user = tweeter.retrieve_user(&user_id).unwrap(); result.push(format!("{} +fav : {} (@{}){}", color::Fg(color::Yellow), user.name, user.handle, color::Fg(color::Reset))); } - result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, None)); + result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, Some(width))); }, tw::events::Event::Unfav { user_id, twete_id } => { result.push("---------------------------------".to_string()); @@ -341,7 +341,7 @@ impl Render for tw::events::Event { let user = tweeter.retrieve_user(&user_id).unwrap(); result.push(format!("{} -fav : {} (@{}){}", color::Fg(color::Yellow), user.name, user.handle, color::Fg(color::Reset))); } - result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, None)); + result.extend(render_twete(&TweetId::Twitter(twete_id), tweeter, Some(width))); }, tw::events::Event::Followed { user_id } => { result.push("---------------------------------".to_string()); -- cgit v1.1