Repository navigation
v4.2.0: Grace for degradation!
This version adds graceful color degradation, which (to my knowledge), makes us one of the first terminal libraries to do so, but definitely the first in our specific niche!
This is all done automatically, using the newly-rehomed Terminal class and its instance. Essentially, every time a color is created through TIM, the new str_to_color method is called, which will by default localize all output colors. During this localization the xterm-standard HEX value for the given color is found, and that is then used to create a new color in the terminal's color space.
For example, lets say you have an RGB color of 000;111;222, but your terminal only supports the xterm-256 palette. PyTermGUI will, under the hood, determine the RGB value of this color, and get the weighted difference between it and and all known palette colors. Once that is done it will find the closest match, create an IndexedColor with the newly found index and return that back to TIM.
Now this all sounds very computationally complicated, which it is. Thus, there are a couple of simple "caches" inside the new colors module. The first one caches all input given to str_to_color with its corresponding output, and the second one saves all input and output of the aforementioned color matching. Because of this, my machine shows only a sub-1 ms difference of frametime parsing a true-color and 16-color representation of the same, complicated markup frame (namely, ptg -m).
Additionally, there is now a really robust implementation of the https://no-color.org standard! Unlike pretty much all modules, we don't just completely omit colors, rather we calculate each color's brightness and then assign a value to them in the xterm-256 greyscale range, thereby retaining most of the contrast, the ability to set background colors and more. You can see some demos of this further down the page.
Additions
- Add a graceful degradation
Colorlayer (5053603) - Expose color support in
terminal(f265807) - Add support for prettifying
UserDictandUserList(35e789c) - Add support for
NO_COLORusing greyscale ramps (0cdf712) - Add
colorsmodule with color types for all terminal colors (f265807)
Refactors
- Move
terminalto its own module (5aeb397)
Bugfixes
- Fix
[sometimes being ommitted duringprettify_markup(a2defd8)
Showcase
The same HSL to RGB color palette printed by
TIM, with onlyterminal.forced_colorspacebeing changed between runs.
ptgran withNO_COLOR=1as an environment variable.

