diff --git a/rs/src/main.rs b/rs/src/main.rs index 389888c..70313b0 100644 --- a/rs/src/main.rs +++ b/rs/src/main.rs @@ -1,19 +1,6 @@ -use std::io::BufRead; mod board; mod ui; fn main() -> Result<(), ()> { - let mut board = board::Board::new(); - board.reset(); - let stdin = std::io::stdin(); - let mut input_lines = stdin.lock().lines(); - loop { - match input_lines.next() { - None => break Ok(()), - Some(line) => match &line.unwrap()[..] { - "get_state" => println!("{}", board), - _ => break Err(()), - }, - } - } + ui::Ui::new().run() } diff --git a/rs/src/ui.rs b/rs/src/ui.rs index 66cce97..f0ac808 100644 --- a/rs/src/ui.rs +++ b/rs/src/ui.rs @@ -1,5 +1,6 @@ use crate::board; use crate::board::GridAxis; +use std::io::BufRead; impl std::fmt::Display for board::Color { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -52,3 +53,30 @@ impl std::fmt::Display for board::Board { Ok(()) } } + +pub struct Ui { + board: board::Board, +} + +impl Ui { + pub fn new() -> Self { + let mut board = board::Board::new(); + board.reset(); + Ui { + board, + } + } + pub fn run(&mut self) -> Result<(), ()> { + let stdin = std::io::stdin(); + let mut input_lines = stdin.lock().lines(); + loop { + match input_lines.next() { + None => break Ok(()), + Some(line) => match &line.unwrap()[..] { + "get_state" => println!("{}", self.board), + _ => break Err(()), + }, + } + } + } +}