Fix xterm-256 color table: wrong cube count and missing grayscale entries#3043
Merged
birkenfeld merged 1 commit intopygments:masterfrom Feb 20, 2026
Merged
Conversation
…ries The color cube loop used range(217) instead of range(216), generating one extra entry (6x6x6 = 216, not 217). The grayscale loop used range(1, 22) generating only 21 entries instead of the correct 24 (colors 232-255). Total was 16 + 217 + 21 = 254 instead of 16 + 216 + 24 = 256. The extra cube entry shifted all grayscale indices by one, and the three missing grayscale values caused wrong color matching for lighter grays. Also update _closest_color to iterate range(256) instead of range(254).
Member
|
LGTM, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The xterm-256 color table in
Terminal256Formatterhas two off-by-one errors:Color cube:
range(217)generates 217 entries instead of 216 (6x6x6 = 216). The extra entry at index 232 contains(0,0,0)(black) instead of the correct grayscale start.Grayscale ramp:
range(1, 22)generates only 21 entries instead of the correct 24 (colors 232-255). Three grayscale values are missing entirely.Total entries: 16 + 217 + 21 = 254 instead of the correct 256. The extra cube entry shifts all grayscale indices by one, and the missing entries cause wrong color matching for grays.
Additionally,
_closest_coloriteratesrange(0, 254)which doesn't cover all entries.Fix
range(216)range(24)range(256)