pub mod agent; pub mod view; pub mod world; use agent::{Agent, SimpleAgent}; use std::io; use std::io::Read; use std::process::exit; use std::sync::{Arc, Mutex}; use std::thread; use view::{RawTerminal, TerminalView, TermionBackend}; use world::ActualWorld; pub fn get_world(width: isize, height: isize, spacing: usize, validating: bool) -> ActualWorld { let mut agents: Vec<(_, Box)> = vec![]; for x in (0..width).step_by(spacing) { for y in (0..height).step_by(spacing) { agents.push(((x, y).into(), Box::new(SimpleAgent))); } } ActualWorld::new((width, height).into(), agents, validating) } pub type DefaultView = Arc>>>>>; pub fn get_view() -> DefaultView { let view = Arc::new(Mutex::new(Some(TerminalView::try_new().unwrap()))); // Exit on q, ESC and Ctrl-C and reset terminal let view2 = view.clone(); thread::spawn(move || { let stdin = io::stdin(); for byte in stdin.bytes().flatten() { if byte == b'q' || byte == 0x1b || byte == 0x03 { if let Ok(mut view) = view2.lock() { *view = None; // drop view println!("\n"); } exit(0); } } }); view }