I want to use 256 colours background and 256 colours foreground for my application using curses
. This requires 65536 colour pairs: which seems to be supported. curses.COLOR_PAIRS
reports 65536. This is my code:
def main(stdscr):
curses.use_default_colors()
for i in range(0, curses.COLORS):
for j in range(0, curses.COLORS - 1): #a bit of a hack, but it should work anyway.
curses.init_pair(i * curses.COLORS + j + 1, i, j) #colour 1 is hardwired, so we have to omit one colour
...
srdscr.addstr(y, x, char, curses.color_pair(fg * curses.COLORS + bg)) #ERROR
Curses hapily allows me to define 65535 (since 0 is hardwired) colour pairs, but won't let me use them. What's going on? How can I use more than 256 colour pairs?
Here's the exact error message, variable names differ of course.
Traceback (most recent call last):
File "client.py", line 173, in <module>
a.mainLoop()
File "client.py", line 134, in mainLoop
curses.wrapper(self.main)
File "/usr/local/lib/python3.10/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "client.py", line 169, in main
self.drawScreen()
File "client.py", line 152, in drawScreen
win.draw()
File "client.py", line 121, in draw
self.s.addstr(y, x, char[2], curses.color_pair(char[0] * 256 + char[1]))
ValueError: Color number is greater than COLORS (256).
I'm using python 3.10 on Linux, I've tried with 3.9, 3.8.5 etc and nothing has worked.