Recommendation for supporting base 16 colors in default dark and light styles including chroma? #376
Replies: 1 comment 3 replies
-
👋 Hey, @andyfeller! Thanks for jotting all this down. There's a lot of good stuff in here. Here are some initial thoughts: As a core feature, Glamour will automatically downsample all colors to the highest supported color profile, including Chroma definitions. So, for example, when Glamour is used in the stock macOS terminal (which supports 256 colors), everything will be downsampled to ANSI256. Similarly, in Linux without a window manager, everything will be downsampled to ANSI16. This means that, given a flag or environment variable, we can totally have Glamour render everything at ANSI16. All that said, we'd love to bundle a simple ANSI16 theme as well. Accessibility aside, many users like it when everything in their terminal uses the same palette (we recently added an ANSI16 theme to Sequin for this reason). We also agree about doubling down on supporting |
Beta Was this translation helpful? Give feedback.
-
As a core maintainer of the GitHub CLI, I'd like to support users with low vision needs by limiting our CLIs to base 16 ANSI colors, which users can configure their terminals to render with sufficient contrast for their personal needs.
Before we get to specifics, please let me say how much I appreciate collaborating with
glamour
maintainers. I'm open to any ideas and suggestions as well as contributing back to the project where possible! 🙇Problems
There are 4 challenges that I'd like to work with the
glamour
maintainers as long time supporters and collaborators so otherglamour
users may benefit:How should CLIs override the default
light
anddark
styles?These styles use various 8-bit colors for markdown elements such a document, headers, links, images, in-line code, and code blocks. In order to minimize how much users have to understand
glamour
and specify a custom glamour style, we want to continue allowingglamour
to respond to user's appearance preferences but use slightly different colors.I'm unsure how
glamour
maintainers expect CLI developers to customize these default styles other than:Hard code overrides for specific, known element styles to use base 16 colors
This approach is a bit brittle as it requires significant diligence on the user's part to monitor changes within the default styles whenever any dependency is updated. This is likely to lead to inconsistent results.
Completely override the
dark
andlight
stylesSomewhat less brittle except for new markdown elements being added to the default styles, this would ensure
glamour
is doing exactly what we expect.Tell users to define their own custom style using
GLAMOUR_STYLE
environment variableThis is absolutely the worst approach from a user friendly, out of the box experience! I'd like to believe none of us want to resort to this option.
How should CLIs override the
terminal256
Chroma formatter for rendering code blocks?glamour
useschroma
to render code blocks, which can support 3-bit, 4-bit, and 8-bit color depths.Unlike the default styles, CLIs cannot easily override the
CodeBlockElement
rendering necessary to customize this behavior without forking the project.Which colors would
glamour
maintainers use to make these styles aesthetically pleasing and sufficiently contrasting?A colleague pointed me to
chalk/ansi-styles
when I was researching how to downsample these 8-bit colors to their nearest base 16 colors. Recognizing there is a deeper rabbit hole regarding color quantization, I don't know if this should be an algorithmic decision or something a designer should weigh in on.See below for collapsed table I used to convert from 8-bit to 4-bit for proof of concept purposes.
Should
glamour
react to the sameACCESSIBLE
env var used byhuh
to default to an accessible experience?Similar to
NO_COLOR
convention`, the terminal community does not have a standard for users to communicate their need for an accessible experience out of the box.I think building upon this foundation will provide a unified experience across
charmbracelet
projects as we continue to support our low vision user needs. 🫶References
Conversion table used for proof of concept from 256 colors to 16 colors
In the following chart, any base 16 color already being used was preserved with color codes
16
and higher being downsampled:Screenshot demonstrating native MacOS Terminal where users can customize ANSI color wells to improve color contrast for personal accessibility needs
Additional note for readers: the
Basic
theme in MacOS Terminal works in conjunction with the Appearance settings in System Preferences, switching to eitherlight
ordark
based on the time of day. Users like myself may set a different theme to be default, which does not adhere to the Appearance setting.Beta Was this translation helpful? Give feedback.
All reactions