Skip to content

Commit

Permalink
Bugfix for terminal mode-setting
Browse files Browse the repository at this point in the history
Bench: 13292315
  • Loading branch information
cosmobobak committed Aug 12, 2024
1 parent 14837c6 commit 5f2478e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "viridithas"
version = "14.0.0"
version = "14.0.1"
edition = "2021"
description = "A superhuman chess engine."
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ pub fn set_mode() -> anyhow::Result<()> {
#[cfg(not(windows))]
Ok(())
}

pub fn set_mode_uci() {
set_mode().unwrap();
}
14 changes: 11 additions & 3 deletions src/uci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
str::{FromStr, ParseBoolError},
sync::{
atomic::{self, AtomicBool, AtomicI32, AtomicU64, AtomicU8, AtomicUsize, Ordering},
mpsc, Mutex,
mpsc, Mutex, Once,
},
time::Instant,
};
Expand Down Expand Up @@ -507,10 +507,10 @@ fn print_uci_response(info: &SearchInfo, full: bool) {
println!("uciok");
}

static SET_TERM: Once = Once::new();

#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
pub fn main_loop(global_bench: bool) -> anyhow::Result<()> {
term::set_mode()?;

let mut pos = Board::default();

let mut tt = TT::new();
Expand Down Expand Up @@ -665,6 +665,14 @@ pub fn main_loop(global_bench: bool) -> anyhow::Result<()> {
input if input.starts_with("go") => {
// start the clock *immediately*
info.time_manager.start();

// if we're in pretty-printing mode, set the terminal properly:
if PRETTY_PRINT.load(Ordering::SeqCst) {
SET_TERM.call_once(|| {
term::set_mode_uci();
});
}

let res = parse_go(input, &pos);
if let Ok(search_limit) = res {
info.time_manager.set_limit(search_limit);
Expand Down

0 comments on commit 5f2478e

Please sign in to comment.