mod sensors; mod netspeed; mod comm; use comm::{Channel, Message}; use std::collections::HashMap; use std::io; use std::sync::mpsc; use std::thread; fn main() { let (tx, rx) = mpsc::channel::(); make_thread(&tx, stdin); make_thread(&tx, sensors::sensors); make_thread(&tx, netspeed::netspeed); let mut data = HashMap::new(); loop { let msg = rx.recv().unwrap(); let empty = "".to_string(); match msg { Message { kind, text } => data.insert(kind, text), }; println!("%{{r}}{} | {}", data.get("netspeed").unwrap_or(&empty), data.get("sensors").unwrap_or(&empty) ); } } fn make_thread(tx: &Channel, func: fn(&Channel) -> ()) { let thread_tx = tx.clone(); thread::spawn(move || { func(&thread_tx); }); } fn stdin(tx: &Channel) { let mut line = String::new(); loop { io::stdin().read_line(&mut line).ok().expect("Failed to read line"); } }