Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci

on:
push:
pull_request:

jobs:
test:
strategy:
fail-fast: false # a failure on one system doesn't cancel the others
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
# Stockfish, so the analysis test runs against the real engine (it's
# skipped where Stockfish is missing, so a failed install isn't fatal)
- name: Install Stockfish (Linux)
if: runner.os == 'Linux'
continue-on-error: true
run: sudo apt-get update && sudo apt-get install -y stockfish
- name: Install Stockfish (macOS)
if: runner.os == 'macOS'
continue-on-error: true
run: brew install stockfish
- name: Install Stockfish (Windows)
if: runner.os == 'Windows'
continue-on-error: true
run: choco install stockfish -y --no-progress
- run: go vet ./...
- run: go test -race ./...
if: runner.os != 'Windows'
- run: go test ./...
if: runner.os == 'Windows'
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: release

on:
push:
tags: ["v*"]

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 changes: 30 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Builds release binaries when a version tag (e.g. v0.2.0) is pushed.
# Test locally with: goreleaser release --snapshot --clean
version: 2
project_name: chess-cli

builds:
- env:
- CGO_ENABLED=0
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
ldflags:
- -s -w -X main.version={{.Version}}

archives:
- formats: [tar.gz]
format_overrides:
- goos: windows
formats: [zip]
files:
- README.md
- LICENSE.md

checksum:
name_template: checksums.txt

changelog:
sort: asc
filters:
exclude:
- "^Merge "
183 changes: 140 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,181 @@
<h1 align='center'>chess-cli ♟️</h1>
<p align="center">
<b>A chess tui app written in Go.</b><br/>
<sub>Play locally with a friend or online with Lichess!</a></sub>
<sub>Play locally with a friend or online with Lichess!</sub>
</p>
<br />

<p align="center">♞♞♞♞♞♞♞♞♞♞♞</p>

chess-cli is a tui (terminal user interface) that allows you to play chess, both offline with a friend or online as a Lichess api client.



