Color Pairs in ncurses not using correct colors Color Pairs in ncurses not using correct colors unix unix

Color Pairs in ncurses not using correct colors


According to @christopher-dumas, the problem was an error in PicoLisp:

Okay I figured out what the problem was
color-pairs was implemented incorrectly, because Picolisp only has a right-shift operation, and the operand order is the oppsite of what C uses. Apparently, the source where I took the origional implementation of color-pairs was wrong. For the new implementation, I copied it from lib_gen.c in the ncurses source code. The new implementation is:

   (de color-pair (n)       (& (>> -8 n) (>> -8 (- (>> -8 1) 1))))

In ncurses, the color-pair value is an 8-bit field in chtype or attr_t, defined in the curses.h header. Here's a quote from the template (the @cf_cv_1UL@ is substituted to handle very old compilers which did not permit a UL suffix for numbers):

#define NCURSES_ATTR_SHIFT       8#define NCURSES_BITS(mask,shift) (NCURSES_CAST(chtype,(mask)) << ((shift) + NCURSES_ATTR_SHIFT))...#define A_COLOR     NCURSES_BITS(((@cf_cv_1UL@) << 8) - @cf_cv_1UL@,0)