Skip to content

Chess cli v2 - #12

Merged
nate-xyz merged 14 commits into
mainfrom
chess-cli-v2
Nov 17, 2026
Merged

nate-xyz merged 14 commits into
mainfrom
chess-cli-v2

Conversation

@hfwitte

@hfwitte hfwitte commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Since f108262 (a76dae4, 5f86be9, c218e47, 517bb9d)

New

  • Added dynamic UI elements that affect layout based on terminal size
  • Changed how very large and very small terminals are handled
  • First time launch asks preference of hjkl/arrow movement
  • Added post game eval with local Stockfish
  • First time launch will look for local Stockfish, offer to install
  • Added a --reset flag to clear saved preferences
  • Image rendering: real Lichess boards and piece images, drawn with the kitty
    graphics protocol (kitty, Ghostty, WezTerm). Pieces are scaled to the exact
    square size, so they stay sharp at any terminal size.
  • 12 piece sets (cburnett, merida, mpchess, chessnut, fantasy, spatial,
    celtic, kiwen-suwi, totoy, papercut, rhosgfx, shapes) and 6 board colours
    (brown, blue, green, purple, ic, grey). Only sets whose licences allow them
    in a GPLv3 program; each keeps its SVG source and licence in
    pkg/assets/pieces/.
  • Three rendering modes, chosen in Options:
    Image rendering - Lichess boards and pieces as pictures
    Advanced rendering - Unicode chess symbols, drawn big in kitty
    Basic rendering - plain symbols in 8 standard colours, any terminal
    (like the original chess-cli)
  • First-run screen: detects your terminal and what it supports, recommends a
    rendering mode, previews each one live. This can be changed in Options.
  • Options screen, with live preview for rendering mode, piece set and board.
  • Puzzles: daily puzzle and puzzle training (5 difficulty levels), rated or
    casual like Lichess. Hint, view solution, themes. Rated needs a Lichess
    login; casual works without.
  • Watch games: Lichess TV channels (top rated, bullet, blitz, rapid,
    classical, Chess960, bots, computer), a player's current game, or any game
    by link/ID. Live clocks and move list; TV fills in the moves from before
    you joined. Only shown when logged in to Lichess.
  • Chess news on the home screen: elite events Lichess is broadcasting (live,
    coming up, recently finished, with leader/winner) and the latest Lichess
    blog posts. Only fetched when logged in. The last news is saved, so it
    shows instantly at startup while fresh news loads; the panel only changes
    if the news did. Refreshes every 15 minutes after that.
  • Step back through a game: mouse wheel on the board, or [ ] (Home/End for
    start/now). Click to come back.
  • Draw on the board like Lichess: right-click a square for a circle,
    right-drag for an arrow; Shift red, Alt blue, Shift+Alt yellow; left-click
    clears.
  • Ctrl-K opens the move box (type e4, Nf3, e7e8=Q...). Option to keep the
    move box always shown instead.
  • Only one chess-cli runs at a time: a second copy says it's already running
    and exits (so two copies can't fight over the Lichess stream or config).
  • Play local Stockfish (Local menu): levels 1-8, play white/black/random,
    offline. If Stockfish isn't installed: download the official release from
    GitHub (checksum-verified, kept in chess-cli's folder, no admin rights),
    point chess-cli at your own Stockfish, or see the install command for your
    system.
  • Clocks beside the board, above and below it next to each player: the
    time, a braille-dot bar (gold for time left, grey as it's used; brighter
    gold for the running clock) and the time control at the other end
    ("10+5", "∞ Unlimited", "Correspondence · 3 days"). In watched, online and
    local games. Option to turn the bar off (clocks go back to the sidebar).
  • Clocks for local games and Stockfish games: none, 1+0, 3+0, 3+2, 5+0, 5+3,
    10+0, 10+5, 15+10, 30+0, 30+20, 45+15, 60+30, 90+30, 120+30, and FIDE
    classical (90 min for 40 moves, +30 min after move 40, 30 s per move from
    move 1). Clock in the Local / Stockfish menus. Running out loses on time.
  • Zen mode (Options), like Lichess: hides names, ratings, chat and game info
    during games and while watching.
  • Game results on the board, like Lichess: green crown on the winner's king,
    red # on a checkmated king, red flag for resignation/time, grey = for a
    draw. The result ("0-1 · Black wins by checkmate") shows beside the board.
    In local, Stockfish, online and watched games.
  • Studies (home screen, when logged in): your Lichess studies, private ones
    too, or any study by link. Chapters listed in the sidebar; the moves with
    variations (indented, in brackets), comments and symbols (!?, ⩲ ...). The
    study's arrows and circles are drawn on the board, and its orientation is
    used. Left/right arrows (or the wheel, [ ]) step along the line, up/down
    jump to the start/end; click any move, in a variation too, to go there.
    f flips the board. Read-only for now. Uses the study:read permission the
    login already asks for, so no new login needed.
    Moves and chapters each sit in a thin grey box; chapters are numbered.
    The move showing has a dark grey background; its comment gets a faint
    green one and the side lines that branch off at it are underlined, so
    you can see what the text is talking about. Lines nested inside them get
    heavier underlines the deeper they go: solid, dashed, dotted, double,
    curly (the terminal's underline styles; kitty, Ghostty, WezTerm and
    others draw them, other terminals show a plain underline). The
    underline is a dim grey so it doesn't crowd the moves. [Not sure about this underline UI - may remove.]
    Move symbols show on the board like Lichess: a coloured badge on the
    destination square (! green, !! dark green, ? orange, ?? red, !? pink,
    ?! blue), and in the same colours in the move list. Position and idea
    symbols too (=, ∞, ±, ⩲, +−, N, ↑↑, ↑, →, ⇆, ⊕ time trouble, =∞, ∆, □,
    ⨀), as on Lichess.
  • Study tags: under the chapter title, the game's details (place, date,
    round, time control, opening, annotator). Each player beside the board,
    above and below it as on Lichess: title in orange, name, rating, and
    their result at the other end. The game's result ends the move list:
    "1–0" and e.g. "Checkmate • White is victorious" (checkmate and stalemate
    read from the final position, time forfeit etc. from the Termination tag).
  • Click a move in the move list to see the position after it; the move the
    board is showing is highlighted (follows the mouse wheel and [ ] too). In
    local, Stockfish, online, watched and puzzle games and on game-over
    screens.
  • Sound, chess-cli's own (synthesised in the program, no audio files or
    licences): Retro (chiptune blips, the default) or Wood (a soft
    piece-on-board click), or off. Moves, captures, checks, castling, game
    start, win/loss/draw, low time (under 10 s, once per side), illegal or
    wrong moves, puzzle right/solved, and stepping through studies. Played
    with the system's player (pw-play, paplay or aplay on Linux, afplay on
    macOS, built-in PlaySound on Windows), so builds stay static. Options:
    Sound: Retro / Wood / Off (plays a sample). The first-run screen asks
    about sound after the rendering choice, previewing each; people
    upgrading are asked once.
  • A king in check (or checkmated) glows red, like Lichess: the same radial
    gradient behind the piece with image rendering, a red-tinted square with
    advanced rendering, a red square with basic rendering. Also while
    stepping back through a game and in studies.

