I've been experimenting with Curses colors and ran into a bit of an issue.
As the documentation of init_pair
states, the first argument (the number of the pair) shall be between 1
and curses.COLOR_PAIRS - 1
. Doing print(curses.COLOR, curses.COLOR_PAIR)
yields 256 65536
, so one would think that calling courses.init_pair(40000, 1, 53)
(random example) would work, but I get an error instead:
Traceback (most recent call last):
File "4-colors.py", line 38, in <module>
curses.wrapper(main)
File "/usr/lib/python3.8/curses/__init__.py", line 105, in wrapper
return func(stdscr, *args, **kwds)
File "4-colors.py", line 18, in main
curses.init_pair(40000, 1, 53)
OverflowError: signed short integer is greater than maximum
Sure enough, the implementation of init_color (I hope that I'm looking at the right file) checks whether the color pair number is within bounds of a signed short.
Why? Is there a way to bypass this and use all of the colors of my terminal, not just an arbitrary half?
Full source code of the MWE:
import curses
def main(window):
curses.start_color()
curses.use_default_colors()
curses.init_pair(40000, 1, 53)
curses.wrapper(main)