![home](https://user-images.githubusercontent.com/57846867/182972093-c9917d32-81c3-4ba5-a6ec-a783bf254f33.png)
![game](https://user-images.githubusercontent.com/42559123/183780181-a4cb62c0-8515-4371-8406-932e11e84f77.png)


<p align="center">♞♞♞♞♞♞♞♞♞♞♞</p>

# Features
# Install


- Mouse input support
- Displays move history
- UCI chess notation input
- Saving and restoring local games
- Lichess features:
- Lichess login w/ oauth
- Lichess challenge request for real time, unlimited, or correspondence games, with all variants and options supported
- Challenge a friend or a random player
- Play against the stockfish AI
- Join ongoing games
- Join from your incoming challenges
**Download a binary** for Linux, macOS or Windows from the
[releases page](https://github.com/nate-xyz/chess-cli/releases), unpack it and
run `chess-cli`.

**Or install with Go** (1.24+):

```sh
go install github.com/nate-xyz/chess-cli@latest
```

**Or build from source:**

```sh
git clone https://github.com/nate-xyz/chess-cli
cd chess-cli
go run . # or: go build -o chess-cli . && ./chess-cli
```

<p align="center">♞♞♞♞♞♞♞♞♞♞♞</p>
A terminal with true colour and a font with the Unicode chess symbols gives the
best result. The board scales with your terminal, so make it big.

### How the board looks

Choose under **Options** on the home screen:

| Rendering | What you get | Where |
|---|---|---|
| **Image** | Lichess boards and piece sets as real images, scaled to the board. 12 piece sets and 6 boards, previewed as you pick | terminals with the [kitty graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/): kitty, Ghostty, WezTerm |
| **Advanced** | Unicode chess symbols, drawn big with kitty's [text sizing protocol](https://sw.kovidgoyal.net/kitty/text-sizing-protocol/) where available | everywhere; big in kitty 0.40+ |
| **Basic** | Plain symbols in the terminal's 8 standard colours, like the original chess-cli | any terminal, including old ones |

Support is detected at startup (image rendering falls back to advanced where
images aren't supported, e.g. inside tmux). `CHESS_CLI_IMAGES=0/1` and
`CHESS_CLI_BIG_PIECES=0/1` override the detection.

Options also has:

- **Move box**: typed-move box always shown, or only on `Ctrl-K`
- **Clock bar**: clocks as a bar beside the board, or plain text in the sidebar
- **Zen mode**: hides names, ratings, chat and game info during games, like
Lichess's zen mode
- **Sound**: Retro (chiptune) or Wood, or off. chess-cli's own sounds,
played with your system's player (`pw-play`, `paplay` or `aplay` on Linux,
`afplay` on macOS, built in on Windows)

# Playing

| | |
|---|---|
| **Mouse** | Click a piece, then click where it should go. Legal moves are dotted, captures marked. |
| **Typing** | `Ctrl-K` opens the move box: UCI (`e2e4`) or standard notation (`Nf3`, `exd5`, `O-O`). Promotions need the piece: `e7e8=Q`, `e8=Q` or `e7e8q`. |
| **Keyboard on the board** | Arrows or `hjkl` move the cursor, `Enter`/`Space` selects, `Esc` cancels, `Tab` goes to the menu. |
| **Going back** | Click a move in the move list, scroll the mouse wheel on the board, or `[` `]` (`Home`/`End` for the start/now). Click the board to return. Works on the game-over screen too. |
| **Drawing** | Right-click a square for a circle, right-drag for an arrow; `Shift` red, `Alt` blue, both yellow. Left-click clears. |
| **Promotion** | A picker opens over the promotion square: click a piece, or press `q` `r` `b` `n`. |
| **Online chat** | `Tab` cycles board → chat → menu. |

Local games are two players on one keyboard; the board flips each move. Games
can be saved and resumed.

# Puzzles

*Puzzles* on the home screen: the **daily puzzle**, or **puzzle training**
(new puzzles one after another, five difficulty levels relative to your
rating). **Rated** puzzles update your Lichess puzzle rating and need a login;
**casual** ones work without. Hints, solutions and themes as on Lichess.

# Watching, studies and news

### dependency documentation:
Once you've logged in to Lichess, the home screen also has:

https://lichess.org/api for lichess
- **Watch**: Lichess TV channels (top rated, bullet, blitz, rapid, classical,
Chess960, bots, computer), a player's current game, or any game by link or
ID. Live clocks and moves; scroll back through the game as usual.
- **Studies**: your Lichess studies (private ones too) or any study by link.
Chapters, variations, comments and the study's arrows and circles. `←` `→`
step through the moves, `↑` `↓` jump to the start/end, click any move
(in a variation too) to go there.
- **Chess news**: elite events Lichess is broadcasting (live, coming up, just
finished, with leaders and winners) and the latest Lichess blog posts.

https://pkg.go.dev/github.com/notnil/chess chess lib
Without a login chess-cli doesn't contact Lichess at all (casual puzzles
aside, which you choose explicitly).

https://docs.rocketnine.space/code.rocketnine.space/tslocum/cview/ cview
# Lichess

https://code.rocketnine.space/tslocum/cview/src/branch/master/demos cview demos
Choose *Lichess* on the home screen and log in through your browser (if it
doesn't open, the link is shown in the app). chess-cli uses the
[Lichess Board API](https://lichess.org/api#tag/board):

https://pkg.go.dev/net/http
- Challenge a friend, seek a random opponent, or play Lichess's Stockfish (levels 1–8)
- All variants, rated or casual, real-time, correspondence or unlimited
- Resume ongoing games; accept, decline (`d`) and cancel challenges
- Chat, draw offers, takebacks, resign/abort
- Claim victory or a draw when your opponent leaves
- Rematch from the game-over screen
- `Esc` on the waiting screen withdraws your challenge or seek

https://mholt.github.io/json-to-go/
**Time controls:** Lichess only allows Rapid, Classical and Correspondence
through the Board API, plus Blitz for direct challenges and games against the AI.
Bullet isn't available to third-party clients.

Only one chess-cli runs at a time; a second copy tells you one is already
running.

Your Lichess token and saved games are kept in `~/.config/chess-cli`
(`chess-cli --help` prints the exact folder on your system).

<p align="center">♞♞♞♞♞♞♞♞♞♞♞</p>

### todo:
# Development

```sh
go test -race ./...
```

The tests include an end-to-end online game: the real UI running on tcell's
mock terminal against a fake Lichess server.

#### general
**Releasing:** push a version tag and GitHub Actions builds and publishes the
binaries with [GoReleaser](https://goreleaser.com):

- Handle all notation types or choose notation to start
#### local client
```sh
git tag v0.2.0 && git push origin v0.2.0
```

- add time options

#### oauth
### Credits

- handle if oauth rejected mid process
Piece sets come from [Lichess](https://github.com/lichess-org/lila); each
keeps its own licence (GPL, MIT, Apache, CC0, CC BY, CC BY-SA). See
[pkg/assets/pieces](pkg/assets/pieces/README.md).

#### online
### Dependency documentation

- [Lichess API](https://lichess.org/api)
- [notnil/chess](https://pkg.go.dev/github.com/notnil/chess): rules and move generation
- [cview](https://pkg.go.dev/codeberg.org/tslocum/cview): TUI widgets
- [tcell](https://pkg.go.dev/github.com/gdamore/tcell/v3): terminal handling

- exit option on loader
- challenge construction
- set default interval position for sliders
- custom starting position option for challenges
- client
- chat
- rematch option post game

<p align="center">♞♞♞♞♞♞♞♞♞♞♞</p>

### Todo

#### general

- Sixel support for image rendering (foot, Konsole, xterm, Windows Terminal)

#### local client

- Save clock times with saved games
- Stockfish analysis of a finished game

#### online

- Challenge construction
- Set default positions for sliders
- Custom starting position
- Puzzle themes, opening explorer, game history/PGN export
- Variants: the board follows standard chess rules only. Games in variants
like crazyhouse or atomic can be created but the app can't follow them yet;
Chess960 is untested.

<p align="center">♞♞♞♞♞♞♞♞♞♞♞</p>
Loading
Loading