From bfc3232b5dae3ac8fa0fba3f50d771d75beda08a Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 10 Nov 2017 23:16:37 -0800 Subject: cleanup * show interface at startup * report when stream is connected at startup --- src/main.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 97d5315..d69d67d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -198,9 +198,14 @@ fn main() { let mut tweeter = tw::TwitterCache::load_cache(); - println!("Loaded cache!"); + tweeter.display_info.status("Cache loaded".to_owned()); - let mut maybe_twete_rx: Option>> = tweeter.profile.clone().map(|user_creds| connect_twitter_stream(tweeter.app_key.clone(), user_creds)); + let mut maybe_twete_rx = tweeter.profile.clone() + .map(|user_creds| { + let rx = connect_twitter_stream(tweeter.app_key.clone(), user_creds); + tweeter.display_info.status("Twitter stream open".to_owned()); + rx + }); std::thread::spawn(move || { for input in stdin().events() { @@ -228,6 +233,12 @@ fn main() { new_termios.c_lflag &= !(ICANON | ECHO); tcsetattr(0, TCSANOW, &new_termios).unwrap(); + + match display::paint(&mut tweeter) { + Ok(_) => (), + Err(e) => println!("{}", e) // TODO: we got here because writing to stdout failed. what to do now? + }; + loop { match do_ui(ui_rx, maybe_twete_rx, &mut tweeter, &mut queryer) { Some((new_ui_rx, new_maybe_twete_rx)) => { @@ -317,7 +328,7 @@ fn handle_input(event: termion::event::Event, tweeter: &mut tw::TwitterCache, qu fn handle_twitter_line(line: Vec, mut tweeter: &mut tw::TwitterCache, mut queryer: &mut ::Queryer) { let jsonstr = std::str::from_utf8(&line).unwrap().trim(); - /* TODO: replace from_str with from_slice */ + /* TODO: replace from_str with from_slice? */ match serde_json::from_str(&jsonstr) { Ok(json) => { tw::handle_message(json, &mut tweeter, &mut queryer); -- cgit v1.1