[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: |
Niegodziwy Beru |
Subject: |
Re: ncurses (init_extended_pair): can't create more than 255 color pairs |
Date: |
Sun, 12 May 2019 14:52:10 +0200 |
Thank you, and sorry for bothering. I rewrite my example according to
your suggestions, and attr_set() work, but now I have problem with
value pairs above 32767. Pair4 (62000) doesn't change his color. Do I
use it correctly, maybe I still missing something?
#include <iostream>
#include <curses.h>
// g++ main.cpp ~/ncurses-6.1-20190504/lib/libncursesw_g.a
-I/home/beru/ncurses-6.1-20190504/include/
int main() {
trace(TRACE_MAXIMUM);
WINDOW *scr = initscr();
start_color();
std::cout << "COLOR_PAIRS: " << COLOR_PAIRS << std::endl;
init_extended_color(2, 999, 0, 0);
init_extended_color(3, 0, 999, 0);
int pair3 = 32767; // 2^15-1
if (init_extended_pair(pair3, 2, 3) == ERR)
std::cout << "Error init: " << pair3 << std::endl;
_tracef("Example pair3");
attr_set(A_COLOR, (short) pair3, (void *) &pair3);
mvprintw(4, 1, "pair3_32767");
int pair4 = 62000;
if (init_extended_pair(pair4, 3, 2) == ERR or pair4 >= COLOR_PAIRS)
std::cout << "Error init: " << pair4 << std::endl;
_tracef("Example pair4");
int s = attr_set(A_COLOR, (short) pair4, (void *) &pair4);
if (s)
std::cout << "attr_set error for pair:" << pair4 << std::endl;
mvprintw(5, 1, "pair4_62000");
refresh();
getch();
endwin();
return 0;
}
Output as before:
./a.out
COLOR_PAIRS: 65536
Best regards,
Beru
niedz., 12 maj 2019 o 01:24 Thomas Dickey <address@hidden> napisał(a):
>
> 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
--
Nulla sine Deo mens bona est
trace
Description: Binary data