gui: support up to 65535 ncurses color pairs (issue #1343) #1365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves PR #1345 which fixed issue #1343. Because this introduces additional ncurses-specific behavior, it may be better to not immediately merge this but instead wait and see if #1345 itself has some regressions for someone. I'm still opening the PR because I have implemented the additional limit increase and it could be tested, but it's not as crucial because 32767 color pairs "ought to be enough for everyone".
Changes
The standard curses API uses
short
s for color pair numbers, so values above 32767, which ncurses claims to support in 256-color modes, wouldn't actually work because they overflow. Two ncurses-specific extensions allow working around this limitation:init_extended_pair
instead ofinit_pair
allows defining color pairs withint
numbers.opts
arguments of many curses color and attribute functions allow passing the color pair withint
number as anint*
to be used instead of the usual color pair asshort
.Because both are ncurses-specific extensions to the curses API, their uses have been implemented conditionally on
NCURSES_EXT_FUNCS
andNCURSES_EXT_COLORS
(through helper macros to reduce duplicating the preprocessor conditions a lot) to attempt to be as compatible as possible.Potential problems
Does this PR actually increase the usable limit from 32767 to 65535?
I only tested it with
colorspam.py
, which outputs 1024 color pairs. It should actually be checked that when trying to display more than 32767 color pairs at once, before this PR it wouldn't display correctly but after this PR it would. It's kind of difficult to fit enough output into a buffer to use 32767 color pairs without scrolling and to visually check the its (in)correctness.Some conditions use
NCURSES_EXT_FUNCS
, othersNCURSES_EXT_COLORS
— is that exact/correct/sufficient or should both be required to be true?For example, is it possible to have an ncurses build that supports only one or the other?
Change:
init_extended_pair
and color pair inopts
are only supported since ncurses patch 20170401. Made the preprocessor conditions stronger in commit 63fa5a0.