jquast / blessed

Blessed is an easy, practical library for making python terminal apps
http://pypi.python.org/pypi/blessed
MIT License
1.18k stars 71 forks source link

88 color terminal is not supported #235

Closed cmdoret closed 2 years ago

cmdoret commented 2 years ago

I tried running blessed on a university cluster, where the COLORTERM variable is not set by default. Creating an instance of blessed.Terminal throws an AssertionError.

import blessed
term = blessed.Terminal()
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-4-901ccc5afcc1> in <module>
----> 1 term = blessed.Terminal()

~/anaconda3/envs/renku/lib/python3.9/site-packages/blessed/terminal.py in __init__(self, kind, stream, force_styling)
    204                             self._kind, _CUR_TERM,))
    205 
--> 206         self.__init__color_capabilities()
    207         self.__init__capabilities()
    208         self.__init__keycodes()

~/anaconda3/envs/renku/lib/python3.9/site-packages/blessed/terminal.py in __init__color_capabilities(self)
    265             self.number_of_colors = 1 << 24
    266         else:
--> 267             self.number_of_colors = max(0, curses.tigetnum('colors') or -1)
    268 
    269     def __clear_color_capabilities(self):

~/anaconda3/envs/renku/lib/python3.9/site-packages/blessed/terminal.py in number_of_colors(self, value)
    944     @number_of_colors.setter
    945     def number_of_colors(self, value):
--> 946         assert value in (0, 4, 8, 16, 256, 1 << 24)
    947         self._number_of_colors = value
    948         self.__clear_color_capabilities()

AssertionError: 

tput colors yields 88, which doesn't match the list of values in number_of_colors. I realize having COLORTERM not set is potentially a misconfiguration on the system, but would it be desirable to just throw a warning, or at least have an informative error message ?

avylove commented 2 years ago

The issue isn't that COLORTERM is not set, but that your number of colors is 88, which we thought wasn't really something we'd run into anymore. We added support for 0, 4, 8. 16. 256, and 16.7m (24-bit) colors. Out of curiosity, what OS is this cluster operating on?

cmdoret commented 2 years ago

Thanks for clarifying, It's running RHEL 7.6. Would adding support for 88 colors have any drawbacks ?

avylove commented 2 years ago

That's not standard for RHEL 7, I think even if you're using rxvt. I was expecting something more exotic or esoteric :) The main downside of supporting 88 colors is it uses a different color chart than everything else. So it just means more data and some if statements to determine which color chart to use (256 or 88). The other thing is figuring out the RGB values for the 88 color chart. I had this at one point, but I can't find it now. I've tried to generate one on my Fedora system, but the palette seems off. It seems very pink and cyan without any grays. Do you actually need 88 colors or would it work if we treated 88 colors like 16 colors?

cmdoret commented 2 years ago

16 colors would actually work fine here :smiley: . In my use case blessed is used as dependency by another program to display a bunch of progress bars, so I would rather have a weird looking palette than the program crashing.

avylove commented 2 years ago

I was actually able to find the color table I had before for 88 colors. I can't remember how I derived it (that was a couple years ago), but the colors seem sane. Not that it means the palette applied to any given terminal is going to be sane.

@jquast, I'll put a PR together, but what is your preference, treating 88 colors as 16 colors or adding the 88 color table back in?

jquast commented 2 years ago

Whichever you prefer is fine with me @avylove, thank you for your help!

I remember studying & disregarding 88 colors as legacy, I was unable to test at the time, but here we are :)

avylove commented 2 years ago

I tried for a while and could not find a good way to know if the values in my old table were valid. I think it would require compiling some version of rxvt from source and enabling 88 colors. So I went with the easy path. We can revisit later if it's an issue for anyone.

236

avylove commented 2 years ago

Fix is in 1.19.1. Thanks for reporting! Let us know how this works for you.