Support for terminal emulators with less colors
AnonymouX47 opened this issue · 0 comments
AnonymouX47 commented
Requires #62
This will be implemented as render methods (and some style-specific parameters) common to all colored text-based render styles, defined by the [Colored]TextImage
(not yet sure if ColoredTextImage
will be a thing) class.
Progress:
- Render methods selection
- Support detection
- Integration into existing text-based render styles
- Style-spcific parameter
- Style-spcific format spec field
- CLI integration
- TUI integration
Initial Idea
NB: These is mostly a raw dump of my thought process at the time I conceived the idea with updates once in a while, so might not be "neat".
[Colored]TextImage
:
-
auto, direct, fbterm_256, xterm_256, ansi and no_color render methods for all text-based styles.
- Determine and store the method equivalent to auto as
_AUTO_METHOD
- The first to be supported in order of quality
- 256 colors have a slightly different escape sequence that uses a pallete index rather than rgb values.
- Determine and store the method equivalent to auto as
-
is_supported(): if any(_is_supported(method) for method in _render_methods)
-
... [See Keep Notes]
-
Style Params:
- grey: bool = False -> Greyscale (only applies to methods other than none)
- threshold_8color: int = 128 -> Any band of a pixel with a value less than the given value is taken to be 0. Otherwise, 1.
- rgb_sep: str = ";" {";", ":"}
Requires updating _get_render_data()
:
- Rename rgb -> pixels
- grey: bool = False
- threshold_8color: int = 128
- color: Optional[str] = "rgb" {rgb, 256color, 8color, None}
- if not color: pixels = None
- elif grey: convert to "L"
- rgb: px = (value,) * 3
- 256:
- 24-scale excludes black and white.
- x = round((value - 1) * 25 / 255) # 26-scale includes black and white
- px = {0: 16, 25: 231}.get(x, 232 - 1 + x) #
-1
because the color after black should be index 0
- 8: px = 7 if value >= threshold else 0
- else:
- rgb: px = (r,g,b)
- 256: 0 <= r, g, b <= 5 -> px = 16 + 36 * round(r * 5 / 255) + 6 * round(g * 5 / 255) + round(b * 5 / 255)
- Each of r,g,b must be scaled down from 256-scale to 6-scale: x =
round(x * 5 / 255)
- r,g,b in 6-scale are basically the digits of the 216-palette index in base 6
- Convert to base 10 to get the 216-palette index: x =
r * 36 + g * 6 + b
- offset by +16 to get the 256-palette index:
16 + x
- Each of r,g,b must be scaled down from 256-scale to 6-scale: x =
- 8: 0 <= r, g, b <= 1 -> px = (r >= threshold) << 2 | (g >= threshold) << 1 | (b >= threshold)
Known Issues:
- For text-based styles, On Kitty, cell BG colors that are equal to the default BG color take the form of the background (I.e might be translucent or blended with a background image).
- This is overcome in the RGB method by slightly manipulating the pixel color (done in #54) but can still occur with 265color or 8color method, as fixing it in these modes will require modifying either the pallete entries or the default BG color, which is generally not desired behavior.
Any suggestions are always welcome. 😃