Changed

  • Game-over screens (local and online) use the new game layout: the final
    board, big, on the right with its result marks and final clocks; players,
    result, move list and menu in the sidebar. Step back through the finished
    game as during play.
  • New game screen layout: board as big as the window allows, against the
    right edge; players, clocks, moves, chat and menu in a sidebar on the left.
  • Move list in standard notation, numbered in pairs (1. e4 e5 2. Nf3 ...).
  • Menus highlight the item under the mouse.
  • The "valid moves" list is gone (legal moves are dotted on the board).
  • Home screen goes back to the main menu when you return to it.
  • Bottom ribbon lists each screen's shortcuts.

Fixed

  • Security: text from Lichess (chat, names, blog titles, error messages) is
    stripped of control characters before display, so it can't inject terminal
    escape sequences; Unicode direction-override characters removed too.
  • Security: usernames and game IDs typed into the app are checked before they
    go into a Lichess request URL.
  • Logging in again (e.g. for rated puzzles) no longer wipes your settings.
  • Settings saved from the background login can't clash with settings being
    changed in the UI (data race).
  • After Lichess rejected a token, logging in again didn't restart the
    account event stream (incoming challenges and game starts went unnoticed).
  • Challenge form: the time sliders now open at the value that will be sent
    (they showed 15 s while sending your previous choice), and default to 10+0
    instead of a bullet control Lichess rejects.
  • Clocks and TV no longer redraw the screen several times a second while
    their screen isn't showing.
  • Watching: clocks didn't run when you joined a game in progress.
  • Scrollbar next to the board (looked like an eval bar) removed.
  • Test suite: race between UI tests; tests never touch your real config.
  • Basic rendering / old terminals: with basic rendering, or a terminal with
    fewer than 256 colours, the UI sticks to the standard colours: current
    move in silver (the dark grey would be black on black), silver box
    borders, no dark tints, plain underlines only (old terminals can misread
    styled ones), player titles and clock labels in standard colours. Move
    symbols on the board use the 8 standard colours. With kitty's big
    pieces the symbol shows in the move list only (the piece fills the
    square). Tested in each mode.
  • Study header (title and tags) could be cut off when the tags wrapped onto
    many lines; it's now measured properly and refits when the window is
    resized.
  • Box titles showed a grey block after the text in some terminals.
  • Hovering over a long list (e.g. study chapters) left it scrolled to where
    the mouse had been, hiding the current item.
  • Comments containing square brackets (e.g. "[11...dxe5 12. dxe5]") showed
    a stray "[]" when the line wrapped inside them.
  • CI on Windows: tests no longer check Unix file permissions there (Windows
    has none), and the terminal's colour count is read once per frame from
    the app's own screen, not on every board draw (in tests, standalone
    boards triggered redraws of the test app, which leaked into another
    test's output). Big pieces (kitty text sizing) now keep track of what's
    on each screen separately, so a board drawn on one screen can't make
    another erase and redraw its pieces.
  • CI: a failure on one system no longer cancels the other two (so all three
    results show); updated to actions/checkout@v5 and actions/setup-go@v6
    (the old ones ran on Node 20, which GitHub is retiring).
  • Tests for the FIDE control's +30 min after each side's 40th move.
  • Fix: black pawns shown sideways in advanced rendering (non-kitty terminals)
  • Fixed keyboard navigation menu
  • Made Auth page prettier
  • Fixed some text wrapping (text was cutting off, even with appropriately large terminal size)
  • Fixed lingering keyboard cursor when using mouse movement

