Fallback to 256color if COLORTERM != truecolor #604
Merged
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.
Face supports hex color
'#aabbcc'
but some terminal does not support truecolor. (example: macOS Terminal.app)This pull request adds fallback to 256color if
ENV['COLORTERM']
is not'truecolor' | '24bit'
About 256color
0..15
is standard color and high intensity color (this color table is customizable by terminal emulator's config)16..231
is 216 color (r,g,b each 6 steps, 6**3 == 216) This pull request uses this part.232..255
grayscale 24step. This pull request does not use this part event if the specified color is gray.Each R,G,B in 216 color are 6 steps,
[0, 95, 135, 175, 215, 255]
In ruby code, steps are
[0, *95.step(255,40)]
when value > 95, color index can be calculated by
1 + ((value-95)/40.0).round
or in short,(value - 35) / 40
COLORTERM env
Many tools uses
ENV['COLORTERM'] == 'truecolor'
orENV['COLORTERM'] in 'truecolor' | '24bit'
to check if truecolor is supported.https://github.com/search?q=COLORTERM&type=code
Some terminal emulator does not set env COLORTERM even if it supports truecolor. (example: Windows Terminal)
To enable truecolor without COLORTERM env, I added
Reline::Face.force_truecolor