diff options
author | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-11 03:33:40 -0800 |
---|---|---|
committer | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-11 03:33:40 -0800 |
commit | 3601bf6433d46dea4dd1960f7a3cdc514602983d (patch) | |
tree | 5d7d057480b0dc186311cd729f7a2c514a8c52eb /src | |
parent | 44b4d324a0176033107789d1421549b24898ac8a (diff) |
move id formatting into a Display impl
Diffstat (limited to 'src')
-rw-r--r-- | src/display/mod.rs | 27 | ||||
-rw-r--r-- | src/tw/mod.rs | 20 |
2 files changed, 35 insertions, 12 deletions
diff --git a/src/display/mod.rs b/src/display/mod.rs index 92fa9dd..0eeba68 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -363,12 +363,13 @@ pub fn render_twete(twete_id: &TweetId, tweeter: &mut tw::TwitterCache) -> Vec<S let rt = tweeter.retrieve_tweet(&TweetId::Twitter(rt_id.to_owned())).unwrap().clone(); // and its author let rt_author = tweeter.retrieve_user(&rt.author_id).unwrap().clone(); - result.push(format!("{} id:{} (rt_id:{}){}{}", + result.push(format!("{} id {} (rt id {}){}{}", id_color, rt.internal_id, twete.internal_id, rt.reply_to_tweet.clone() - .map(|id| tweeter.retrieve_tweet(&TweetId::Twitter(id.to_owned())) - .and_then(|tw| Some(format!(" reply_to:{}", tw.internal_id))) - .unwrap_or(format!(" reply_to:twitter::{}", id)) + .map(|id_str| TweetId::Twitter(id_str.to_owned())) + .map(|id| tweeter.retrieve_tweet(&id) + .and_then(|tw| Some(format!(" reply to {}", tw.internal_id))) + .unwrap_or(format!(" reply to {}", id)) ) .unwrap_or("".to_string()), color::Fg(color::Reset) @@ -381,12 +382,13 @@ pub fn render_twete(twete_id: &TweetId, tweeter: &mut tw::TwitterCache) -> Vec<S )); } None => { - result.push(format!("{} id:{}{}{}", + result.push(format!("{} id {}{}{}", id_color, twete.internal_id, twete.reply_to_tweet.clone() - .map(|id| tweeter.retrieve_tweet(&TweetId::Twitter(id.to_owned())) - .and_then(|tw| Some(format!(" reply_to:{}", tw.internal_id))) - .unwrap_or(format!(" reply_to:twitter::{}", id)) + .map(|id_str| TweetId::Twitter(id_str.to_owned())) + .map(|id| tweeter.retrieve_tweet(&id) + .and_then(|tw| Some(format!(" reply to {}", tw.internal_id))) + .unwrap_or(format!(" reply to {}", id)) ) .unwrap_or("".to_string()), color::Fg(color::Reset) @@ -406,12 +408,13 @@ pub fn render_twete(twete_id: &TweetId, tweeter: &mut tw::TwitterCache) -> Vec<S let maybe_qt = tweeter.retrieve_tweet(&TweetId::Twitter(qt_id.to_owned())).map(|x| x.to_owned()); if let Some(qt) = maybe_qt { let qt_author = tweeter.retrieve_user(&qt.author_id).unwrap().clone(); - result.push(format!("{} id:{}{}{}", + result.push(format!("{} id {}{}{}", id_color, qt.internal_id, qt.reply_to_tweet.clone() - .map(|id| tweeter.retrieve_tweet(&TweetId::Twitter(id.to_owned())) - .and_then(|tw| Some(format!(" reply_to:{}", tw.internal_id))) - .unwrap_or(format!(" reply_to:twitter::{}", id)) + .map(|id_str| TweetId::Twitter(id.to_owned())) + .map(|id| tweeter.retrieve_tweet(&id) + .and_then(|tw| Some(format!(" reply to {}", tw.internal_id))) + .unwrap_or(format!(" reply to {}", id)) ) .unwrap_or("".to_string()), color::Fg(color::Reset) diff --git a/src/tw/mod.rs b/src/tw/mod.rs index e2b8b03..b5ad72b 100644 --- a/src/tw/mod.rs +++ b/src/tw/mod.rs @@ -1,4 +1,5 @@ use std::path::Path; +use std::fmt; use std::str::FromStr; use std::fs::File; use std::io::{BufRead, BufReader, Read}; @@ -167,6 +168,25 @@ pub enum TweetId { Twitter(String) // twitter::number } +impl fmt::Display for TweetId { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &TweetId::Today(ref id) => { + write!(f, "{}", id) + }, + &TweetId::Dated(ref date, ref id) => { + write!(f, "{}:{}", date, id) + }, + &TweetId::Bare(ref id) => { + write!(f, ":{}", id) + }, + &TweetId::Twitter(ref id) => { + write!(f, "twitter:{}", id) + } + } + } +} + #[cfg(test)] mod tests { use super::*; |