Big Unicode pieces in kitty (f82c27a, f108262)

  • Pieces scale up with the board in kitty 0.40+ (kitty text sizing
    protocol), centred in their squares. Detected at startup;
    CHESS_CLI_BIG_PIECES=0/1 overrides.
  • Type moves in standard notation too: Nf3, exd5, O-O / 0-0, e8=Q (as well as
    UCI e2e4).
  • Clearer message when a typed move isn't legal.
  • Quote on the home screen wraps with padding.

Releases and CI (c013c59)

  • Prebuilt binaries for Linux, macOS and Windows, each for amd64 (Intel/AMD)
    and arm64 (Apple Silicon, Raspberry Pi, ARM laptops): six downloads per
    release, so people can play without installing Go. Pushing a version tag
    (e.g. v0.2.0) starts the release workflow (.github/workflows/release.yml),
    which runs GoReleaser (.goreleaser.yaml): it builds all six with
    CGO_ENABLED=0 (static, no system libraries needed), stamps the version
    into the binary (chess-cli --version), packs each as a .tar.gz (.zip for
    Windows) with README and licence, writes checksums.txt (SHA-256) and
    publishes them as a GitHub Release with notes made from the commit
    messages since the last tag. Try it locally first with
    goreleaser release --snapshot --clean (builds into dist/, publishes
    nothing).
  • go install github.com/nate-xyz/chess-cli@latest works.
  • CI: vet and race tests on Linux, macOS and Windows.
  • chess-cli --version / --help.
  • README rewritten.

Lichess rework (7fb52a9)

  • Login happens in the background through the browser (no more hang); the
    link is shown if the browser doesn't open. Token saved in
    ~/.config/chess-cli with private permissions.
  • Event stream reconnects automatically; no more crashes on network errors.
  • Chat in online games (Tab to switch to it).
  • Rematch from the game-over screen.
  • Claim victory or a draw when the opponent leaves.
  • Accept, decline and cancel challenges; Esc withdraws a pending
    challenge/seek.
  • Draw and takeback offers show reliably (one popup at a time).
  • Fixed: seeks used the wrong time setting; accepting a challenge that failed
    still opened the game; CPU busy-loop while waiting; saved games now in the
    config folder.

Promotion picker (00df152)

  • Choosing a promotion piece: a Q/N/R/B column opens over the square; click
    or press q/r/b/n; Esc cancels.

Scalable board (64f55c2)

  • The board scales with the terminal.
  • Shows your Lichess username only (no email permission requested).
  • Fixed: board missing on the local game-over screen.

Earlier

- New BoardView primitive replaces the fixed-size cv.Table board. Squares
  scale to the available space and redraw on terminal resize; pieces render
  as half-block pixel art at larger sizes, glyphs when small.
