From 3601bf6433d46dea4dd1960f7a3cdc514602983d Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Sat, 11 Nov 2017 03:33:40 -0800 Subject: move id formatting into a Display impl --- src/display/mod.rs | 27 +++++++++++++++------------ 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 Vec { - 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 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::*; -- cgit v1.1