fix: quantize colors in environments without true color support#36
Merged
Norbert515 merged 2 commits intoNorbert515:mainfrom Jan 25, 2026
Merged
fix: quantize colors in environments without true color support#36Norbert515 merged 2 commits intoNorbert515:mainfrom
Norbert515 merged 2 commits intoNorbert515:mainfrom
Conversation
Remove extra blank line after HSVColor class to satisfy dart format.
Owner
Contributor
Author
|
I'm going to look into this because none of my settings seemed to affect it. Maybe it's something in my .zshrc file. I'll report back once I narrow it down. |
Contributor
Author
|
Okay, it's not anything in my .zshrc file. It might be that I customized some colors at some point (I vaguely recall doing that) and that almost certainly changes how Apple's terminal does the color quantization. Still, it may be beneficial to do the color quantization here in the library for the most consistent results. |
Owner
|
Yes, I agree! I just wanted to double check that I'd be able to reproduce the issue. Nonetheless, PR looks good and you got tests & verified to works for you so that should be enough! |
Contributor
Author
|
Thank you! Was fun to learn about this! |
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.

This is a very neat library. Thank you for making it!
I noticed that colors were wildly off in the macOS terminal (mine was set to xterm-256), even though it looked fine in the VSCode terminal. So, I used an AI (codex) to diagnose and make this change + some human cleanup.
This change makes an attempt to detect if we're in a terminal that does not support true color. If the terminal does not support true color, it will attempt to quantize the color to the nearest 256 colors. I suppose this is not necessarily useful for environments with less than 256 colors...but I'm unaware of how to detect support for even more restricted environments.
From my testing, these changes seem to work well in both light and dark mode in the macOS terminal.
The color computations and detection are cached to avoid slowing down the rendering hot-path any more than necessary.
Dark
Before:

After:

Light
Before:

After:

Gruvbox Dark
Before:

After:

Catpuccin Mocha
Before:

After:

Nord
Before:

After:

Dracula
Before:

After:
