Skip to content

fix(formatters): break TTY colour distance ties deterministically - #1527

Merged
alecthomas merged 1 commit into
alecthomas:masterfrom
danrneal:fix/tty-indexed-deterministic-tiebreak
Nov 22, 2026
Merged

alecthomas merged 1 commit into
alecthomas:masterfrom
danrneal:fix/tty-indexed-deterministic-tiebreak

Conversation

@danrneal

@danrneal danrneal commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

When a style colour is equidistant from two indexed TTY palette entries, Go's randomized map iteration over table.foreground makes the chosen ANSI escape code non-deterministic across runs. For example, #2ac3de (used in tokyonight-night and tokyonight-storm) is equidistant from xterm indices 38 (#00afd7) and 44 (#00d7d7) in ttyTables[256], causing terminal256 output to flip non-deterministically between the two codes.

Break equal-distance ties by preferring the smaller chroma.Colour value (colour < closestColour). Extract findClosestColour over iter.Seq[chroma.Colour] so unit tests verify both candidate orderings deterministically alongside findClosest(ttyTables[256], ...).

When a style colour is equidistant from two indexed TTY palette entries, Go's randomized map iteration over `table.foreground` makes the chosen ANSI escape code non-deterministic across runs. For example, `#2ac3de` (used in `tokyonight-night` and `tokyonight-storm`) is equidistant from xterm indices 38 (`#00afd7`) and 44 (`#00d7d7`) in `ttyTables[256]`, causing `terminal256` output to flip non-deterministically between the two codes.

Break equal-distance ties by preferring the smaller `chroma.Colour` value (`colour < closestColour`). Extract `findClosestColour` over `iter.Seq[chroma.Colour]` so unit tests verify both candidate orderings deterministically alongside `findClosest(ttyTables[256], ...)`.
@danrneal
danrneal force-pushed the fix/tty-indexed-deterministic-tiebreak branch from cec0b84 to d9f6b87 Compare November 22, 2026 04:06
@danrneal danrneal changed the title fix(formatters): break colour distance ties deterministically in findClosest fix(formatters): break TTY colour distance ties deterministically Nov 22, 2026
@alecthomas
alecthomas merged commit 07b0944 into alecthomas:master Nov 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants