diff --git a/Cargo.lock b/Cargo.lock index 7deb177..0bbf748 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -422,6 +422,7 @@ name = "othello" version = "0.1.0" dependencies = [ "arrayvec", + "console", "const_fn", "criterion", "crossbeam-channel", diff --git a/Cargo.toml b/Cargo.toml index c647c28..9f491af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ debug = true [dependencies] arrayvec = "0.7" +console = "0.15.11" const_fn = "0.4" crossbeam-channel = "0.5.14" either = "1.13" diff --git a/src/elo.rs b/src/elo.rs index 75a9512..5eb89d5 100644 --- a/src/elo.rs +++ b/src/elo.rs @@ -5,7 +5,7 @@ use crate::{ logic::{ChildrenEvalMethod, FutureMoveConfig}, repr::{Board, Piece, Winner}, }; -use indicatif::{ParallelProgressIterator, ProgressStyle}; +use indicatif::{ParallelProgressIterator, ProgressStyle, TermLike}; use rand::seq::SliceRandom; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use skillratings::{ @@ -164,6 +164,7 @@ impl PlayerArena { // Immediately drop our copy of the sender so the channel closes properly drop(sender); + let term = console::Term::stdout(); // Process results on main thread as they arrive let mut received_num = 0; while let Ok((i, j, o)) = receiver.recv() { @@ -172,7 +173,11 @@ impl PlayerArena { // print the leaderboard every 5 steps if received_num % 5 == 0 { - println!("{}", self); + term.clear_last_lines(num) + .expect("unable to clear prev lines"); + let formatted_self = format!("{}", self); + term.write_str(&formatted_self) + .expect("unable to write leaderboard"); } // break if all pairs were recieved