|
|
@ -3,6 +3,12 @@ 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 {
|
|
|
@ -14,3 +20,24 @@ pub fn get_world(width: isize, height: isize, spacing: usize, validating: bool) |
|
|
|
}
|
|
|
|
ActualWorld::new((width, height).into(), agents, validating)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type DefaultView = Arc<Mutex<Option<TerminalView<TermionBackend<RawTerminal<io::Stdout>>>>>>;
|
|
|
|
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
|
|
|
|
}
|