Live framed search dashboard for a terminal #6

Merged
claude merged 2 commits from pretty-dashboard into main 2026-11-15 14:34:52 +01:00
2 changed files with 10 additions and 60 deletions
Showing only changes of commit 4973535596 - Show all commits

No files matched your search

+4 -4
View File
@@ -61,10 +61,10 @@ Extra commands:
`go depth N` limits the mean playout depth. `nodes` in `info` lines are playouts. `go depth N` limits the mean playout depth. `nodes` in `info` lines are playouts.
Started from a terminal, Rigby shows its search for a human instead: a framed Started from a terminal, Rigby shows its search for a human instead: a framed
dashboard, redrawn in place ten times a second, with the board (the best move dashboard, redrawn in place ten times a second, with the score and an evaluation
highlighted), the score and an evaluation bar, depth, playouts, speed, a time bar, bar, depth, playouts, speed, a time bar, tree fill, the principal variation in SAN
tree fill, the principal variation in SAN and the most visited root moves with and the most visited root moves with their share of the visits, score and prior.
their share of the visits, score and prior. It adapts to the terminal's size. The It adapts to the terminal's size. The
first `uci` command switches to plain UCI output for good; GUIs and match runners 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 it. `NO_COLOR` send it first and read stdout through a pipe, so they never see it. `NO_COLOR`
turns it off, `RIGBY_PRETTY=1` forces it into a pipe (e.g. `less -R`). It needs a turns it off, `RIGBY_PRETTY=1` forces it into a pipe (e.g. `less -R`). It needs a
+6 -56
View File
@@ -212,45 +212,7 @@ struct Box {
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Board // Statistics, nine lines
// ---------------------------------------------------------------------------
constexpr int BOARD_WIDTH = 2 + 8 * 3;
Line board_row(const Position& pos, int rank, Move best) {
static constexpr const char* GLYPHS[] = {"♟", "♞", "♝", "♜", "♛", "♚"};
static const std::string LIGHT = bg(168, 140, 110), DARK = bg(122, 95, 73);
static const std::string LIGHT_HI = bg(176, 172, 82), DARK_HI = bg(136, 138, 58);
static const std::string WHITE_PIECE = BOLD + fg(255, 255, 255), BLACK_PIECE = BOLD + fg(18, 16, 22);
Line l;
l.add(std::to_string(rank + 1) + " ", LABEL);
for (int file = 0; file < 8; file++) {
const int sq = rank * 8 + file;
const bool light = (file + rank) % 2 == 1;
const bool hi = best && (sq == best.from() || sq == best.to());
const std::string& square = hi ? (light ? LIGHT_HI : DARK_HI) : (light ? LIGHT : DARK);
const int piece = pos.piece_on(sq);
if (piece == NO_PIECE) {
l.text += square + " " + RESET;
} else {
l.text += square + (piece_color(piece) == WHITE ? WHITE_PIECE : BLACK_PIECE) + " " +
GLYPHS[piece_type(piece)] + " " + RESET;
}
l.width += 3;
}
return l;
}
Line board_files() {
Line l;
l.add(" ");
for (char f = 'a'; f <= 'h'; f++) l.add(std::string(" ") + f + " ", LABEL);
return l;
}
// ---------------------------------------------------------------------------
// Statistics column, nine lines next to the board
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
constexpr int LABEL_WIDTH = 10; constexpr int LABEL_WIDTH = 10;
@@ -273,7 +235,7 @@ std::vector<Line> stats(const Dashboard& d, int width) {
const double q = eval::cp_to_q(d.cp); const double q = eval::cp_to_q(d.cp);
const double white = d.root.stm == WHITE ? (q + 1.0) / 2.0 : (1.0 - q) / 2.0; const double white = d.root.stm == WHITE ? (q + 1.0) / 2.0 : (1.0 - q) / 2.0;
Line eval_bar = label("white"); Line eval_bar = label("white");
const int bar_width = std::max(width - LABEL_WIDTH - 5, 4); const int bar_width = std::clamp(width - LABEL_WIDTH - 5, 4, 48);
eval_bar.append(bar(white, bar_width, fg(240, 240, 245), fg(55, 55, 68), bg(55, 55, 68))); eval_bar.append(bar(white, bar_width, fg(240, 240, 245), fg(55, 55, 68), bg(55, 55, 68)));
eval_bar.add(pad_left(format("%.0f%%", white * 100.0), 5), VALUE); eval_bar.add(pad_left(format("%.0f%%", white * 100.0), 5), VALUE);
out.push_back(eval_bar); out.push_back(eval_bar);
@@ -304,7 +266,7 @@ std::vector<Line> stats(const Dashboard& d, int width) {
Line progress_bar = label(""); Line progress_bar = label("");
if (progress >= 0.0) if (progress >= 0.0)
progress_bar.append(bar(d.done ? 1.0 : progress, width - LABEL_WIDTH, CYAN, fg(45, 50, 66), bg(45, 50, 66))); progress_bar.append(bar(d.done ? 1.0 : progress, bar_width + 5, CYAN, fg(45, 50, 66), bg(45, 50, 66)));
out.push_back(progress_bar); out.push_back(progress_bar);
// Tree memory: one square per tenth. // Tree memory: one square per tenth.
@@ -399,8 +361,6 @@ std::vector<std::string> render(const Dashboard& d, int frame) {
Box box{std::clamp(term.cols - 1, 52, 104), {}}; Box box{std::clamp(term.cols - 1, 52, 104), {}};
const int inner = box.inner(); const int inner = box.inner();
const bool show_board = inner >= BOARD_WIDTH + 3 + 34;
const int stats_width = show_board ? inner - BOARD_WIDTH - 3 : inner;
// Fit the height: fewer root moves first, then no blank lines. // Fit the height: fewer root moves first, then no blank lines.
const int pv_max = 2; const int pv_max = 2;
@@ -416,24 +376,14 @@ std::vector<std::string> render(const Dashboard& d, int frame) {
const bool show_moves = rows >= 1; const bool show_moves = rows >= 1;
Line title; Line title;
title.add("♞ Rigby", TITLE); title.add("Rigby", TITLE);
Line status; Line status;
if (d.done) status.add("✓ done", BOLD + BRIGHT_GREEN); if (d.done) status.add("✓ done", BOLD + BRIGHT_GREEN);
else status.add(std::string(SPINNER[frame % 10]) + " searching", YELLOW); else status.add(std::string(SPINNER[frame % 10]) + " searching", YELLOW);
box.top(title, status); box.top(title, status);
if (blanks) box.row(Line{}); if (blanks) box.row(Line{});
const Move best = d.pv.empty() ? Move() : d.pv.front(); for (const Line& l : stats(d, inner)) box.row(l);
const std::vector<Line> right = stats(d, stats_width);
for (int i = 0; i < 9; i++) {
Line l;
if (show_board) {
l = i < 8 ? board_row(d.root, 7 - i, best) : board_files();
l.pad_to(BOARD_WIDTH).add(" ");
}
l.append(right[size_t(i)]);
box.row(l);
}
if (blanks) box.row(Line{}); if (blanks) box.row(Line{});
Line pv_title; Line pv_title;
@@ -485,7 +435,7 @@ std::atomic<int>& typed_lines() {
std::string banner(const std::string& name, const std::string& version, const std::string& author) { std::string banner(const std::string& name, const std::string& version, const std::string& author) {
Box box{58, {}}; Box box{58, {}};
Line title; Line title;
title.add("♞ " + name, TITLE).add(" " + version, VALUE); title.add(name, TITLE).add(" " + version, VALUE);
Line right; Line right;
right.add("MCTS chess engine", LABEL); right.add("MCTS chess engine", LABEL);
box.top(title, right); box.top(title, right);