-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
36 lines (32 loc) · 903 Bytes
/
main.rs
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
use clap::Parser;
use game::{GameMode, RusdleState, WordSet};
use std::io;
use std::path::PathBuf;
mod game;
mod renderer;
mod rendering;
#[derive(Parser)]
struct Cli {
#[clap(arg_enum, default_value_t = game::GameMode::Wordle)]
mode: GameMode,
#[clap(short, long, parse(from_os_str), value_name = "FILE")]
word_list: Option<PathBuf>,
#[clap(short, long, parse(from_os_str), value_name = "FILE")]
dictionary: Option<PathBuf>,
}
fn main() -> Result<(), io::Error> {
let cli = Cli::parse();
let mut game = RusdleState::new(WordSet::load(cli.word_list, cli.dictionary)?, cli.mode);
renderer::with_terminal(|r| {
loop {
r.render(&game)?;
if game.is_over() {
break;
}
if let Some(input) = r.next_input()? {
game.handle_input(input)
}
}
Ok(())
})
}