1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
mod args;

#[cfg(feature = "tui")]
mod tui;

use args::Args;
use rlifesrc_lib::{PolyWorld, Status};
use std::process::exit;

/// Runs the search without TUI.
///
/// If `all` is true, it will print all possible results
/// instead of only the first one.
fn run_search(world: &mut PolyWorld, all: bool) {
    if all {
        let mut found = false;
        loop {
            match world.search(None) {
                Status::Found => {
                    found = true;
                    println!("{}", world.rle_gen(0));
                }
                Status::None => break,
                _ => (),
            }
        }
        if !found {
            eprintln!("Not found.");
            exit(1);
        }
    } else if world.search(None) == Status::Found {
        println!("{}", world.rle_gen(0));
    } else {
        eprintln!("Not found.");
        exit(1);
    }
}

#[cfg(feature = "tui")]
fn main() {
    let args = Args::parse().unwrap_or_else(|e| e.exit());
    let mut world = args.world;
    if args.no_tui {
        run_search(&mut world, args.all);
    } else {
        tui::tui(world, args.reset).unwrap();
    }
}

#[cfg(not(feature = "tui"))]
fn main() {
    let mut args = Args::parse().unwrap_or_else(|e| e.exit());
    run_search(&mut args.world, args.all);
}