Skip to content

fix: quantize colors in environments without true color support#36

Merged
Norbert515 merged 2 commits intoNorbert515:mainfrom
jolexxa:fix/color-fallback
Jan 25, 2026
Merged

fix: quantize colors in environments without true color support#36
Norbert515 merged 2 commits intoNorbert515:mainfrom
jolexxa:fix/color-fallback

Conversation

@jolexxa
Copy link
Contributor

@jolexxa jolexxa commented Jan 24, 2026

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:
Screenshot 2026-01-24 at 2 33 43 AM

After:
Screenshot 2026-01-24 at 2 34 14 AM

Light

Before:
Screenshot 2026-01-24 at 2 33 45 AM

After:
Screenshot 2026-01-24 at 2 34 15 AM

Gruvbox Dark

Before:
Screenshot 2026-01-24 at 2 33 54 AM

After:
Screenshot 2026-01-24 at 2 34 21 AM

Catpuccin Mocha

Before:
Screenshot 2026-01-24 at 2 33 51 AM

After:
Screenshot 2026-01-24 at 2 34 20 AM

Nord

Before:
Screenshot 2026-01-24 at 2 33 48 AM

After:
Screenshot 2026-01-24 at 2 34 17 AM

Dracula

Before:
Screenshot 2026-01-24 at 2 33 49 AM

After:
Screenshot 2026-01-24 at 2 34 18 AM

jolexxa and others added 2 commits January 24, 2026 02:26
Remove extra blank line after HSVColor class to satisfy dart format.
@Norbert515
Copy link
Owner

Screenshot 2026-01-24 at 4 52 47 PM

PR looks good, I'm just trying to reproduce the broken state. I'm running the MacOS default terminal without these changes and the example/theme_showcase.dart seems to be working correclty for me. Any idea what is different in your setup?

@jolexxa
Copy link
Contributor Author

jolexxa commented Jan 24, 2026

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.

@jolexxa
Copy link
Contributor Author

jolexxa commented Jan 24, 2026

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.

@Norbert515
Copy link
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!

@Norbert515 Norbert515 merged commit 4ea0ef5 into Norbert515:main Jan 25, 2026
3 checks passed
@jolexxa
Copy link
Contributor Author

jolexxa commented Jan 25, 2026

Thank you! Was fun to learn about this!

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