fix: gray levels, half_white, and hardened hex color parsing#25
Merged
Conversation
…lors Add named grays for 4-gray displays: darkgray/dkgray (64) and lightgray/ltgray (191) around the existing gray (127). Fix half_white/hw, which wrongly resolved to mid gray (127) instead of light gray (191). Harden hex parsing for 16-gray and templated values: accept 8-digit #RRGGBBAA and 4-digit #RGBA alpha forms, and strip surrounding whitespace. Centralize named colors into a single NAMED_COLORS mapping. The resolver and the inline text-markup allowlist (COLOR_TOKEN_PATTERN) are both derived from it, so a future named color is added in exactly one place instead of being duplicated across colors.py and text.py.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Cover the named gray ramp (black/dkgray/gray/ltgray/white), the hex grayscale ramp, and inline [dkgray]/[gray]/[ltgray] markup rendered via parse_colors.
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.
Context
From the OpenDisplay
firmware-devDiscord thread (6/22/2026): users running 4-gray / 16-gray e-paper displays (reTerminal E1001, etc.) hit color problems via drawcustom — not enough gray levels, andhalf_whiterendering as mid-gray.Changes
Gray handling (
colors.py)darkgray/dkgray→(64,64,64)andlightgray/ltgray→(191,191,191), giving a clean 4-gray ramp:black → dkgray → gray (127) → ltgray → white.half_white/hw, which was wrongly grouped withhalf_black/grayand resolved to mid-gray(127); it now resolves to light gray(191).Hex hardening (
colors.py)#RRGGBBAAand 4-digit#RGBA(alpha) in addition to the existing 3/6-digit forms." #FF0000 "work.#888888, …); the panel driver quantizes to its nearest level. Nogray0..15constants added (avoids palette/regex bloat).Maintainability
NAMED_COLORSmapping as the source of truth. The resolver does a dict lookup, and the inline text-markup allowlist is derived fromCOLOR_TOKEN_PATTERN— so a future named color is added in one place instead of being duplicated acrosscolors.pyandtext.py. Accent aliases remain special-cased (they resolve dynamically fromaccent_color).Tests
half_whitefix, 4/8-digit + alpha + whitespace hex, and the new inline-markup tags.Out of scope / follow-up
The original "hex replaced with null on
fill:" report is a validation bug in the HA integration's drawcustom schema (OpenEPaperLink/Home_Assistant_Integration), not this library — hex parsing here always worked. That repo's color validator should accept hex forfillthe same as forcolor.