xref: /minix3/lib/libcurses/attributes.c (revision 51ffecc181005cb45a40108612ee28d1daaeeb86)
1*51ffecc1SBen Gras /*	$NetBSD: attributes.c,v 1.21 2010/12/25 10:08:20 blymn Exp $	*/
2*51ffecc1SBen Gras 
3*51ffecc1SBen Gras /*-
4*51ffecc1SBen Gras  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5*51ffecc1SBen Gras  * All rights reserved.
6*51ffecc1SBen Gras  *
7*51ffecc1SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
8*51ffecc1SBen Gras  * by Julian Coleman.
9*51ffecc1SBen Gras  *
10*51ffecc1SBen Gras  * Redistribution and use in source and binary forms, with or without
11*51ffecc1SBen Gras  * modification, are permitted provided that the following conditions
12*51ffecc1SBen Gras  * are met:
13*51ffecc1SBen Gras  * 1. Redistributions of source code must retain the above copyright
14*51ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer.
15*51ffecc1SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
16*51ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer in the
17*51ffecc1SBen Gras  *    documentation and/or other materials provided with the distribution.
18*51ffecc1SBen Gras  *
19*51ffecc1SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*51ffecc1SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*51ffecc1SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*51ffecc1SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*51ffecc1SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*51ffecc1SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*51ffecc1SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*51ffecc1SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*51ffecc1SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*51ffecc1SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*51ffecc1SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
30*51ffecc1SBen Gras  */
31*51ffecc1SBen Gras 
32*51ffecc1SBen Gras #include <sys/cdefs.h>
33*51ffecc1SBen Gras #ifndef lint
34*51ffecc1SBen Gras __RCSID("$NetBSD: attributes.c,v 1.21 2010/12/25 10:08:20 blymn Exp $");
35*51ffecc1SBen Gras #endif				/* not lint */
36*51ffecc1SBen Gras 
37*51ffecc1SBen Gras #include "curses.h"
38*51ffecc1SBen Gras #include "curses_private.h"
39*51ffecc1SBen Gras 
40*51ffecc1SBen Gras void __wcolor_set(WINDOW *, attr_t);
41*51ffecc1SBen Gras 
42*51ffecc1SBen Gras #ifndef _CURSES_USE_MACROS
43*51ffecc1SBen Gras /*
44*51ffecc1SBen Gras  * attr_get --
45*51ffecc1SBen Gras  *	Get wide attributes and color pair from stdscr
46*51ffecc1SBen Gras  */
47*51ffecc1SBen Gras /* ARGSUSED */
48*51ffecc1SBen Gras int
attr_get(attr_t * attr,short * pair,void * opt)49*51ffecc1SBen Gras attr_get(attr_t *attr, short *pair, void *opt)
50*51ffecc1SBen Gras {
51*51ffecc1SBen Gras 	return wattr_get(stdscr, attr, pair, opt);
52*51ffecc1SBen Gras }
53*51ffecc1SBen Gras 
54*51ffecc1SBen Gras /*
55*51ffecc1SBen Gras  * attr_on --
56*51ffecc1SBen Gras  *	Test and set wide attributes on stdscr
57*51ffecc1SBen Gras  */
58*51ffecc1SBen Gras /* ARGSUSED */
59*51ffecc1SBen Gras int
attr_on(attr_t attr,void * opt)60*51ffecc1SBen Gras attr_on(attr_t attr, void *opt)
61*51ffecc1SBen Gras {
62*51ffecc1SBen Gras 	return wattr_on(stdscr, attr, opt);
63*51ffecc1SBen Gras }
64*51ffecc1SBen Gras 
65*51ffecc1SBen Gras /*
66*51ffecc1SBen Gras  * attr_off --
67*51ffecc1SBen Gras  *	Test and unset wide attributes on stdscr
68*51ffecc1SBen Gras  */
69*51ffecc1SBen Gras /* ARGSUSED */
70*51ffecc1SBen Gras int
attr_off(attr_t attr,void * opt)71*51ffecc1SBen Gras attr_off(attr_t attr, void *opt)
72*51ffecc1SBen Gras {
73*51ffecc1SBen Gras 	return wattr_off(stdscr, attr, opt);
74*51ffecc1SBen Gras }
75*51ffecc1SBen Gras 
76*51ffecc1SBen Gras /*
77*51ffecc1SBen Gras  * attr_set --
78*51ffecc1SBen Gras  *	Set wide attributes and color pair on stdscr
79*51ffecc1SBen Gras  */
80*51ffecc1SBen Gras /* ARGSUSED */
81*51ffecc1SBen Gras int
attr_set(attr_t attr,short pair,void * opt)82*51ffecc1SBen Gras attr_set(attr_t attr, short pair, void *opt)
83*51ffecc1SBen Gras {
84*51ffecc1SBen Gras 	return wattr_set(stdscr, attr, pair, opt);
85*51ffecc1SBen Gras }
86*51ffecc1SBen Gras 
87*51ffecc1SBen Gras /*
88*51ffecc1SBen Gras  * color_set --
89*51ffecc1SBen Gras  *	Set color pair on stdscr
90*51ffecc1SBen Gras  */
91*51ffecc1SBen Gras /* ARGSUSED */
92*51ffecc1SBen Gras int
color_set(short pair,void * opt)93*51ffecc1SBen Gras color_set(short pair, void *opt)
94*51ffecc1SBen Gras {
95*51ffecc1SBen Gras 	return wcolor_set(stdscr, pair, opt);
96*51ffecc1SBen Gras }
97*51ffecc1SBen Gras 
98*51ffecc1SBen Gras /*
99*51ffecc1SBen Gras  * attron --
100*51ffecc1SBen Gras  *	Test and set attributes on stdscr
101*51ffecc1SBen Gras  */
102*51ffecc1SBen Gras int
attron(int attr)103*51ffecc1SBen Gras attron(int attr)
104*51ffecc1SBen Gras {
105*51ffecc1SBen Gras 	return wattr_on(stdscr, (attr_t) attr, NULL);
106*51ffecc1SBen Gras }
107*51ffecc1SBen Gras 
108*51ffecc1SBen Gras /*
109*51ffecc1SBen Gras  * attroff --
110*51ffecc1SBen Gras  *	Test and unset attributes on stdscr.
111*51ffecc1SBen Gras  */
112*51ffecc1SBen Gras int
attroff(int attr)113*51ffecc1SBen Gras attroff(int attr)
114*51ffecc1SBen Gras {
115*51ffecc1SBen Gras 	return wattr_off(stdscr, (attr_t) attr, NULL);
116*51ffecc1SBen Gras }
117*51ffecc1SBen Gras 
118*51ffecc1SBen Gras /*
119*51ffecc1SBen Gras  * attrset --
120*51ffecc1SBen Gras  *	Set specific attribute modes.
121*51ffecc1SBen Gras  *	Unset others.  On stdscr.
122*51ffecc1SBen Gras  */
123*51ffecc1SBen Gras int
attrset(int attr)124*51ffecc1SBen Gras attrset(int attr)
125*51ffecc1SBen Gras {
126*51ffecc1SBen Gras 	return wattrset(stdscr, attr);
127*51ffecc1SBen Gras }
128*51ffecc1SBen Gras #endif	/* _CURSES_USE_MACROS */
129*51ffecc1SBen Gras 
130*51ffecc1SBen Gras /*
131*51ffecc1SBen Gras  * wattr_get --
132*51ffecc1SBen Gras  *	Get wide attributes and colour pair from window
133*51ffecc1SBen Gras  *	Note that attributes also includes colour.
134*51ffecc1SBen Gras  */
135*51ffecc1SBen Gras /* ARGSUSED */
136*51ffecc1SBen Gras int
wattr_get(WINDOW * win,attr_t * attr,short * pair,void * opt)137*51ffecc1SBen Gras wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opt)
138*51ffecc1SBen Gras {
139*51ffecc1SBen Gras #ifdef DEBUG
140*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win);
141*51ffecc1SBen Gras #endif
142*51ffecc1SBen Gras 	if (attr != NULL) {
143*51ffecc1SBen Gras 		*attr = win->wattr;
144*51ffecc1SBen Gras #ifdef HAVE_WCHAR
145*51ffecc1SBen Gras 		*attr &= WA_ATTRIBUTES;
146*51ffecc1SBen Gras #endif
147*51ffecc1SBen Gras 	}
148*51ffecc1SBen Gras 
149*51ffecc1SBen Gras 	if (pair != NULL)
150*51ffecc1SBen Gras 		*pair = PAIR_NUMBER(win->wattr);
151*51ffecc1SBen Gras 	return OK;
152*51ffecc1SBen Gras }
153*51ffecc1SBen Gras 
154*51ffecc1SBen Gras /*
155*51ffecc1SBen Gras  * wattr_on --
156*51ffecc1SBen Gras  *	Test and set wide attributes on window
157*51ffecc1SBen Gras  */
158*51ffecc1SBen Gras /* ARGSUSED */
159*51ffecc1SBen Gras int
wattr_on(WINDOW * win,attr_t attr,void * opt)160*51ffecc1SBen Gras wattr_on(WINDOW *win, attr_t attr, void *opt)
161*51ffecc1SBen Gras {
162*51ffecc1SBen Gras #ifdef DEBUG
163*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
164*51ffecc1SBen Gras #endif
165*51ffecc1SBen Gras 	/* If can enter modes, set the relevent attribute bits. */
166*51ffecc1SBen Gras 	if (exit_attribute_mode != NULL) {
167*51ffecc1SBen Gras 		if (attr & __BLINK && enter_blink_mode != NULL)
168*51ffecc1SBen Gras 			win->wattr |= __BLINK;
169*51ffecc1SBen Gras 		if (attr & __BOLD && enter_bold_mode != NULL)
170*51ffecc1SBen Gras 			win->wattr |= __BOLD;
171*51ffecc1SBen Gras 		if (attr & __DIM && enter_dim_mode != NULL)
172*51ffecc1SBen Gras 			win->wattr |= __DIM;
173*51ffecc1SBen Gras 		if (attr & __BLANK && enter_secure_mode != NULL)
174*51ffecc1SBen Gras 			win->wattr |= __BLANK;
175*51ffecc1SBen Gras 		if (attr & __PROTECT && enter_protected_mode != NULL)
176*51ffecc1SBen Gras 			win->wattr |= __PROTECT;
177*51ffecc1SBen Gras 		if (attr & __REVERSE && enter_reverse_mode != NULL)
178*51ffecc1SBen Gras 			win->wattr |= __REVERSE;
179*51ffecc1SBen Gras #ifdef HAVE_WCHAR
180*51ffecc1SBen Gras 		if (attr & WA_LOW && enter_low_hl_mode != NULL)
181*51ffecc1SBen Gras 			win->wattr |= WA_LOW;
182*51ffecc1SBen Gras 		if (attr & WA_TOP && enter_top_hl_mode != NULL)
183*51ffecc1SBen Gras 			win->wattr |= WA_TOP;
184*51ffecc1SBen Gras 		if (attr & WA_LEFT && enter_left_hl_mode != NULL)
185*51ffecc1SBen Gras 			win->wattr |= WA_LEFT;
186*51ffecc1SBen Gras 		if (attr & WA_RIGHT && enter_right_hl_mode != NULL)
187*51ffecc1SBen Gras 			win->wattr |= WA_RIGHT;
188*51ffecc1SBen Gras 		if (attr & WA_HORIZONTAL && enter_horizontal_hl_mode != NULL)
189*51ffecc1SBen Gras 			win->wattr |= WA_HORIZONTAL;
190*51ffecc1SBen Gras 		if (attr & WA_VERTICAL && enter_vertical_hl_mode != NULL)
191*51ffecc1SBen Gras 			win->wattr |= WA_VERTICAL;
192*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
193*51ffecc1SBen Gras 	}
194*51ffecc1SBen Gras 	if (attr & __STANDOUT && enter_standout_mode != NULL && exit_standout_mode != NULL)
195*51ffecc1SBen Gras 		wstandout(win);
196*51ffecc1SBen Gras 	if (attr & __UNDERSCORE && enter_underline_mode != NULL && exit_underline_mode != NULL)
197*51ffecc1SBen Gras 		wunderscore(win);
198*51ffecc1SBen Gras 	if ((attr_t) attr & __COLOR)
199*51ffecc1SBen Gras 		__wcolor_set(win, (attr_t) attr);
200*51ffecc1SBen Gras 	return OK;
201*51ffecc1SBen Gras }
202*51ffecc1SBen Gras 
203*51ffecc1SBen Gras /*
204*51ffecc1SBen Gras  * wattr_off --
205*51ffecc1SBen Gras  *	Test and unset wide attributes on window
206*51ffecc1SBen Gras  *
207*51ffecc1SBen Gras  *	Note that the 'me' sequence unsets all attributes.  We handle
208*51ffecc1SBen Gras  *	which attributes should really be set in refresh.c:makech().
209*51ffecc1SBen Gras  */
210*51ffecc1SBen Gras /* ARGSUSED */
211*51ffecc1SBen Gras int
wattr_off(WINDOW * win,attr_t attr,void * opt)212*51ffecc1SBen Gras wattr_off(WINDOW *win, attr_t attr, void *opt)
213*51ffecc1SBen Gras {
214*51ffecc1SBen Gras #ifdef DEBUG
215*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
216*51ffecc1SBen Gras #endif
217*51ffecc1SBen Gras 	/* If can do exit modes, unset the relevent attribute bits. */
218*51ffecc1SBen Gras 	if (exit_attribute_mode != NULL) {
219*51ffecc1SBen Gras 		if (attr & __BLINK)
220*51ffecc1SBen Gras 			win->wattr &= ~__BLINK;
221*51ffecc1SBen Gras 		if (attr & __BOLD)
222*51ffecc1SBen Gras 			win->wattr &= ~__BOLD;
223*51ffecc1SBen Gras 		if (attr & __DIM)
224*51ffecc1SBen Gras 			win->wattr &= ~__DIM;
225*51ffecc1SBen Gras 		if (attr & __BLANK)
226*51ffecc1SBen Gras 			win->wattr &= ~__BLANK;
227*51ffecc1SBen Gras 		if (attr & __PROTECT)
228*51ffecc1SBen Gras 			win->wattr &= ~__PROTECT;
229*51ffecc1SBen Gras 		if (attr & __REVERSE)
230*51ffecc1SBen Gras 			win->wattr &= ~__REVERSE;
231*51ffecc1SBen Gras #ifdef HAVE_WCHAR
232*51ffecc1SBen Gras 		if (attr & WA_LOW)
233*51ffecc1SBen Gras 			win->wattr &= ~WA_LOW;
234*51ffecc1SBen Gras 		if (attr & WA_TOP)
235*51ffecc1SBen Gras 			win->wattr &= ~WA_TOP;
236*51ffecc1SBen Gras 		if (attr & WA_LEFT)
237*51ffecc1SBen Gras 			win->wattr &= ~WA_LEFT;
238*51ffecc1SBen Gras 		if (attr & WA_RIGHT)
239*51ffecc1SBen Gras 			win->wattr &= ~WA_RIGHT;
240*51ffecc1SBen Gras 		if (attr & WA_HORIZONTAL)
241*51ffecc1SBen Gras 			win->wattr &= ~WA_HORIZONTAL;
242*51ffecc1SBen Gras 	if (attr & WA_VERTICAL)
243*51ffecc1SBen Gras 			win->wattr &= ~WA_VERTICAL;
244*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
245*51ffecc1SBen Gras 	}
246*51ffecc1SBen Gras 	if (attr & __STANDOUT)
247*51ffecc1SBen Gras 		wstandend(win);
248*51ffecc1SBen Gras 	if (attr & __UNDERSCORE)
249*51ffecc1SBen Gras 		wunderend(win);
250*51ffecc1SBen Gras 	if ((attr_t) attr & __COLOR) {
251*51ffecc1SBen Gras 		if (max_colors != 0)
252*51ffecc1SBen Gras 			win->wattr &= ~__COLOR;
253*51ffecc1SBen Gras 	}
254*51ffecc1SBen Gras 	return OK;
255*51ffecc1SBen Gras }
256*51ffecc1SBen Gras 
257*51ffecc1SBen Gras /*
258*51ffecc1SBen Gras  * wattr_set --
259*51ffecc1SBen Gras  *	Set wide attributes and color pair on window
260*51ffecc1SBen Gras  */
261*51ffecc1SBen Gras int
wattr_set(WINDOW * win,attr_t attr,short pair,void * opt)262*51ffecc1SBen Gras wattr_set(WINDOW *win, attr_t attr, short pair, void *opt)
263*51ffecc1SBen Gras {
264*51ffecc1SBen Gras #ifdef DEBUG
265*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
266*51ffecc1SBen Gras 	    win, attr, pair);
267*51ffecc1SBen Gras #endif
268*51ffecc1SBen Gras  	wattr_off(win, __ATTRIBUTES, opt);
269*51ffecc1SBen Gras 	/*
270*51ffecc1SBen Gras 	 * This overwrites any colour setting from the attributes
271*51ffecc1SBen Gras 	 * and is compatible with ncurses.
272*51ffecc1SBen Gras 	 */
273*51ffecc1SBen Gras  	attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
274*51ffecc1SBen Gras  	wattr_on(win, attr, opt);
275*51ffecc1SBen Gras 	return OK;
276*51ffecc1SBen Gras }
277*51ffecc1SBen Gras 
278*51ffecc1SBen Gras /*
279*51ffecc1SBen Gras  * wattron --
280*51ffecc1SBen Gras  *	Test and set attributes.
281*51ffecc1SBen Gras  */
282*51ffecc1SBen Gras int
wattron(WINDOW * win,int attr)283*51ffecc1SBen Gras wattron(WINDOW *win, int attr)
284*51ffecc1SBen Gras {
285*51ffecc1SBen Gras #ifdef DEBUG
286*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr);
287*51ffecc1SBen Gras #endif
288*51ffecc1SBen Gras 	return wattr_on(win, (attr_t) attr, NULL);
289*51ffecc1SBen Gras }
290*51ffecc1SBen Gras 
291*51ffecc1SBen Gras /*
292*51ffecc1SBen Gras  * wattroff --
293*51ffecc1SBen Gras  *	Test and unset attributes.
294*51ffecc1SBen Gras  */
295*51ffecc1SBen Gras int
wattroff(WINDOW * win,int attr)296*51ffecc1SBen Gras wattroff(WINDOW *win, int attr)
297*51ffecc1SBen Gras {
298*51ffecc1SBen Gras #ifdef DEBUG
299*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr);
300*51ffecc1SBen Gras #endif
301*51ffecc1SBen Gras 	return wattr_off(win, (attr_t) attr, NULL);
302*51ffecc1SBen Gras }
303*51ffecc1SBen Gras 
304*51ffecc1SBen Gras /*
305*51ffecc1SBen Gras  * wattrset --
306*51ffecc1SBen Gras  *	Set specific attribute modes.
307*51ffecc1SBen Gras  *	Unset others.
308*51ffecc1SBen Gras  */
309*51ffecc1SBen Gras int
wattrset(WINDOW * win,int attr)310*51ffecc1SBen Gras wattrset(WINDOW *win, int attr)
311*51ffecc1SBen Gras {
312*51ffecc1SBen Gras #ifdef DEBUG
313*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr);
314*51ffecc1SBen Gras #endif
315*51ffecc1SBen Gras 	wattr_off(win, __ATTRIBUTES, NULL);
316*51ffecc1SBen Gras 	wattr_on(win, (attr_t) attr, NULL);
317*51ffecc1SBen Gras 	return OK;
318*51ffecc1SBen Gras }
319*51ffecc1SBen Gras 
320*51ffecc1SBen Gras /*
321*51ffecc1SBen Gras  * wcolor_set --
322*51ffecc1SBen Gras  *	Set color pair on window
323*51ffecc1SBen Gras  */
324*51ffecc1SBen Gras /* ARGSUSED */
325*51ffecc1SBen Gras int
wcolor_set(WINDOW * win,short pair,void * opt)326*51ffecc1SBen Gras wcolor_set(WINDOW *win, short pair, void *opt)
327*51ffecc1SBen Gras {
328*51ffecc1SBen Gras #ifdef DEBUG
329*51ffecc1SBen Gras 	__CTRACE(__CTRACE_COLOR, "wolor_set: win %p, pair %d\n", win, pair);
330*51ffecc1SBen Gras #endif
331*51ffecc1SBen Gras 	__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
332*51ffecc1SBen Gras 	return OK;
333*51ffecc1SBen Gras }
334*51ffecc1SBen Gras 
335*51ffecc1SBen Gras /*
336*51ffecc1SBen Gras  * getattrs --
337*51ffecc1SBen Gras  *	Get window attributes.
338*51ffecc1SBen Gras  */
339*51ffecc1SBen Gras chtype
getattrs(WINDOW * win)340*51ffecc1SBen Gras getattrs(WINDOW *win)
341*51ffecc1SBen Gras {
342*51ffecc1SBen Gras #ifdef DEBUG
343*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
344*51ffecc1SBen Gras #endif
345*51ffecc1SBen Gras 	return((chtype) win->wattr);
346*51ffecc1SBen Gras }
347*51ffecc1SBen Gras 
348*51ffecc1SBen Gras /*
349*51ffecc1SBen Gras  * termattrs --
350*51ffecc1SBen Gras  *	Get terminal attributes
351*51ffecc1SBen Gras  */
352*51ffecc1SBen Gras chtype
termattrs(void)353*51ffecc1SBen Gras termattrs(void)
354*51ffecc1SBen Gras {
355*51ffecc1SBen Gras 	chtype ch = 0;
356*51ffecc1SBen Gras 
357*51ffecc1SBen Gras #ifdef DEBUG
358*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "termattrs\n");
359*51ffecc1SBen Gras #endif
360*51ffecc1SBen Gras 	if (exit_attribute_mode != NULL) {
361*51ffecc1SBen Gras #ifdef DEBUG
362*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "termattrs: have exit attribute mode\n");
363*51ffecc1SBen Gras #endif
364*51ffecc1SBen Gras 		if (enter_blink_mode != NULL)
365*51ffecc1SBen Gras 			ch |= __BLINK;
366*51ffecc1SBen Gras 		if (enter_bold_mode != NULL)
367*51ffecc1SBen Gras 			ch |= __BOLD;
368*51ffecc1SBen Gras 		if (enter_dim_mode != NULL)
369*51ffecc1SBen Gras 			ch |= __DIM;
370*51ffecc1SBen Gras 		if (enter_secure_mode != NULL)
371*51ffecc1SBen Gras 			ch |= __BLANK;
372*51ffecc1SBen Gras 		if (enter_protected_mode != NULL)
373*51ffecc1SBen Gras 			ch |= __PROTECT;
374*51ffecc1SBen Gras 		if (enter_reverse_mode != NULL)
375*51ffecc1SBen Gras 			ch |= __REVERSE;
376*51ffecc1SBen Gras 	}
377*51ffecc1SBen Gras 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
378*51ffecc1SBen Gras 		ch |= __STANDOUT;
379*51ffecc1SBen Gras 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
380*51ffecc1SBen Gras 		ch |= __UNDERSCORE;
381*51ffecc1SBen Gras 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
382*51ffecc1SBen Gras 		ch |= __ALTCHARSET;
383*51ffecc1SBen Gras 
384*51ffecc1SBen Gras 	return ch;
385*51ffecc1SBen Gras }
386*51ffecc1SBen Gras 
387*51ffecc1SBen Gras /*
388*51ffecc1SBen Gras  * term_attrs --
389*51ffecc1SBen Gras  *	Get terminal wide attributes
390*51ffecc1SBen Gras  */
391*51ffecc1SBen Gras attr_t
term_attrs(void)392*51ffecc1SBen Gras term_attrs(void)
393*51ffecc1SBen Gras {
394*51ffecc1SBen Gras 	attr_t attr = 0;
395*51ffecc1SBen Gras 
396*51ffecc1SBen Gras #ifdef DEBUG
397*51ffecc1SBen Gras 	__CTRACE(__CTRACE_ATTR, "term_attrs\n");
398*51ffecc1SBen Gras #endif
399*51ffecc1SBen Gras 	if (exit_attribute_mode != NULL) {
400*51ffecc1SBen Gras 		if (enter_blink_mode != NULL)
401*51ffecc1SBen Gras 			attr |= __BLINK;
402*51ffecc1SBen Gras 		if (enter_bold_mode != NULL)
403*51ffecc1SBen Gras 			attr |= __BOLD;
404*51ffecc1SBen Gras 		if (enter_dim_mode != NULL)
405*51ffecc1SBen Gras 			attr |= __DIM;
406*51ffecc1SBen Gras 		if (enter_secure_mode != NULL)
407*51ffecc1SBen Gras 			attr |= __BLANK;
408*51ffecc1SBen Gras 		if (enter_protected_mode != NULL)
409*51ffecc1SBen Gras 			attr |= __PROTECT;
410*51ffecc1SBen Gras 		if (enter_reverse_mode != NULL)
411*51ffecc1SBen Gras 			attr |= __REVERSE;
412*51ffecc1SBen Gras #ifdef HAVE_WCHAR
413*51ffecc1SBen Gras 		if (enter_low_hl_mode != NULL)
414*51ffecc1SBen Gras 			attr |= WA_LOW;
415*51ffecc1SBen Gras 		if (enter_top_hl_mode != NULL)
416*51ffecc1SBen Gras 			attr |= WA_TOP;
417*51ffecc1SBen Gras 		if (enter_left_hl_mode != NULL)
418*51ffecc1SBen Gras 			attr |= WA_LEFT;
419*51ffecc1SBen Gras 		if (enter_right_hl_mode != NULL)
420*51ffecc1SBen Gras 			attr |= WA_RIGHT;
421*51ffecc1SBen Gras 		if (enter_horizontal_hl_mode != NULL)
422*51ffecc1SBen Gras 			attr |= WA_HORIZONTAL;
423*51ffecc1SBen Gras 		if (enter_vertical_hl_mode != NULL)
424*51ffecc1SBen Gras 			attr |= WA_VERTICAL;
425*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
426*51ffecc1SBen Gras 	}
427*51ffecc1SBen Gras 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
428*51ffecc1SBen Gras 		attr |= __STANDOUT;
429*51ffecc1SBen Gras 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
430*51ffecc1SBen Gras 		attr |= __UNDERSCORE;
431*51ffecc1SBen Gras 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
432*51ffecc1SBen Gras 		attr |= __ALTCHARSET;
433*51ffecc1SBen Gras 
434*51ffecc1SBen Gras 	return attr;
435*51ffecc1SBen Gras }
436*51ffecc1SBen Gras 
437*51ffecc1SBen Gras /*
438*51ffecc1SBen Gras  * __wcolor_set --
439*51ffecc1SBen Gras  * Set color attribute on window
440*51ffecc1SBen Gras  */
441*51ffecc1SBen Gras void
__wcolor_set(WINDOW * win,attr_t attr)442*51ffecc1SBen Gras __wcolor_set(WINDOW *win, attr_t attr)
443*51ffecc1SBen Gras {
444*51ffecc1SBen Gras 	/* If another color pair is set, turn that off first. */
445*51ffecc1SBen Gras 	win->wattr &= ~__COLOR;
446*51ffecc1SBen Gras 	/* If can do color video, set the color pair bits. */
447*51ffecc1SBen Gras 	if (max_colors != 0 && attr & __COLOR)
448*51ffecc1SBen Gras 		win->wattr |= attr & __COLOR;
449*51ffecc1SBen Gras }
450