feat: coloured search output for a terminal

Started from a terminal, Rigby now shows its search for a human:
coloured progress lines (depth/seldepth, playouts, speed, time, a tree
fill bar, score in pawns, the PV fading with depth) at 125, 250, 500 ms
and then every second, and at the end a table of the most visited root
moves with a bar for their share of the visits, their score and prior.
Tree reuse and collections are shown as notes, and bestmove is
highlighted.

The first "uci" command switches to plain UCI output for good. GUIs and
match runners send it first and read stdout through a pipe, so they
never see the coloured output. NO_COLOR turns it off. On Windows the
console gets ANSI processing and UTF-8 output.

Checked: the UCI output of a scripted session (two searches with tree
reuse, a stalemate root) is identical to main apart from nps and time;
go wtime, go infinite with stop, and quit work; the pretty mode was
driven in a real console, including the switch to UCI. Search is
untouched, so the bench is unchanged.

Bench: 546018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 14:15:49 +01:00
1 parent 1754753a6e
commit 6490286852
6 files changed
+319 -17

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include <string>
#include <vector>
#include "types.h"
namespace rigby::pretty {
// Human-readable, coloured search output for a terminal. The engine uses it
// until the first "uci" command; GUIs and match runners always send "uci"
// (and read stdout through a pipe), so they only ever see plain UCI.
// True when stdout is a terminal (and NO_COLOR is not set). Turns on ANSI
// colours and UTF-8 output on the Windows console.
bool init_terminal();
std::string banner(const std::string& name, const std::string& version, const std::string& author);
// One snapshot of a running search.
struct Progress {
int depth = 0;
int seldepth = 0;
u64 playouts = 0;
u64 nps = 0;
i64 ms = 0;
int hashfull = 0; // per mille
int cp = 0; // side to move's view
std::vector<std::string> pv;
};
struct RootMove {
std::string move;
u32 visits = 0;
int cp = 0; // from Q, side to move's view
float prior = 0.0f;
};
std::string header();
std::string progress(const Progress& p);
// The most visited root moves, with their share of the visits.
std::string root_table(std::vector<RootMove> moves, size_t max_rows);
std::string note(const std::string& text);
std::string reused(u64 nodes);
std::string bestmove(const std::string& move);
} // namespace rigby::pretty