[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Issue using more than 255 color pairs
From: |
Thomas Dickey |
Subject: |
Re: Issue using more than 255 color pairs |
Date: |
Sat, 15 Jul 2023 17:55:44 -0400 |
On Sun, Jul 16, 2023 at 12:06:31AM +0200, David Unterwandling wrote:
> In-Reply-To: <ZLK77gvDufh2Rwhb@prl-debianold-64.jexium-island.net>
> References: <ZLK77xDE6pSvXDCB@scw>
> <ZLK77gvDufh2Rwhb@prl-debianold-64.jexium-island.net>
>
>
> > perhaps if you provided a complete test-program which demonstrates an
> > unwanted change, I could investigate that.
>
> #define _XOPEN_SOURCE 700
_XOPEN_SOURCE is already defined in the compiler's preamble (outside your
source). Normally you'd do that on the command-line.
> #include <curses.h>
> #include <string.h>
>
> void main(void)
^ (standard C uses "int")
> {
> register int i;
> char *f, *s;
>
> initscr();
> start_color();
> use_default_colors();
>
> sprintf(f, "%d color pairs allowed", COLOR_PAIRS); /* 65536 */
"f" is an uninitialized buffer (and that sprintf trashes memory)
> s = strdup(f);
> addstr(s);
>
> for (i = 1; i < 300; i++)
> init_pair(i, -1, COLOR_RED);
>
> if (!COLOR_PAIR(256))
> addstr(", but maximum is 256\n");
When "i" is 256, that equals COLORS, and ncurses does something like
foo = (bar >= 0) ? (bar % COLORS) : -1;
so you get 0 (zero). That's expected (because I have to allow for -1 as
a special out-of-range value).
I could make init_pair return an error, but since you're not checking
for errors, this case wouldn't make a difference.
> #define A_COLOR NCURSES_BITS(((1U) << 16) - 1U, 0)
I suppose you're wondering why you can't make the program work if you are
redefining constants in curses.h ?
By redefining it, you moved your program's sense of where the attribute
and color bits are -- but ncurses didn't move.
> attron(COLOR_PAIR(260));
this line (as seen in ncurses) is
attron(A_STANDOUT | COLOR_PAIR(4));
> addstr("now these are immutable and have A_REVERSE");
>
> refresh();
> getch();
> endwin();
> }
>
--
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net
signature.asc
Description: PGP signature
- Re: Issue using more than 255 color pairs, David Unterwandling, 2023/07/15
- Re: Issue using more than 255 color pairs, David Unterwandling, 2023/07/15
- Re: Issue using more than 255 color pairs,
Thomas Dickey <=
- Re: Issue using more than 255 color pairs, Thomas Dickey, 2023/07/16
- Re: Issue using more than 255 color pairs, David Unterwandling, 2023/07/16
- Re: Issue using more than 255 color pairs, Thomas Dickey, 2023/07/16
- Re: Issue using more than 255 color pairs, David Unterwandling, 2023/07/17
- Re: Issue using more than 255 color pairs, David Unterwandling, 2023/07/17
- Re: Issue using more than 255 color pairs, Bill Gray, 2023/07/16
- Re: Issue using more than 255 color pairs, Thomas Dickey, 2023/07/16
- Re: Issue using more than 255 color pairs, Dennis Clarke, 2023/07/16
- Re: Issue using more than 255 color pairs, William McBrine, 2023/07/16
- Re: Issue using more than 255 color pairs, Bill Gray, 2023/07/16