2002-11-25 12:11:18 +03:00
|
|
|
/* $NetBSD: color.c,v 1.21 2002/11/25 09:11:18 jdc Exp $ */
|
2000-04-13 01:43:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Julian Coleman.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-04-24 18:09:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2002-11-25 12:11:18 +03:00
|
|
|
__RCSID("$NetBSD: color.c,v 1.21 2002/11/25 09:11:18 jdc Exp $");
|
2000-04-24 18:09:41 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2000-04-13 01:43:09 +04:00
|
|
|
#include "curses.h"
|
|
|
|
#include "curses_private.h"
|
|
|
|
|
2002-08-04 20:43:04 +04:00
|
|
|
/* Have we initialised colours? */
|
|
|
|
int __using_color = 0;
|
|
|
|
|
|
|
|
/* Default colour number */
|
|
|
|
attr_t __default_color = 0;
|
|
|
|
|
|
|
|
/* Default colour pair values - white on black. */
|
|
|
|
struct __pair __default_pair = {COLOR_WHITE, COLOR_BLACK, 0};
|
|
|
|
|
|
|
|
/* Default colour values */
|
2000-04-13 01:43:09 +04:00
|
|
|
/* Flags for colours and pairs */
|
|
|
|
#define __USED 0x01
|
|
|
|
|
|
|
|
/* Attributes that clash with colours */
|
|
|
|
attr_t __nca;
|
|
|
|
|
2000-04-14 21:37:15 +04:00
|
|
|
static void
|
2002-08-04 20:43:04 +04:00
|
|
|
__change_pair(short);
|
|
|
|
|
2000-04-13 01:43:09 +04:00
|
|
|
/*
|
|
|
|
* has_colors --
|
|
|
|
* Check if terminal has colours.
|
|
|
|
*/
|
|
|
|
bool
|
2000-04-15 17:17:02 +04:00
|
|
|
has_colors(void)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
2000-12-20 00:34:24 +03:00
|
|
|
if (__tc_Co > 0 && __tc_pa > 0 && ((__tc_AF != NULL &&
|
|
|
|
__tc_AB != NULL) || __tc_Ip != NULL || __tc_Ic != NULL ||
|
|
|
|
(__tc_Sb != NULL && __tc_Sf != NULL)))
|
2000-04-13 01:43:09 +04:00
|
|
|
return(TRUE);
|
|
|
|
else
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* can_change_colors --
|
|
|
|
* Check if terminal can change colours.
|
|
|
|
*/
|
|
|
|
bool
|
2000-04-15 17:17:02 +04:00
|
|
|
can_change_colors(void)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
2000-12-20 00:34:24 +03:00
|
|
|
if (__tc_cc)
|
2000-04-13 01:43:09 +04:00
|
|
|
return(TRUE);
|
|
|
|
else
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start_color --
|
|
|
|
* Initialise colour support.
|
|
|
|
*/
|
|
|
|
int
|
2000-04-17 16:25:45 +04:00
|
|
|
start_color(void)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
2002-08-04 20:43:04 +04:00
|
|
|
int i;
|
|
|
|
attr_t temp_nc;
|
|
|
|
struct __winlist *wlp;
|
|
|
|
WINDOW *win;
|
|
|
|
int y, x;
|
2000-04-13 01:43:09 +04:00
|
|
|
|
|
|
|
if (has_colors() == FALSE)
|
|
|
|
return(ERR);
|
|
|
|
|
|
|
|
/* Max colours and colour pairs */
|
2000-12-20 00:34:24 +03:00
|
|
|
if (__tc_Co == -1)
|
2000-04-13 01:43:09 +04:00
|
|
|
COLORS = 0;
|
|
|
|
else {
|
2000-12-20 00:34:24 +03:00
|
|
|
COLORS = __tc_Co > MAX_COLORS ? MAX_COLORS : __tc_Co;
|
|
|
|
if (__tc_pa == -1) {
|
2000-04-13 01:43:09 +04:00
|
|
|
COLOR_PAIRS = 0;
|
|
|
|
COLORS = 0;
|
|
|
|
} else {
|
2002-08-04 20:43:04 +04:00
|
|
|
COLOR_PAIRS = (__tc_pa > MAX_PAIRS ?
|
|
|
|
MAX_PAIRS : __tc_pa) - 1;
|
|
|
|
/* Use the last colour pair for curses default. */
|
|
|
|
__default_color = COLOR_PAIR(COLOR_PAIRS);
|
2000-04-13 01:43:09 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-19 02:47:40 +04:00
|
|
|
if (!COLORS)
|
|
|
|
return (ERR);
|
2000-04-13 01:43:09 +04:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->COLORS = COLORS;
|
|
|
|
_cursesi_screen->COLOR_PAIRS = COLOR_PAIRS;
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2000-04-13 01:43:09 +04:00
|
|
|
/* Reset terminal colour and colour pairs. */
|
2000-12-20 00:34:24 +03:00
|
|
|
if (__tc_oc != NULL)
|
|
|
|
tputs(__tc_oc, 0, __cputchar);
|
|
|
|
if (__tc_op != NULL) {
|
|
|
|
tputs(__tc_op, 0, __cputchar);
|
2001-12-02 12:14:20 +03:00
|
|
|
curscr->wattr &= _cursesi_screen->mask_op;
|
2000-04-13 01:43:09 +04:00
|
|
|
}
|
|
|
|
|
2000-04-21 19:54:42 +04:00
|
|
|
/* Type of colour manipulation - ANSI/TEK/HP/other */
|
2000-12-20 00:34:24 +03:00
|
|
|
if (__tc_AF != NULL && __tc_AB != NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->color_type = COLOR_ANSI;
|
2000-12-20 00:34:24 +03:00
|
|
|
else if (__tc_Ip != NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->color_type = COLOR_HP;
|
2000-12-20 00:34:24 +03:00
|
|
|
else if (__tc_Ic != NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->color_type = COLOR_TEK;
|
2000-12-20 00:34:24 +03:00
|
|
|
else if (__tc_Sb != NULL && __tc_Sf != NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->color_type = COLOR_OTHER;
|
2000-04-13 01:43:09 +04:00
|
|
|
else
|
|
|
|
return(ERR); /* Unsupported colour method */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-04-19 02:47:40 +04:00
|
|
|
__CTRACE("start_color: COLORS = %d, COLOR_PAIRS = %d",
|
|
|
|
COLORS, COLOR_PAIRS);
|
2001-12-02 12:14:20 +03:00
|
|
|
switch (_cursesi_screen->color_type) {
|
2000-04-13 01:43:09 +04:00
|
|
|
case COLOR_ANSI:
|
2000-04-19 02:47:40 +04:00
|
|
|
__CTRACE(" (ANSI style)\n");
|
2000-04-13 01:43:09 +04:00
|
|
|
break;
|
|
|
|
case COLOR_HP:
|
2000-04-19 02:47:40 +04:00
|
|
|
__CTRACE(" (HP style)\n");
|
2000-04-13 01:43:09 +04:00
|
|
|
break;
|
|
|
|
case COLOR_TEK:
|
2000-04-19 02:47:40 +04:00
|
|
|
__CTRACE(" (Tektronics style)\n");
|
|
|
|
break;
|
|
|
|
case COLOR_OTHER:
|
|
|
|
__CTRACE(" (Other style)\n");
|
2000-04-13 01:43:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2000-04-13 01:43:09 +04:00
|
|
|
/*
|
|
|
|
* Attributes that cannot be used with color.
|
|
|
|
* Store these in an attr_t for wattrset()/wattron().
|
|
|
|
*/
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca = __NORMAL;
|
2000-12-20 00:34:24 +03:00
|
|
|
if (__tc_NC != -1) {
|
2001-12-02 12:14:20 +03:00
|
|
|
temp_nc = (attr_t) t_getnum(_cursesi_screen->cursesi_genbuf, "NC");
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0001)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __STANDOUT;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0002)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __UNDERSCORE;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0004)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __REVERSE;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0008)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __BLINK;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0010)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __DIM;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0020)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __BOLD;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0040)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __BLANK;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0080)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __PROTECT;
|
2000-04-13 01:43:09 +04:00
|
|
|
if (temp_nc & 0x0100)
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->nca |= __ALTCHARSET;
|
2000-04-13 01:43:09 +04:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2001-12-02 12:14:20 +03:00
|
|
|
__CTRACE ("start_color: __nca = %d\n", _cursesi_screen->nca);
|
2000-04-13 01:43:09 +04:00
|
|
|
#endif
|
2000-04-27 04:26:57 +04:00
|
|
|
|
|
|
|
/* Set up initial 8 colours */
|
|
|
|
if (COLORS >= COLOR_BLACK)
|
|
|
|
(void) init_color(COLOR_BLACK, 0, 0, 0);
|
|
|
|
if (COLORS >= COLOR_RED)
|
|
|
|
(void) init_color(COLOR_RED, 1000, 0, 0);
|
|
|
|
if (COLORS >= COLOR_GREEN)
|
|
|
|
(void) init_color(COLOR_GREEN, 0, 1000, 0);
|
|
|
|
if (COLORS >= COLOR_YELLOW)
|
|
|
|
(void) init_color(COLOR_YELLOW, 1000, 1000, 0);
|
|
|
|
if (COLORS >= COLOR_BLUE)
|
|
|
|
(void) init_color(COLOR_BLUE, 0, 0, 1000);
|
|
|
|
if (COLORS >= COLOR_MAGENTA)
|
|
|
|
(void) init_color(COLOR_MAGENTA, 1000, 0, 1000);
|
|
|
|
if (COLORS >= COLOR_CYAN)
|
|
|
|
(void) init_color(COLOR_CYAN, 0, 1000, 1000);
|
|
|
|
if (COLORS >= COLOR_WHITE)
|
|
|
|
(void) init_color(COLOR_WHITE, 1000, 1000, 1000);
|
|
|
|
|
|
|
|
/* Initialise other colours */
|
|
|
|
for (i = 8; i < COLORS; i++) {
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->colours[i].red = 0;
|
|
|
|
_cursesi_screen->colours[i].green = 0;
|
|
|
|
_cursesi_screen->colours[i].blue = 0;
|
|
|
|
_cursesi_screen->colours[i].flags = 0;
|
2000-04-27 04:26:57 +04:00
|
|
|
}
|
|
|
|
|
2002-08-04 20:43:04 +04:00
|
|
|
/* Initialise pair 0 to default colours. */
|
|
|
|
_cursesi_screen->colour_pairs[0].fore = -1;
|
|
|
|
_cursesi_screen->colour_pairs[0].back = -1;
|
|
|
|
_cursesi_screen->colour_pairs[0].flags = 0;
|
|
|
|
|
|
|
|
/* Initialise user colour pairs to default (white on black) */
|
|
|
|
for (i = 1; i < COLOR_PAIRS; i++) {
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->colour_pairs[i].fore = COLOR_WHITE;
|
|
|
|
_cursesi_screen->colour_pairs[i].back = COLOR_BLACK;
|
|
|
|
_cursesi_screen->colour_pairs[i].flags = 0;
|
2000-04-27 04:26:57 +04:00
|
|
|
}
|
|
|
|
|
2002-08-04 20:43:04 +04:00
|
|
|
/* Initialise default colour pair. */
|
|
|
|
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore =
|
|
|
|
__default_pair.fore;
|
|
|
|
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back =
|
|
|
|
__default_pair.back;
|
|
|
|
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags =
|
|
|
|
__default_pair.flags;
|
|
|
|
|
|
|
|
__using_color = 1;
|
|
|
|
|
|
|
|
/* Set all positions on all windows to curses default colours. */
|
|
|
|
for (wlp = __winlistp; wlp != NULL; wlp = wlp->nextp) {
|
|
|
|
win = wlp->winp;
|
|
|
|
if (wlp->winp == curscr) {
|
|
|
|
/* Reset colour attribute on curscr */
|
|
|
|
for (y = 0; y < curscr->maxy; y++)
|
|
|
|
for (x = 0; x < curscr->maxx; x++) {
|
|
|
|
if ((curscr->lines[y]->line[x].battr & __COLOR) == __default_color)
|
|
|
|
curscr->lines[y]->line[x].battr &= ~__COLOR;
|
|
|
|
}
|
|
|
|
} else if (wlp->winp != __virtscr) {
|
|
|
|
/* Set background attribute on other windows */
|
|
|
|
if (!(win->battr & __COLOR))
|
|
|
|
win->battr |= __default_color;
|
|
|
|
for (y = 0; y < win->maxy; y++) {
|
|
|
|
for (x = 0; x < win->maxx; x++)
|
|
|
|
if (!(win->lines[y]->line[x].battr & __COLOR))
|
|
|
|
win->lines[y]->line[x].battr |= __default_color;
|
|
|
|
}
|
|
|
|
__touchwin(win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-13 01:43:09 +04:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init_pair --
|
|
|
|
* Set pair foreground and background colors.
|
|
|
|
*/
|
|
|
|
int
|
2000-04-15 17:17:02 +04:00
|
|
|
init_pair(short pair, short fore, short back)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
|
|
|
int changed;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("init_pair: %d, %d, %d\n", pair, fore, back);
|
|
|
|
#endif
|
2000-04-27 09:03:22 +04:00
|
|
|
|
2002-11-25 12:11:18 +03:00
|
|
|
if (pair < 0 || pair >= COLOR_PAIRS)
|
2000-04-27 09:03:22 +04:00
|
|
|
return (ERR);
|
2002-08-04 20:43:04 +04:00
|
|
|
if (fore < -1 || fore >= COLORS)
|
2000-04-27 09:03:22 +04:00
|
|
|
return (ERR);
|
2002-08-04 20:43:04 +04:00
|
|
|
if (back < -1 || back >= COLORS)
|
2000-04-27 09:03:22 +04:00
|
|
|
return (ERR);
|
2000-04-13 01:43:09 +04:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
if ((_cursesi_screen->colour_pairs[pair].flags & __USED) &&
|
|
|
|
(fore != _cursesi_screen->colour_pairs[pair].fore ||
|
|
|
|
back != _cursesi_screen->colour_pairs[pair].back))
|
2000-04-13 01:43:09 +04:00
|
|
|
changed = 1;
|
|
|
|
else
|
|
|
|
changed = 0;
|
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->colour_pairs[pair].flags |= __USED;
|
|
|
|
_cursesi_screen->colour_pairs[pair].fore = fore;
|
|
|
|
_cursesi_screen->colour_pairs[pair].back = back;
|
2000-04-13 01:43:09 +04:00
|
|
|
|
2000-12-20 00:34:24 +03:00
|
|
|
/* XXX: need to initialise HP style (Ip) */
|
2000-04-13 01:43:09 +04:00
|
|
|
|
2000-04-27 09:03:22 +04:00
|
|
|
if (changed)
|
|
|
|
__change_pair(pair);
|
|
|
|
return (OK);
|
2000-04-13 01:43:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pair_content --
|
|
|
|
* Get pair foreground and background colours.
|
|
|
|
*/
|
|
|
|
int
|
2000-04-15 17:17:02 +04:00
|
|
|
pair_content(short pair, short *forep, short *backp)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
2002-08-04 20:43:04 +04:00
|
|
|
if (pair < 0 || pair > _cursesi_screen->COLOR_PAIRS)
|
2000-04-13 01:43:09 +04:00
|
|
|
return(ERR);
|
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
*forep = _cursesi_screen->colour_pairs[pair].fore;
|
|
|
|
*backp = _cursesi_screen->colour_pairs[pair].back;
|
2000-04-13 01:43:09 +04:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init_color --
|
|
|
|
* Set colour red, green and blue values.
|
|
|
|
*/
|
|
|
|
int
|
2000-04-15 17:17:02 +04:00
|
|
|
init_color(short color, short red, short green, short blue)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("init_color: %d, %d, %d, %d\n", color, red, green, blue);
|
|
|
|
#endif
|
2002-08-04 20:43:04 +04:00
|
|
|
if (color < 0 || color >= _cursesi_screen->COLORS)
|
2000-04-13 01:43:09 +04:00
|
|
|
return(ERR);
|
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen->colours[color].red = red;
|
|
|
|
_cursesi_screen->colours[color].green = green;
|
|
|
|
_cursesi_screen->colours[color].blue = blue;
|
2000-04-13 01:43:09 +04:00
|
|
|
/* XXX Not yet implemented */
|
|
|
|
return(ERR);
|
2000-12-20 00:34:24 +03:00
|
|
|
/* XXX: need to initialise Tek style (Ic) and support HLS */
|
2000-04-13 01:43:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* color_content --
|
|
|
|
* Get colour red, green and blue values.
|
|
|
|
*/
|
|
|
|
int
|
2000-04-15 17:17:02 +04:00
|
|
|
color_content(short color, short *redp, short *greenp, short *bluep)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
2001-12-02 12:14:20 +03:00
|
|
|
if (color < 0 || color >= _cursesi_screen->COLORS)
|
2000-04-13 01:43:09 +04:00
|
|
|
return(ERR);
|
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
*redp = _cursesi_screen->colours[color].red;
|
|
|
|
*greenp = _cursesi_screen->colours[color].green;
|
|
|
|
*bluep = _cursesi_screen->colours[color].blue;
|
2000-04-13 01:43:09 +04:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2002-08-04 20:43:04 +04:00
|
|
|
/*
|
|
|
|
* use_default_colors --
|
|
|
|
* Use terminal default colours instead of curses default colour.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
use_default_colors()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("use_default_colors\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return(assume_default_colors(-1, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assume_default_colors --
|
|
|
|
* Set the default foreground and background colours.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
assume_default_colors(short fore, short back)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("assume_default_colors: %d, %d, %d\n", fore, back);
|
|
|
|
#endif
|
|
|
|
__default_pair.fore = fore;
|
|
|
|
__default_pair.back = back;
|
|
|
|
__default_pair.flags = __USED;
|
|
|
|
|
|
|
|
if (COLOR_PAIRS) {
|
|
|
|
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore = fore;
|
|
|
|
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back = back;
|
|
|
|
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags = __USED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we've already called start_color(), make sure all instances
|
|
|
|
* of the curses default colour pair are dirty.
|
|
|
|
*/
|
|
|
|
if (__using_color)
|
|
|
|
__change_pair(PAIR_NUMBER(__default_color));
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-13 01:43:09 +04:00
|
|
|
/*
|
|
|
|
* __set_color --
|
|
|
|
* Set terminal foreground and background colours.
|
|
|
|
*/
|
|
|
|
void
|
2002-10-22 15:37:34 +04:00
|
|
|
__set_color( /*ARGSUSED*/ WINDOW *win, attr_t attr)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
|
|
|
short pair;
|
|
|
|
|
2002-08-04 20:43:04 +04:00
|
|
|
if ((curscr->wattr & __COLOR) == (attr & __COLOR))
|
|
|
|
return;
|
|
|
|
|
2001-01-06 01:57:56 +03:00
|
|
|
pair = PAIR_NUMBER((u_int32_t)attr);
|
2000-04-13 01:43:09 +04:00
|
|
|
#ifdef DEBUG
|
2001-12-02 12:14:20 +03:00
|
|
|
__CTRACE("__set_color: %d, %d, %d\n", pair,
|
2002-06-26 22:13:59 +04:00
|
|
|
_cursesi_screen->colour_pairs[pair].fore,
|
|
|
|
_cursesi_screen->colour_pairs[pair].back);
|
2000-04-13 01:43:09 +04:00
|
|
|
#endif
|
2001-12-02 12:14:20 +03:00
|
|
|
switch (_cursesi_screen->color_type) {
|
2000-04-13 01:43:09 +04:00
|
|
|
/* Set ANSI forground and background colours */
|
|
|
|
case COLOR_ANSI:
|
2002-08-04 20:43:04 +04:00
|
|
|
if (_cursesi_screen->colour_pairs[pair].fore == -1 ||
|
|
|
|
_cursesi_screen->colour_pairs[pair].back == -1)
|
|
|
|
__unset_color(curscr);
|
|
|
|
if (_cursesi_screen->colour_pairs[pair].fore != -1)
|
|
|
|
tputs(__parse_cap(_cursesi_screen->tc_AF,
|
|
|
|
_cursesi_screen->colour_pairs[pair].fore),
|
|
|
|
0, __cputchar);
|
|
|
|
if (_cursesi_screen->colour_pairs[pair].back != -1)
|
|
|
|
tputs(__parse_cap(_cursesi_screen->tc_AB,
|
|
|
|
_cursesi_screen->colour_pairs[pair].back),
|
|
|
|
0, __cputchar);
|
2000-04-13 01:43:09 +04:00
|
|
|
break;
|
|
|
|
case COLOR_HP:
|
|
|
|
/* XXX: need to support HP style */
|
|
|
|
break;
|
|
|
|
case COLOR_TEK:
|
|
|
|
/* XXX: need to support Tek style */
|
|
|
|
break;
|
2000-04-19 02:47:40 +04:00
|
|
|
case COLOR_OTHER:
|
2002-08-04 20:43:04 +04:00
|
|
|
if (_cursesi_screen->colour_pairs[pair].fore == -1 ||
|
|
|
|
_cursesi_screen->colour_pairs[pair].back == -1)
|
|
|
|
__unset_color(curscr);
|
|
|
|
if (_cursesi_screen->colour_pairs[pair].fore != -1)
|
|
|
|
tputs(__parse_cap(_cursesi_screen->tc_Sf,
|
|
|
|
_cursesi_screen->colour_pairs[pair].fore),
|
|
|
|
0, __cputchar);
|
|
|
|
if (_cursesi_screen->colour_pairs[pair].back != -1)
|
|
|
|
tputs(__parse_cap(_cursesi_screen->tc_Sb,
|
|
|
|
_cursesi_screen->colour_pairs[pair].back),
|
|
|
|
0, __cputchar);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curscr->wattr &= ~__COLOR;
|
|
|
|
curscr->wattr |= attr & __COLOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* __unset_color --
|
|
|
|
* Clear terminal foreground and background colours.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
__unset_color(WINDOW *win)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("__unset_color\n");
|
|
|
|
#endif
|
|
|
|
switch (_cursesi_screen->color_type) {
|
|
|
|
/* Clear ANSI forground and background colours */
|
|
|
|
case COLOR_ANSI:
|
|
|
|
if (__tc_op != NULL) {
|
|
|
|
tputs(__tc_op, 0, __cputchar);
|
|
|
|
win->wattr &= __mask_op;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case COLOR_HP:
|
|
|
|
/* XXX: need to support HP style */
|
|
|
|
break;
|
|
|
|
case COLOR_TEK:
|
|
|
|
/* XXX: need to support Tek style */
|
|
|
|
break;
|
|
|
|
case COLOR_OTHER:
|
|
|
|
if (__tc_op != NULL) {
|
|
|
|
tputs(__tc_op, 0, __cputchar);
|
|
|
|
win->wattr &= __mask_op;
|
|
|
|
}
|
2000-04-19 02:47:40 +04:00
|
|
|
break;
|
2000-04-13 01:43:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* __restore_colors --
|
|
|
|
* Redo color definitions after restarting 'curses' mode.
|
|
|
|
*/
|
|
|
|
void
|
2000-04-15 17:17:02 +04:00
|
|
|
__restore_colors(void)
|
2000-04-13 01:43:09 +04:00
|
|
|
{
|
2000-12-20 00:34:24 +03:00
|
|
|
if (__tc_cc != NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
switch (_cursesi_screen->color_type) {
|
2000-04-13 01:43:09 +04:00
|
|
|
case COLOR_HP:
|
2000-12-20 00:34:24 +03:00
|
|
|
/* XXX: need to re-initialise HP style (Ip) */
|
2000-04-13 01:43:09 +04:00
|
|
|
break;
|
|
|
|
case COLOR_TEK:
|
2000-12-20 00:34:24 +03:00
|
|
|
/* XXX: need to re-initialise Tek style (Ic) */
|
2000-04-13 01:43:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-04-14 21:37:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* __change_pair --
|
|
|
|
* Mark dirty all positions using pair.
|
|
|
|
*/
|
|
|
|
void
|
2000-04-15 17:17:02 +04:00
|
|
|
__change_pair(short pair)
|
2000-04-14 21:37:15 +04:00
|
|
|
{
|
|
|
|
struct __winlist *wlp;
|
|
|
|
WINDOW *win;
|
|
|
|
int y, x;
|
|
|
|
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2000-04-14 21:37:15 +04:00
|
|
|
for (wlp = __winlistp; wlp != NULL; wlp = wlp->nextp) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("__change_pair: win = %0.2o\n", wlp->winp);
|
|
|
|
#endif
|
2002-08-04 20:43:04 +04:00
|
|
|
win = wlp->winp;
|
|
|
|
if (win == curscr) {
|
2000-04-14 21:37:15 +04:00
|
|
|
/* Reset colour attribute on curscr */
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("__change_pair: win == curscr\n");
|
|
|
|
#endif
|
|
|
|
for (y = 0; y < curscr->maxy; y++)
|
2002-08-04 20:43:04 +04:00
|
|
|
for (x = 0; x < curscr->maxx; x++) {
|
2000-04-14 21:37:15 +04:00
|
|
|
if ((curscr->lines[y]->line[x].attr &
|
|
|
|
__COLOR) == COLOR_PAIR(pair))
|
|
|
|
curscr->lines[y]->line[x].attr
|
|
|
|
&= ~__COLOR;
|
2002-08-04 20:43:04 +04:00
|
|
|
if ((curscr->lines[y]->line[x].battr &
|
|
|
|
__COLOR) == COLOR_PAIR(pair))
|
|
|
|
curscr->lines[y]->line[x].battr
|
|
|
|
&= ~__COLOR;
|
|
|
|
}
|
|
|
|
} else if (win != __virtscr) {
|
|
|
|
/* Mark dirty those positions with colour pair "pair" */
|
2000-04-14 21:37:15 +04:00
|
|
|
for (y = 0; y < win->maxy; y++) {
|
|
|
|
for (x = 0; x < win->maxx; x++)
|
|
|
|
if ((win->lines[y]->line[x].attr &
|
2002-08-04 20:43:04 +04:00
|
|
|
__COLOR) == COLOR_PAIR(pair) ||
|
|
|
|
(win->lines[y]->line[x].battr &
|
2000-04-14 21:37:15 +04:00
|
|
|
__COLOR) == COLOR_PAIR(pair)) {
|
|
|
|
if (!(win->lines[y]->flags &
|
2000-04-16 02:53:05 +04:00
|
|
|
__ISDIRTY))
|
2000-04-14 21:37:15 +04:00
|
|
|
win->lines[y]->flags |=
|
|
|
|
__ISDIRTY;
|
2000-04-16 02:53:05 +04:00
|
|
|
/*
|
|
|
|
* firstchp/lastchp are shared
|
|
|
|
* between parent window and
|
|
|
|
* sub-window.
|
|
|
|
*/
|
|
|
|
if (*win->lines[y]->firstchp >
|
|
|
|
x)
|
2000-04-14 21:37:15 +04:00
|
|
|
*win->lines[y]->firstchp
|
|
|
|
= x;
|
2000-04-16 02:53:05 +04:00
|
|
|
if (*win->lines[y]->lastchp < x)
|
2000-04-14 21:37:15 +04:00
|
|
|
*win->lines[y]->lastchp
|
|
|
|
= x;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2000-04-16 02:53:05 +04:00
|
|
|
if ((win->lines[y]->flags & __ISDIRTY))
|
2000-04-14 21:37:15 +04:00
|
|
|
__CTRACE("__change_pair: first = %d, last = %d\n", *win->lines[y]->firstchp, *win->lines[y]->lastchp);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|