- Mouse click-to-move kept (click doesn't steal focus from the move input);
  keyboard cursor via Tab + arrows/hjkl + Enter. Legal targets, selection,
  captures and last move are highlighted. Promotions by mouse now work
  (auto-queen) - previously impossible.
- Online: only your own pieces are selectable, on your turn.
- Fix: local post-game screen drew onto the online post-game board.
- Lichess: 'Logged in as' shows username only; stop requesting email:read.
- Tests for geometry, square mapping and click-to-move.
Replaces auto-queen. A Lichess-style column of the four pieces opens over
the promotion square (the rest of the board dims); click one or press
q/r/b/n, Esc or a click elsewhere cancels. Works with the board flipped.
Selection/picker are dropped when the position changes underneath them.
Stability
- One HTTP helper for every API call: timeouts, bodies always closed,
  Lichess error messages surfaced ("Not your turn") instead of raw codes.
  No more log.Fatal/os.Exit on network errors.
- Account event stream reconnects with backoff; game stream reconnects
  (Lichess resends full state) and is cancelled when you leave a game.
- All online game state is now changed only on the UI goroutine; network
  calls (moves, accept, resign...) no longer block the UI. Tests pass
  under -race.
- Removed a busy loop on the loading screen that pinned a CPU core.
- Single reader for account events (two goroutines raced for them).

Login and storage
- Login runs in the background: UI stays responsive, the login URL is
  shown in case the browser doesn't open, "Cancel" on Lichess and closing
  the tab (5 min timeout) are handled, OAuth state is checked, and a
  revoked token triggers a fresh login. Expiry comes from Lichess.
- Token and saved games move to ~/.config/chess-cli (0600) instead of
  the working directory; old files are migrated (the world-readable
  legacy token file is removed after migration).

Bugs fixed
- Random-opponent seeks with a clock sent challenge params (clock.limit)
  instead of the seek's time (minutes)/increment.
- Challenges were sent with keepAliveStream but the app read the whole
  response, so it only learned its challenge id once the game started.
  It now reads the id immediately and keeps the challenge alive.
- Draw/takeback offers never showed for usernames with capitals (name vs
  lower-case id); offer popups no longer stack on repeated updates.
- Challenges list kept stale ids between visits (empty list, wrong game).
- Accepting a challenge opened the game even when the accept failed.
- Post-game board is shown from your side.

Features
- Loading screen: Esc cancels the challenge/seek on Lichess.
- In-game chat panel (history loaded on join), Tab cycles move input,
  board and chat.
- Claim victory/draw when the opponent leaves (with countdown).
- Rematch from the post-game screen (same settings, colours swapped;
  same level vs the AI).
- Challenges screen: decline incoming (d), cancel outgoing (Enter).
- Typed promotions without a piece get a hint (e7e8 -> e7e8q).
- Abort is only offered while Lichess allows it.

Tests: API layer against a fake Lichess (errors, challenge keep-alive and
cancel, seek params, game stream events, OAuth success/cancel/forged
state, legacy config migration) and an end-to-end online game driving
the real UI on tcell's mock terminal (mouse moves, opponent reply, draw
offer, chat, opponent leaving, resignation, rematch).
- GoReleaser config: Linux/macOS/Windows x amd64/arm64 archives with
  checksums, built when a v* tag is pushed (release workflow). Verified
  with a local snapshot build.
- CI workflow: vet + tests (race detector on Linux/macOS) on all three OSes.
- Import cview from codeberg.org directly (same v1.6.3) and drop the
  replace directives, which made `go install ...@latest` impossible.
- Drop the leftover tcell v1 encoding import; use tcell v3's.
- `--version` (set at release time) and `--help` (shows the config dir).
- README: install/run instructions, controls, Lichess features and the
  Board API time-control limits, where files live, development/release
  notes, updated todo list.
- Pieces are drawn with kitty's text sizing protocol: the terminal renders
  the Unicode glyphs scaled to fill each square (squares are 2s x s cells,
  s = 1..7). The board's cells are locked in tcell (tcell won't draw over
  them) and the multicell pieces are sent after each frame, only when the
  board changed; they're erased when the board leaves the screen.
- Support is detected at startup with the spec's cursor-position probe, so
  any terminal that implements the protocol gets big pieces; tmux and
  others fall back to normal glyphs. CHESS_CLI_BIG_PIECES=0/1 overrides.
- Removed the half-block pixel-art pieces.
- Move input accepts standard algebraic (Nf3, exd5, e8=Q, O-O / 0-0),
  long algebraic, and UCI with a promotion marker (e7e8=N) as well as
  plain UCI; promotions typed without a piece get a hint.
- Fix: typed-move errors in online games went to the local game's status.
- Welcome quote gets padding and word wrap.
- README: which terminals get big pieces, notation, todo.
kitty measures text by its width in the main monospace font, which has no
chess symbols, so a centred piece had its left edge at the square's centre.
Sending each piece with a trailing space gives kitty a width close to the
glyph's, centring it (verified in kitty 0.45 at scales 3 and 6).

Move dots use ⬤ instead of ●: kitty draws ● with its built-in shape
renderer and tiled it across the square.
@hfwitte
hfwitte requested a review from nate-xyz November 15, 2026 23:13
@hfwitte hfwitte self-assigned this Nov 15, 2026
@hfwitte hfwitte added the enhancement New feature or request label Nov 15, 2026
@nate-xyz

Copy link
Copy Markdown
Owner

lgtm

@nate-xyz
nate-xyz merged commit 98e3612 into main Nov 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants