From 799757386fa02339c20eff9f256de0f97b5fa042 Mon Sep 17 00:00:00 2001 From: Andy Wortman 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 +++++++++--------- src/main.rs | 3 +++ src/tw/mod.rs | 6 +++++- 3 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src') 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()); diff --git a/src/main.rs b/src/main.rs index ecac646..bfb60f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -323,6 +323,9 @@ fn handle_input(event: termion::event::Event, tweeter: &mut tw::TwitterCache, qu } } }, + Event::Key(Key::End) => { + tweeter.display_info.infos_seek = 0; + } Event::Key(Key::PageUp) => { tweeter.display_info.infos_seek = tweeter.display_info.infos_seek.saturating_add(1); } diff --git a/src/tw/mod.rs b/src/tw/mod.rs index 7024260..acee0c2 100644 --- a/src/tw/mod.rs +++ b/src/tw/mod.rs @@ -286,6 +286,9 @@ impl TwitterCache { key: "".to_owned(), secret: "".to_owned() }, + // So, supporting multiple profiles will be ... interesting? + // how do we support a variable number of channels? which will be necessary as we'll + // have one channel up per twitter stream... profile: None, // this will become a HashMap when multiple profiles are supported following: HashSet::new(), following_history: HashMap::new(), @@ -345,7 +348,6 @@ impl TwitterCache { fn cache_tweet(&mut self, tweet: Tweet) { if !self.tweets.contains_key(&tweet.id) { - let mut file = OpenOptions::new() .create(true) @@ -706,12 +708,14 @@ fn handle_twitter_delete( structure: serde_json::Map, tweeter: &mut TwitterCache, _queryer: &mut ::Queryer) { + /* tweeter.display_info.recv(display::Infos::Event( events::Event::Deleted { user_id: structure["delete"]["status"]["user_id_str"].as_str().unwrap().to_string(), twete_id: structure["delete"]["status"]["id_str"].as_str().unwrap().to_string() } )); + */ } fn handle_twitter_twete( -- cgit v1.1