Browse Source

Implement exiting

main
Adrian Heine 6 months ago
parent
commit
adbf3b4e56
  1. 30
      src/main.rs

30
src/main.rs

@ -1,11 +1,33 @@
use gntag::agent::{Agent, SimpleAgent};
use gntag::view::TerminalView;
use gntag::world::ActualWorld;
use std::io;
use std::io::Read;
use std::process::exit;
use std::sync::{Arc, Mutex};
use std::thread;
fn main() {
let mut view = TerminalView::try_new().unwrap();
let view = Arc::new(Mutex::new(Some(TerminalView::try_new().unwrap())));
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);
}
}
});
loop {
let (width, height) = view.content_size().unwrap();
let (width, height) = (*view.lock().unwrap())
.as_mut()
.unwrap()
.content_size()
.unwrap();
let mut agents: Vec<(_, Box<dyn Agent>)> = vec![];
for x in (0..width).step_by(10) {
for y in (0..height).step_by(10) {
@ -16,7 +38,9 @@ fn main() {
let mut gen = 0;
loop {
let resized = view
let resized = (*view.lock().unwrap())
.as_mut()
.unwrap()
.draw(
gen,
world

Loading…
Cancel
Save