1 /****************************************************************************
2 * Copyright 2018-2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1996-on *
34 * and: Juergen Pfeifer 2009 *
35 ****************************************************************************/
39 * Handles color emulation of SYS V curses
42 #define NEW_PAIR_INTERNAL 1
44 #include <curses.priv.h>
49 #define CUR SP_TERMTYPE
52 MODULE_ID("$Id: lib_color.c,v 1.145 2020/05/27 23:55:32 tom Exp $")
54 #ifdef USE_TERM_DRIVER
55 #define CanChange InfoOf(SP_PARM).canchange
56 #define DefaultPalette InfoOf(SP_PARM).defaultPalette
57 #define HasColor InfoOf(SP_PARM).hascolor
58 #define InitColor InfoOf(SP_PARM).initcolor
59 #define MaxColors InfoOf(SP_PARM).maxcolors
60 #define MaxPairs InfoOf(SP_PARM).maxpairs
61 #define UseHlsPalette (DefaultPalette == _nc_hls_palette)
63 #define CanChange can_change
64 #define DefaultPalette (hue_lightness_saturation ? hls_palette : cga_palette)
65 #define HasColor has_color
66 #define InitColor initialize_color
67 #define MaxColors max_colors
68 #define MaxPairs max_pairs
69 #define UseHlsPalette (hue_lightness_saturation)
72 #ifndef USE_TERM_DRIVER
74 * These should be screen structure members. They need to be globals for
75 * historical reasons. So we assign them in start_color() and also in
76 * set_term()'s screen-switching logic.
80 NCURSES_PUBLIC_VAR(COLOR_PAIRS) (void)
82 return SP ? SP->_pair_count : -1;
85 NCURSES_PUBLIC_VAR(COLORS) (void)
87 return SP ? SP->_color_count : -1;
90 NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
91 NCURSES_EXPORT_VAR(int) COLORS = 0;
93 #endif /* !USE_TERM_DRIVER */
95 #define DATA(r,g,b) {r,g,b, 0,0,0, 0}
97 #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
101 #define OkColorHi(n) (((n) < COLORS) && ((n) < maxcolors))
102 #define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE)
105 * Given a RGB range of 0..1000, we'll normally set the individual values
106 * to about 2/3 of the maximum, leaving full-range for bold/bright colors.
111 static const color_t cga_palette[] =
114 DATA(RGB_OFF, RGB_OFF, RGB_OFF), /* COLOR_BLACK */
115 DATA(RGB_ON, RGB_OFF, RGB_OFF), /* COLOR_RED */
116 DATA(RGB_OFF, RGB_ON, RGB_OFF), /* COLOR_GREEN */
117 DATA(RGB_ON, RGB_ON, RGB_OFF), /* COLOR_YELLOW */
118 DATA(RGB_OFF, RGB_OFF, RGB_ON), /* COLOR_BLUE */
119 DATA(RGB_ON, RGB_OFF, RGB_ON), /* COLOR_MAGENTA */
120 DATA(RGB_OFF, RGB_ON, RGB_ON), /* COLOR_CYAN */
121 DATA(RGB_ON, RGB_ON, RGB_ON), /* COLOR_WHITE */
124 static const color_t hls_palette[] =
127 DATA( 0, 0, 0), /* COLOR_BLACK */
128 DATA( 120, 50, 100), /* COLOR_RED */
129 DATA( 240, 50, 100), /* COLOR_GREEN */
130 DATA( 180, 50, 100), /* COLOR_YELLOW */
131 DATA( 330, 50, 100), /* COLOR_BLUE */
132 DATA( 60, 50, 100), /* COLOR_MAGENTA */
133 DATA( 300, 50, 100), /* COLOR_CYAN */
134 DATA( 0, 50, 100), /* COLOR_WHITE */
137 #ifdef USE_TERM_DRIVER
138 NCURSES_EXPORT_VAR(const color_t*) _nc_cga_palette = cga_palette;
139 NCURSES_EXPORT_VAR(const color_t*) _nc_hls_palette = hls_palette;
143 #if NCURSES_EXT_FUNCS
145 * These are called from _nc_do_color(), which in turn is called from
146 * vidattr - so we have to assume that sp may be null.
149 default_fg(NCURSES_SP_DCL0)
151 return (SP_PARM != 0) ? SP_PARM->_default_fg : COLOR_WHITE;
155 default_bg(NCURSES_SP_DCL0)
157 return SP_PARM != 0 ? SP_PARM->_default_bg : COLOR_BLACK;
160 #define default_fg(sp) COLOR_WHITE
161 #define default_bg(sp) COLOR_BLACK
164 #ifndef USE_TERM_DRIVER
166 * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
167 * to maintain compatibility with a pre-ANSI scheme. The same scheme is
168 * also used in the FreeBSD syscons.
171 toggled_colors(int c)
174 static const int table[] =
175 {0, 4, 2, 6, 1, 5, 3, 7,
176 8, 12, 10, 14, 9, 13, 11, 15};
184 set_background_color(NCURSES_SP_DCLx int bg, NCURSES_SP_OUTC outc)
186 #ifdef USE_TERM_DRIVER
187 CallDriver_3(SP_PARM, td_color, FALSE, bg, outc);
189 if (set_a_background) {
190 TPUTS_TRACE("set_a_background");
191 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
192 TIPARM_1(set_a_background, bg),
195 TPUTS_TRACE("set_background");
196 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
197 TIPARM_1(set_background, toggled_colors(bg)),
204 set_foreground_color(NCURSES_SP_DCLx int fg, NCURSES_SP_OUTC outc)
206 #ifdef USE_TERM_DRIVER
207 CallDriver_3(SP_PARM, td_color, TRUE, fg, outc);
209 if (set_a_foreground) {
210 TPUTS_TRACE("set_a_foreground");
211 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
212 TIPARM_1(set_a_foreground, fg),
215 TPUTS_TRACE("set_foreground");
216 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
217 TIPARM_1(set_foreground, toggled_colors(fg)),
224 init_color_table(NCURSES_SP_DCL0)
226 const color_t *tp = DefaultPalette;
231 for (n = 0; n < COLORS; n++) {
233 SP_PARM->_color_table[n] = tp[n];
235 SP_PARM->_color_table[n] = tp[n % MAX_PALETTE];
237 SP_PARM->_color_table[n].green = 100;
239 if (SP_PARM->_color_table[n].red)
240 SP_PARM->_color_table[n].red = 1000;
241 if (SP_PARM->_color_table[n].green)
242 SP_PARM->_color_table[n].green = 1000;
243 if (SP_PARM->_color_table[n].blue)
244 SP_PARM->_color_table[n].blue = 1000;
251 init_direct_colors(NCURSES_SP_DCL0)
253 static NCURSES_CONST char name[] = "RGB";
258 rgb_bits_t *result = &(SP_PARM->_direct_color);
263 /* find the number of bits needed for the maximum color value */
264 for (width = 0; (1 << width) - 1 < (COLORS - 1); ++width) {
268 if ((n = tigetflag(name)) > 0) {
270 result->bits.red = UChar(n);
271 result->bits.green = UChar(n);
272 result->bits.blue = UChar(width - (2 * n));
273 } else if ((n = tigetnum(name)) > 0) {
274 result->bits.red = UChar(n);
275 result->bits.green = UChar(n);
276 result->bits.blue = UChar(n);
277 } else if ((s = tigetstr(name)) != 0 && VALID_STRING(s)) {
280 int blue = width - (2 * n);
282 switch (sscanf(s, "%d/%d/%d", &red, &green, &blue)) {
284 blue = width - (2 * n);
296 result->bits.red = UChar(red);
297 result->bits.green = UChar(green);
298 result->bits.blue = UChar(blue);
301 return (result->value != 0);
305 * Reset the color pair, e.g., to whatever color pair 0 is.
308 reset_color_pair(NCURSES_SP_DCL0)
310 #ifdef USE_TERM_DRIVER
311 return CallDriver(SP_PARM, td_rescol);
316 if (orig_pair != 0) {
317 (void) NCURSES_PUTP2("orig_pair", orig_pair);
325 * Reset color pairs and definitions. Actually we do both more to accommodate
326 * badly-written terminal descriptions than for the relatively rare case where
327 * someone has changed the color definitions.
330 NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_DCL0)
334 T((T_CALLED("_nc_reset_colors(%p)"), (void *) SP_PARM));
335 if (SP_PARM->_color_defs > 0)
336 SP_PARM->_color_defs = -(SP_PARM->_color_defs);
337 if (reset_color_pair(NCURSES_SP_ARG))
340 #ifdef USE_TERM_DRIVER
341 result = CallDriver(SP_PARM, td_rescolors);
343 if (orig_colors != 0) {
344 NCURSES_PUTP2("orig_colors", orig_colors);
353 _nc_reset_colors(void)
355 return NCURSES_SP_NAME(_nc_reset_colors) (CURRENT_SCREEN);
360 NCURSES_SP_NAME(start_color) (NCURSES_SP_DCL0)
363 int maxpairs = 0, maxcolors = 0;
365 T((T_CALLED("start_color(%p)"), (void *) SP_PARM));
369 } else if (SP_PARM->_coloron) {
373 maxcolors = MaxColors;
374 if (reset_color_pair(NCURSES_SP_ARG) != TRUE) {
375 set_foreground_color(NCURSES_SP_ARGx
376 default_fg(NCURSES_SP_ARG),
377 NCURSES_SP_NAME(_nc_outch));
378 set_background_color(NCURSES_SP_ARGx
379 default_bg(NCURSES_SP_ARG),
380 NCURSES_SP_NAME(_nc_outch));
382 #if !NCURSES_EXT_COLORS
384 * Without ext-colors, we cannot represent more than 256 color pairs.
390 if (maxpairs > 0 && maxcolors > 0) {
391 SP_PARM->_pair_limit = maxpairs;
393 #if NCURSES_EXT_FUNCS
395 * If using default colors, allocate extra space in table to
396 * allow for default-color as a component of a color-pair.
398 SP_PARM->_pair_limit += (1 + (2 * maxcolors));
399 #if !NCURSES_EXT_COLORS
400 SP_PARM->_pair_limit = limit_PAIRS(SP_PARM->_pair_limit);
402 #endif /* NCURSES_EXT_FUNCS */
403 SP_PARM->_pair_count = maxpairs;
404 SP_PARM->_color_count = maxcolors;
406 COLOR_PAIRS = maxpairs;
410 ReservePairs(SP_PARM, 16);
411 if (SP_PARM->_color_pairs != 0) {
412 if (init_direct_colors(NCURSES_SP_ARG)) {
415 SP_PARM->_color_table = TYPE_CALLOC(color_t, maxcolors);
416 if (SP_PARM->_color_table != 0) {
417 MakeColorPair(SP_PARM->_color_pairs[0],
418 default_fg(NCURSES_SP_ARG),
419 default_bg(NCURSES_SP_ARG));
420 init_color_table(NCURSES_SP_ARG);
426 T(("started color: COLORS = %d, COLOR_PAIRS = %d",
427 COLORS, COLOR_PAIRS));
429 SP_PARM->_coloron = 1;
430 } else if (SP_PARM->_color_pairs != 0) {
431 FreeAndNull(SP_PARM->_color_pairs);
445 return NCURSES_SP_NAME(start_color) (CURRENT_SCREEN);
449 /* This function was originally written by Daniel Weaver <danw@znyx.com> */
451 rgb2hls(int r, int g, int b, int *h, int *l, int *s)
452 /* convert RGB to HLS system */
456 if ((min = g < r ? g : r) > b)
458 if ((max = g > r ? g : r) < b)
461 /* calculate lightness */
462 *l = ((min + max) / 20);
464 if (min == max) { /* black, white and all shades of gray */
470 /* calculate saturation */
472 *s = (((max - min) * 100) / (max + min));
474 *s = (((max - min) * 100) / (2000 - max - min));
478 t = (120 + ((g - b) * 60) / (max - min));
480 t = (240 + ((b - r) * 60) / (max - min));
482 t = (360 + ((r - g) * 60) / (max - min));
488 * Change all cells which use(d) a given color pair to force a repaint.
491 _nc_change_pair(SCREEN *sp, int pair)
495 if (CurScreen(sp)->_clear)
498 if (_nc_globals.leak_checking)
502 for (y = 0; y <= CurScreen(sp)->_maxy; y++) {
503 struct ldat *ptr = &(CurScreen(sp)->_line[y]);
504 bool changed = FALSE;
505 for (x = 0; x <= CurScreen(sp)->_maxx; x++) {
506 if (GetPair(ptr->text[x]) == pair) {
507 /* Set the old cell to zero to ensure it will be
508 updated on the next doupdate() */
509 SetChar(ptr->text[x], 0, 0);
510 CHANGED_CELL(ptr, x);
515 NCURSES_SP_NAME(_nc_make_oldhash) (NCURSES_SP_ARGx y);
520 _nc_reserve_pairs(SCREEN *sp, int want)
522 int have = sp->_pair_alloc;
528 if (have > sp->_pair_limit)
529 have = sp->_pair_limit;
531 if (sp->_color_pairs == 0) {
532 sp->_color_pairs = TYPE_CALLOC(colorpair_t, have);
533 } else if (have > sp->_pair_alloc) {
534 #if NCURSES_EXT_COLORS
537 if ((next = typeCalloc(colorpair_t, have)) == 0)
538 _nc_err_abort(MSG_NO_MEMORY);
539 memcpy(next, sp->_color_pairs, (size_t) sp->_pair_alloc * sizeof(*next));
540 _nc_copy_pairs(sp, next, sp->_color_pairs, sp->_pair_alloc);
541 free(sp->_color_pairs);
542 sp->_color_pairs = next;
544 TYPE_REALLOC(colorpair_t, have, sp->_color_pairs);
545 if (sp->_color_pairs != 0) {
546 memset(sp->_color_pairs + sp->_pair_alloc, 0,
547 sizeof(colorpair_t) * (size_t) (have - sp->_pair_alloc));
551 if (sp->_color_pairs != 0) {
552 sp->_pair_alloc = have;
557 * Extension (1997/1/18) - Allow negative f/b values to set default color
561 _nc_init_pair(SCREEN *sp, int pair, int f, int b)
563 static colorpair_t null_pair;
564 colorpair_t result = null_pair;
565 colorpair_t previous;
568 T((T_CALLED("init_pair(%p,%d,%d,%d)"), (void *) sp, pair, f, b));
570 if (!ValidPair(sp, pair))
573 maxcolors = MaxColors;
575 ReservePairs(sp, pair);
576 previous = sp->_color_pairs[pair];
577 #if NCURSES_EXT_FUNCS
578 if (sp->_default_color || sp->_assumed_color) {
579 bool isDefault = FALSE;
580 bool wasDefault = FALSE;
581 int default_pairs = sp->_default_pairs;
584 * Map caller's color number, e.g., -1, 0, 1, .., 7, etc., into
585 * internal unsigned values which we will store in the _color_pairs[]
588 if (isDefaultColor(f)) {
591 } else if (!OkColorHi(f)) {
595 if (isDefaultColor(b)) {
598 } else if (!OkColorHi(b)) {
603 * Check if the table entry that we are going to init/update used
606 if (isDefaultColor(FORE_OF(previous))
607 || isDefaultColor(BACK_OF(previous)))
611 * Keep track of the number of entries in the color pair table which
612 * used a default color.
614 if (isDefault && !wasDefault) {
616 } else if (wasDefault && !isDefault) {
621 * As an extension, ncurses allows the pair number to exceed the
622 * terminal's color_pairs value for pairs using a default color.
624 * Note that updating a pair which used a default color with one
625 * that does not will decrement the count - and possibly interfere
626 * with sequentially adding new pairs.
628 if (pair > (sp->_pair_count + default_pairs)) {
631 sp->_default_pairs = default_pairs;
635 if ((f < 0) || !OkColorHi(f)
636 || (b < 0) || !OkColorHi(b)
643 * When a pair's content is changed, replace its colors (if pair was
644 * initialized before a screen update is performed replacing original
645 * pair colors with the new ones).
647 MakeColorPair(result, f, b);
648 if ((FORE_OF(previous) != 0
649 || BACK_OF(previous) != 0)
650 && !isSamePair(previous, result)) {
651 _nc_change_pair(sp, pair);
654 _nc_reset_color_pair(sp, pair, &result);
655 sp->_color_pairs[pair] = result;
656 _nc_set_color_pair(sp, pair, cpINIT);
658 if (GET_SCREEN_PAIR(sp) == pair)
659 SET_SCREEN_PAIR(sp, (int) (~0)); /* force attribute update */
661 #ifdef USE_TERM_DRIVER
662 CallDriver_3(sp, td_initpair, pair, f, b);
664 if (initialize_pair && InPalette(f) && InPalette(b)) {
665 const color_t *tp = DefaultPalette;
668 ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
670 (int) tp[f].red, (int) tp[f].green, (int) tp[f].blue,
671 (int) tp[b].red, (int) tp[b].green, (int) tp[b].blue));
673 NCURSES_PUTP2("initialize_pair",
674 TIPARM_7(initialize_pair,
689 NCURSES_SP_NAME(init_pair) (NCURSES_SP_DCLx
690 NCURSES_PAIRS_T pair,
694 return _nc_init_pair(SP_PARM, pair, f, b);
699 init_pair(NCURSES_COLOR_T pair, NCURSES_COLOR_T f, NCURSES_COLOR_T b)
701 return NCURSES_SP_NAME(init_pair) (CURRENT_SCREEN, pair, f, b);
705 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
708 _nc_init_color(SCREEN *sp, int color, int r, int g, int b)
713 T((T_CALLED("init_color(%p,%d,%d,%d,%d)"),
718 if (sp == 0 || sp->_direct_color.value)
721 maxcolors = MaxColors;
725 && (color >= 0 && OkColorHi(color))
726 && (okRGB(r) && okRGB(g) && okRGB(b))) {
728 sp->_color_table[color].init = 1;
729 sp->_color_table[color].r = r;
730 sp->_color_table[color].g = g;
731 sp->_color_table[color].b = b;
735 &sp->_color_table[color].red,
736 &sp->_color_table[color].green,
737 &sp->_color_table[color].blue);
739 sp->_color_table[color].red = r;
740 sp->_color_table[color].green = g;
741 sp->_color_table[color].blue = b;
744 #ifdef USE_TERM_DRIVER
745 CallDriver_4(sp, td_initcolor, color, r, g, b);
747 NCURSES_PUTP2("initialize_color",
748 TIPARM_4(initialize_color, color, r, g, b));
750 sp->_color_defs = max(color + 1, sp->_color_defs);
758 NCURSES_SP_NAME(init_color) (NCURSES_SP_DCLx
759 NCURSES_COLOR_T color,
764 return _nc_init_color(SP_PARM, color, r, g, b);
769 init_color(NCURSES_COLOR_T color,
774 return NCURSES_SP_NAME(init_color) (CURRENT_SCREEN, color, r, g, b);
779 NCURSES_SP_NAME(can_change_color) (NCURSES_SP_DCL)
783 T((T_CALLED("can_change_color(%p)"), (void *) SP_PARM));
785 if (HasTerminal(SP_PARM) && (CanChange != 0)) {
794 can_change_color(void)
796 return NCURSES_SP_NAME(can_change_color) (CURRENT_SCREEN);
801 NCURSES_SP_NAME(has_colors) (NCURSES_SP_DCL0)
806 T((T_CALLED("has_colors(%p)"), (void *) SP_PARM));
807 if (HasTerminal(SP_PARM)) {
808 #ifdef USE_TERM_DRIVER
811 code = ((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
812 && (((set_foreground != NULL)
813 && (set_background != NULL))
814 || ((set_a_foreground != NULL)
815 && (set_a_background != NULL))
816 || set_color_pair)) ? TRUE : FALSE);
826 return NCURSES_SP_NAME(has_colors) (CURRENT_SCREEN);
831 _nc_color_content(SCREEN *sp, int color, int *r, int *g, int *b)
836 T((T_CALLED("color_content(%p,%d,%p,%p,%p)"),
846 maxcolors = MaxColors;
848 if (color < 0 || !OkColorHi(color) || !sp->_coloron) {
853 if (sp->_direct_color.value) {
854 rgb_bits_t *work = &(sp->_direct_color);
856 #define max_direct_color(name) ((1 << work->bits.name) - 1)
857 #define value_direct_color(max) (1000 * ((color >> bitoff) & max)) / max
859 int max_r = max_direct_color(red);
860 int max_g = max_direct_color(green);
861 int max_b = max_direct_color(blue);
865 c_b = value_direct_color(max_b);
866 bitoff += work->bits.blue;
868 c_g = value_direct_color(max_g);
869 bitoff += work->bits.green;
871 c_r = value_direct_color(max_r);
874 c_r = sp->_color_table[color].red;
875 c_g = sp->_color_table[color].green;
876 c_b = sp->_color_table[color].blue;
886 TR(TRACE_ATTRS, ("...color_content(%d,%d,%d,%d)",
887 color, c_r, c_g, c_b));
894 NCURSES_SP_NAME(color_content) (NCURSES_SP_DCLx
895 NCURSES_COLOR_T color,
900 int my_r, my_g, my_b;
901 int rc = _nc_color_content(SP_PARM, color, &my_r, &my_g, &my_b);
903 *r = limit_COLOR(my_r);
904 *g = limit_COLOR(my_g);
905 *b = limit_COLOR(my_b);
912 color_content(NCURSES_COLOR_T color,
917 return NCURSES_SP_NAME(color_content) (CURRENT_SCREEN, color, r, g, b);
922 _nc_pair_content(SCREEN *sp, int pair, int *f, int *b)
926 T((T_CALLED("pair_content(%p,%d,%p,%p)"),
932 if (!ValidPair(sp, pair)) {
938 ReservePairs(sp, pair);
939 fg = FORE_OF(sp->_color_pairs[pair]);
940 bg = BACK_OF(sp->_color_pairs[pair]);
941 #if NCURSES_EXT_FUNCS
942 if (isDefaultColor(fg))
944 if (isDefaultColor(bg))
953 TR(TRACE_ATTRS, ("...pair_content(%p,%d,%d,%d)",
956 (int) fg, (int) bg));
963 NCURSES_SP_NAME(pair_content) (NCURSES_SP_DCLx
964 NCURSES_PAIRS_T pair,
969 int rc = _nc_pair_content(SP_PARM, pair, &my_f, &my_b);
971 *f = limit_COLOR(my_f);
972 *b = limit_COLOR(my_b);
979 pair_content(NCURSES_COLOR_T pair, NCURSES_COLOR_T *f, NCURSES_COLOR_T *b)
981 return NCURSES_SP_NAME(pair_content) (CURRENT_SCREEN, pair, f, b);
986 NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_DCLx
990 NCURSES_SP_OUTC outc)
992 #ifdef USE_TERM_DRIVER
993 CallDriver_4(SP_PARM, td_docolor, old_pair, pair, reverse, outc);
995 int fg = COLOR_DEFAULT;
996 int bg = COLOR_DEFAULT;
1000 if (!ValidPair(SP_PARM, pair)) {
1002 } else if (pair != 0) {
1003 if (set_color_pair) {
1004 TPUTS_TRACE("set_color_pair");
1005 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1006 TIPARM_1(set_color_pair, pair),
1009 } else if (SP_PARM != 0) {
1010 if (_nc_pair_content(SP_PARM, pair, &fg, &bg) == ERR)
1017 && _nc_pair_content(SP_PARM, old_pair, &old_fg, &old_bg) != ERR) {
1018 if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
1019 || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
1020 #if NCURSES_EXT_FUNCS
1022 * A minor optimization - but extension. If "AX" is specified in
1023 * the terminal description, treat it as screen's indicator of ECMA
1024 * SGR 39 and SGR 49, and assume the two sequences are independent.
1026 if (SP_PARM->_has_sgr_39_49
1027 && isDefaultColor(old_bg)
1028 && !isDefaultColor(old_fg)) {
1029 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
1030 } else if (SP_PARM->_has_sgr_39_49
1031 && isDefaultColor(old_fg)
1032 && !isDefaultColor(old_bg)) {
1033 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
1036 reset_color_pair(NCURSES_SP_ARG);
1039 reset_color_pair(NCURSES_SP_ARG);
1040 if (old_pair < 0 && pair <= 0)
1044 #if NCURSES_EXT_FUNCS
1045 if (isDefaultColor(fg))
1046 fg = default_fg(NCURSES_SP_ARG);
1047 if (isDefaultColor(bg))
1048 bg = default_bg(NCURSES_SP_ARG);
1057 TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
1060 if (!isDefaultColor(fg)) {
1061 set_foreground_color(NCURSES_SP_ARGx fg, outc);
1063 if (!isDefaultColor(bg)) {
1064 set_background_color(NCURSES_SP_ARGx bg, outc);
1069 #if NCURSES_SP_FUNCS
1070 NCURSES_EXPORT(void)
1071 _nc_do_color(int old_pair, int pair, int reverse, NCURSES_OUTC outc)
1073 SetSafeOutcWrapper(outc);
1074 NCURSES_SP_NAME(_nc_do_color) (CURRENT_SCREEN,
1082 #if NCURSES_EXT_COLORS
1084 NCURSES_SP_NAME(init_extended_pair) (NCURSES_SP_DCLx int pair, int f, int b)
1086 return _nc_init_pair(SP_PARM, pair, f, b);
1090 NCURSES_SP_NAME(init_extended_color) (NCURSES_SP_DCLx
1092 int r, int g, int b)
1094 return _nc_init_color(SP_PARM, color, r, g, b);
1098 NCURSES_SP_NAME(extended_color_content) (NCURSES_SP_DCLx
1100 int *r, int *g, int *b)
1102 return _nc_color_content(SP_PARM, color, r, g, b);
1106 NCURSES_SP_NAME(extended_pair_content) (NCURSES_SP_DCLx
1110 return _nc_pair_content(SP_PARM, pair, f, b);
1113 NCURSES_EXPORT(void)
1114 NCURSES_SP_NAME(reset_color_pairs) (NCURSES_SP_DCL0)
1117 if (SP_PARM->_color_pairs) {
1118 _nc_free_ordered_pairs(SP_PARM);
1119 free(SP_PARM->_color_pairs);
1120 SP_PARM->_color_pairs = 0;
1121 SP_PARM->_pair_alloc = 0;
1122 ReservePairs(SP_PARM, 16);
1123 clearok(CurScreen(SP_PARM), TRUE);
1124 touchwin(StdScreen(SP_PARM));
1129 #if NCURSES_SP_FUNCS
1131 init_extended_pair(int pair, int f, int b)
1133 return NCURSES_SP_NAME(init_extended_pair) (CURRENT_SCREEN, pair, f, b);
1137 init_extended_color(int color, int r, int g, int b)
1139 return NCURSES_SP_NAME(init_extended_color) (CURRENT_SCREEN,
1145 extended_color_content(int color, int *r, int *g, int *b)
1147 return NCURSES_SP_NAME(extended_color_content) (CURRENT_SCREEN,
1153 extended_pair_content(int pair, int *f, int *b)
1155 return NCURSES_SP_NAME(extended_pair_content) (CURRENT_SCREEN, pair, f, b);
1158 NCURSES_EXPORT(void)
1159 reset_color_pairs(void)
1161 NCURSES_SP_NAME(reset_color_pairs) (CURRENT_SCREEN);
1163 #endif /* NCURSES_SP_FUNCS */
1164 #endif /* NCURSES_EXT_COLORS */