bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ncurses (init_extended_pair): can't create more than 255 color pairs


From: Thomas Dickey
Subject: Re: ncurses (init_extended_pair): can't create more than 255 color pairs
Date: Sat, 11 May 2019 19:24:07 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Sat, May 11, 2019 at 01:43:46PM +0200, Niegodziwy Beru wrote:
> Hello,
> In version 6.1, ncurses introduce init_extended_pair to extend limit
> of possible color pairs above short limit. In my app I would like to
> display three words:
> 
> pair255 (green background, red foreground)
> pair256 (green background, red foreground)
> pair32767 (red background, green foreground)
> 
> Only pair value 255 work correctly, pair numbers 256 and 32767 doesn’t
> generate proper colors (I don’t get any errors, and COLOR_PAIRS
> indicates value 65536).
> 
> Originally I post this problem on stackoverflow
> (https://stackoverflow.com/questions/55972033/ncurses-init-extended-pair-cant-create-more-than-255-color-pairs
> ), where I have two problems, with library delivered by Ubuntu, but
> with newest code (from repository) I was able to reproduce only one of
> them.
...
> 2. Compilation and execution:
> 
> $ g++  main.cpp ~/ncurses-6.1-20190504/lib/libncursesw_g.a

I think you missed a step here: you're using the header files from
the system (/usr/include) rather than those for the library which
you built.

> $ ./a.out
> COLOR_PAIRS: 65536
> 
> 3. Steps that I use to build ncurses:
> 
> $ wget -c https://invisible-island.net/datafiles/current/ncurses.tar.gz
> $ tar -zxvf ncurses.tar.gz
> $ cd ncurses-6.1-20190504/
> $ ./configure --enable-ext-colors --enable-widec --with-trace
> --with-terminfo-dirs="/etc/terminfo:/lib/terminfo:/usr/share/terminfo"
> --with-default-terminfo-dir=/etc/terminfo --without-gpm
> $ make

I did something like this, but compiled your example in-tree,
and added -I/-L options to point it to the built files:

g++  main.cpp -Iinclude -Llib -lncursesw

(and changed the #include to "curses.h").

The reason why you don't get the expected colors is because the
function you used cannot hold that many bits:

    int pair3 = 32767; // 2^15-1
    if (init_extended_pair(pair3, 3, 2) == ERR)
        std::cout << "Error: " << pair3 << std::endl;

    _tracef("Example pair3");
    attr_on(COLOR_PAIR(pair3), NULL);
    mvprintw(4, 1, "pair32767");
    attr_off(COLOR_PAIR(pair3), NULL);

attr_on/attr_off can only hold 8 bits of color pair.  See the manual page:

       int attr_get(attr_t *attrs, short *pair, void *opts);
       int wattr_get(WINDOW *win, attr_t *attrs, short *pair, void *opts);
       int attr_set(attr_t attrs, short pair, void *opts);
       int wattr_set(WINDOW *win, attr_t attrs, short pair, void *opts);

       int attr_off(attr_t attrs, void *opts);
       int wattr_off(WINDOW *win, attr_t attrs, void *opts);
       int attr_on(attr_t attrs, void *opts);
       int wattr_on(WINDOW *win, attr_t attrs, void *opts);
 
The attr_set/wattr_set functions can pass larger values of color
pair in the "pair" parameter (or values above 32767 via "opts").

-- 
Thomas E. Dickey <address@hidden>
https://invisible-island.net
ftp://ftp.invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]