xref: /netbsd-src/lib/libcurses/attributes.c (revision 19b437abe9d6be28c72a9ca9650cad2ee75bf94e)
1*19b437abSuwe /*	$NetBSD: attributes.c,v 1.28 2018/11/23 11:15:14 uwe Exp $	*/
2586d4ce1Smrg 
3f0469424Sjdc /*-
4f0469424Sjdc  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5586d4ce1Smrg  * All rights reserved.
6586d4ce1Smrg  *
7f0469424Sjdc  * This code is derived from software contributed to The NetBSD Foundation
8f0469424Sjdc  * by Julian Coleman.
9f0469424Sjdc  *
10586d4ce1Smrg  * Redistribution and use in source and binary forms, with or without
11586d4ce1Smrg  * modification, are permitted provided that the following conditions
12586d4ce1Smrg  * are met:
13586d4ce1Smrg  * 1. Redistributions of source code must retain the above copyright
14586d4ce1Smrg  *    notice, this list of conditions and the following disclaimer.
15f0469424Sjdc  * 2. Redistributions in binary form must reproduce the above copyright
16f0469424Sjdc  *    notice, this list of conditions and the following disclaimer in the
17f0469424Sjdc  *    documentation and/or other materials provided with the distribution.
18586d4ce1Smrg  *
19f0469424Sjdc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20f0469424Sjdc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21f0469424Sjdc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f0469424Sjdc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23f0469424Sjdc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24f0469424Sjdc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25f0469424Sjdc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26f0469424Sjdc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27f0469424Sjdc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28f0469424Sjdc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29f0469424Sjdc  * POSSIBILITY OF SUCH DAMAGE.
30586d4ce1Smrg  */
31586d4ce1Smrg 
3266cab71cSblymn #include <sys/cdefs.h>
3366cab71cSblymn #ifndef lint
34*19b437abSuwe __RCSID("$NetBSD: attributes.c,v 1.28 2018/11/23 11:15:14 uwe Exp $");
3566cab71cSblymn #endif				/* not lint */
3666cab71cSblymn 
37586d4ce1Smrg #include "curses.h"
3823464ee5Sblymn #include "curses_private.h"
39586d4ce1Smrg 
4044b007caSuwe static int __wattr_off(WINDOW *, attr_t);
4144b007caSuwe static int __wattr_on(WINDOW *, attr_t);
42485cf054Suwe static void __wcolor_set(WINDOW *, attr_t);
43b5eb0508Sjdc 
4444b007caSuwe 
45aaf74682Sblymn #ifndef _CURSES_USE_MACROS
46aaf74682Sblymn /*
47b5eb0508Sjdc  * attr_get --
4880b22938Sjdc  *	Get wide attributes and color pair from stdscr
49b5eb0508Sjdc  */
50b5eb0508Sjdc /* ARGSUSED */
51b5eb0508Sjdc int
52*19b437abSuwe attr_get(attr_t *attr, short *pair, void *opts)
53b5eb0508Sjdc {
54*19b437abSuwe 	return wattr_get(stdscr, attr, pair, opts);
55b5eb0508Sjdc }
56b5eb0508Sjdc 
57b5eb0508Sjdc /*
58b5eb0508Sjdc  * attr_on --
5980b22938Sjdc  *	Test and set wide attributes on stdscr
60b5eb0508Sjdc  */
61b5eb0508Sjdc /* ARGSUSED */
62b5eb0508Sjdc int
63*19b437abSuwe attr_on(attr_t attr, void *opts)
64b5eb0508Sjdc {
65*19b437abSuwe 	return wattr_on(stdscr, attr, opts);
66b5eb0508Sjdc }
67b5eb0508Sjdc 
68b5eb0508Sjdc /*
69b5eb0508Sjdc  * attr_off --
7080b22938Sjdc  *	Test and unset wide attributes on stdscr
71b5eb0508Sjdc  */
72b5eb0508Sjdc /* ARGSUSED */
73b5eb0508Sjdc int
74*19b437abSuwe attr_off(attr_t attr, void *opts)
75b5eb0508Sjdc {
76*19b437abSuwe 	return wattr_off(stdscr, attr, opts);
77b5eb0508Sjdc }
78b5eb0508Sjdc 
79b5eb0508Sjdc /*
80b5eb0508Sjdc  * attr_set --
8180b22938Sjdc  *	Set wide attributes and color pair on stdscr
82b5eb0508Sjdc  */
83b5eb0508Sjdc /* ARGSUSED */
84b5eb0508Sjdc int
85*19b437abSuwe attr_set(attr_t attr, short pair, void *opts)
86b5eb0508Sjdc {
87*19b437abSuwe 	return wattr_set(stdscr, attr, pair, opts);
88b5eb0508Sjdc }
89b5eb0508Sjdc 
90b5eb0508Sjdc /*
91b5eb0508Sjdc  * color_set --
92b5eb0508Sjdc  *	Set color pair on stdscr
93b5eb0508Sjdc  */
94b5eb0508Sjdc /* ARGSUSED */
95b5eb0508Sjdc int
96*19b437abSuwe color_set(short pair, void *opts)
97b5eb0508Sjdc {
98*19b437abSuwe 	return wcolor_set(stdscr, pair, opts);
99b5eb0508Sjdc }
100b5eb0508Sjdc 
101b5eb0508Sjdc /*
1024cb1d6d3Sjdc  * attron --
103aaf74682Sblymn  *	Test and set attributes on stdscr
104aaf74682Sblymn  */
105aaf74682Sblymn int
106aaf74682Sblymn attron(int attr)
107aaf74682Sblymn {
10844b007caSuwe 	return __wattr_on(stdscr, (attr_t) attr);
109aaf74682Sblymn }
110aaf74682Sblymn 
111aaf74682Sblymn /*
1124cb1d6d3Sjdc  * attroff --
113aaf74682Sblymn  *	Test and unset attributes on stdscr.
114aaf74682Sblymn  */
115aaf74682Sblymn int
116aaf74682Sblymn attroff(int attr)
117aaf74682Sblymn {
11844b007caSuwe 	return __wattr_off(stdscr, (attr_t) attr);
119aaf74682Sblymn }
120aaf74682Sblymn 
121aaf74682Sblymn /*
1224cb1d6d3Sjdc  * attrset --
123aaf74682Sblymn  *	Set specific attribute modes.
124aaf74682Sblymn  *	Unset others.  On stdscr.
125aaf74682Sblymn  */
126aaf74682Sblymn int
127aaf74682Sblymn attrset(int attr)
128aaf74682Sblymn {
129aaf74682Sblymn 	return wattrset(stdscr, attr);
130aaf74682Sblymn }
131b5eb0508Sjdc #endif	/* _CURSES_USE_MACROS */
132aaf74682Sblymn 
133b5eb0508Sjdc /*
134b5eb0508Sjdc  * wattr_get --
13580b22938Sjdc  *	Get wide attributes and colour pair from window
136b5eb0508Sjdc  *	Note that attributes also includes colour.
137b5eb0508Sjdc  */
138b5eb0508Sjdc /* ARGSUSED */
139b5eb0508Sjdc int
140*19b437abSuwe wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opts)
141b5eb0508Sjdc {
142b5eb0508Sjdc #ifdef DEBUG
1431f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win);
144aaf74682Sblymn #endif
145e124de36Sblymn 	if (attr != NULL) {
146b5eb0508Sjdc 		*attr = win->wattr;
147e124de36Sblymn #ifdef HAVE_WCHAR
148e124de36Sblymn 		*attr &= WA_ATTRIBUTES;
149e124de36Sblymn #endif
150e124de36Sblymn 	}
151e124de36Sblymn 
152b5eb0508Sjdc 	if (pair != NULL)
153b5eb0508Sjdc 		*pair = PAIR_NUMBER(win->wattr);
154b5eb0508Sjdc 	return OK;
155b5eb0508Sjdc }
156b5eb0508Sjdc 
157b5eb0508Sjdc /*
158b5eb0508Sjdc  * wattr_on --
15980b22938Sjdc  *	Test and set wide attributes on window
160b5eb0508Sjdc  */
161b5eb0508Sjdc int
162*19b437abSuwe wattr_on(WINDOW *win, attr_t attr, void *opts)
163b5eb0508Sjdc {
164*19b437abSuwe 	if (__predict_false(opts != NULL))
16544b007caSuwe 		return ERR;
166e56dac4eSroy 
16744b007caSuwe 	return __wattr_on(win, attr);
168b5eb0508Sjdc }
169b5eb0508Sjdc 
170b5eb0508Sjdc /*
171b5eb0508Sjdc  * wattr_off --
17280b22938Sjdc  *	Test and unset wide attributes on window
173b5eb0508Sjdc  *
174b5eb0508Sjdc  *	Note that the 'me' sequence unsets all attributes.  We handle
175b5eb0508Sjdc  *	which attributes should really be set in refresh.c:makech().
176b5eb0508Sjdc  */
177b5eb0508Sjdc int
178*19b437abSuwe wattr_off(WINDOW *win, attr_t attr, void *opts)
179b5eb0508Sjdc {
180*19b437abSuwe 	if (__predict_false(opts != NULL))
18144b007caSuwe 		return ERR;
182e56dac4eSroy 
18344b007caSuwe 	return __wattr_off(win, attr);
184b5eb0508Sjdc }
18544b007caSuwe 
186b5eb0508Sjdc 
187b5eb0508Sjdc /*
188b5eb0508Sjdc  * wattr_set --
18980b22938Sjdc  *	Set wide attributes and color pair on window
190b5eb0508Sjdc  */
191b5eb0508Sjdc int
192*19b437abSuwe wattr_set(WINDOW *win, attr_t attr, short pair, void *opts)
193b5eb0508Sjdc {
194b5eb0508Sjdc #ifdef DEBUG
1951f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
1961f221324Sjdc 	    win, attr, pair);
197b5eb0508Sjdc #endif
198*19b437abSuwe 	if (__predict_false(opts != NULL))
19944b007caSuwe 		return ERR;
20044b007caSuwe 
201b5eb0508Sjdc 	/*
202b5eb0508Sjdc 	 * This overwrites any colour setting from the attributes
203b5eb0508Sjdc 	 * and is compatible with ncurses.
204b5eb0508Sjdc 	 */
205e124de36Sblymn 	attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
20644b007caSuwe 
20744b007caSuwe 	__wattr_off(win, __ATTRIBUTES);
20844b007caSuwe 	__wattr_on(win, attr);
209b5eb0508Sjdc 	return OK;
210b5eb0508Sjdc }
211aaf74682Sblymn 
212586d4ce1Smrg /*
213485cf054Suwe  * wcolor_set --
214485cf054Suwe  *	Set color pair on window
215485cf054Suwe  */
216485cf054Suwe /* ARGSUSED */
217485cf054Suwe int
218*19b437abSuwe wcolor_set(WINDOW *win, short pair, void *opts)
219485cf054Suwe {
220485cf054Suwe #ifdef DEBUG
221485cf054Suwe 	__CTRACE(__CTRACE_COLOR, "wolor_set: win %p, pair %d\n", win, pair);
222485cf054Suwe #endif
223485cf054Suwe 	__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
224485cf054Suwe 	return OK;
225485cf054Suwe }
226485cf054Suwe 
227485cf054Suwe /*
228485cf054Suwe  * getattrs --
229485cf054Suwe  *	Get window attributes.
230485cf054Suwe  */
231485cf054Suwe chtype
232485cf054Suwe getattrs(WINDOW *win)
233485cf054Suwe {
234485cf054Suwe #ifdef DEBUG
235485cf054Suwe 	__CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
236485cf054Suwe #endif
237485cf054Suwe 	return((chtype) win->wattr);
238485cf054Suwe }
239485cf054Suwe 
240485cf054Suwe /*
2414cb1d6d3Sjdc  * wattron --
242586d4ce1Smrg  *	Test and set attributes.
243586d4ce1Smrg  */
244586d4ce1Smrg int
245aaf74682Sblymn wattron(WINDOW *win, int attr)
246586d4ce1Smrg {
247586d4ce1Smrg #ifdef DEBUG
2481f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr);
249586d4ce1Smrg #endif
25044b007caSuwe 	return __wattr_on(win, (attr_t) attr);
251586d4ce1Smrg }
252586d4ce1Smrg 
253586d4ce1Smrg /*
2544cb1d6d3Sjdc  * wattroff --
255586d4ce1Smrg  *	Test and unset attributes.
256586d4ce1Smrg  */
257586d4ce1Smrg int
258aaf74682Sblymn wattroff(WINDOW *win, int attr)
259586d4ce1Smrg {
260f0469424Sjdc #ifdef DEBUG
2611f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr);
262f0469424Sjdc #endif
26344b007caSuwe 	return __wattr_off(win, (attr_t) attr);
264586d4ce1Smrg }
265586d4ce1Smrg 
266586d4ce1Smrg /*
2674cb1d6d3Sjdc  * wattrset --
268586d4ce1Smrg  *	Set specific attribute modes.
269586d4ce1Smrg  *	Unset others.
270586d4ce1Smrg  */
271586d4ce1Smrg int
272aaf74682Sblymn wattrset(WINDOW *win, int attr)
273586d4ce1Smrg {
2745daa1795Sjdc #ifdef DEBUG
2751f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr);
2765daa1795Sjdc #endif
27744b007caSuwe 	__wattr_off(win, __ATTRIBUTES);
27844b007caSuwe 	__wattr_on(win, (attr_t) attr);
279b5eb0508Sjdc 	return OK;
280b5eb0508Sjdc }
281b5eb0508Sjdc 
282b5eb0508Sjdc /*
28380b22938Sjdc  * termattrs --
28480b22938Sjdc  *	Get terminal attributes
28580b22938Sjdc  */
28680b22938Sjdc chtype
28780b22938Sjdc termattrs(void)
28880b22938Sjdc {
28960683edbSyamt 	chtype ch = 0;
29060683edbSyamt 
29180b22938Sjdc #ifdef DEBUG
29280b22938Sjdc 	__CTRACE(__CTRACE_ATTR, "termattrs\n");
29380b22938Sjdc #endif
29498eb8895Sroy 	if (exit_attribute_mode != NULL) {
295bcc3426fSblymn #ifdef DEBUG
296bcc3426fSblymn 	__CTRACE(__CTRACE_ATTR, "termattrs: have exit attribute mode\n");
297bcc3426fSblymn #endif
29898eb8895Sroy 		if (enter_blink_mode != NULL)
29980b22938Sjdc 			ch |= __BLINK;
30098eb8895Sroy 		if (enter_bold_mode != NULL)
30180b22938Sjdc 			ch |= __BOLD;
30298eb8895Sroy 		if (enter_dim_mode != NULL)
30380b22938Sjdc 			ch |= __DIM;
30498eb8895Sroy 		if (enter_secure_mode != NULL)
30580b22938Sjdc 			ch |= __BLANK;
30698eb8895Sroy 		if (enter_protected_mode != NULL)
30780b22938Sjdc 			ch |= __PROTECT;
30898eb8895Sroy 		if (enter_reverse_mode != NULL)
30980b22938Sjdc 			ch |= __REVERSE;
31080b22938Sjdc 	}
31198eb8895Sroy 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
31280b22938Sjdc 		ch |= __STANDOUT;
31398eb8895Sroy 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
31480b22938Sjdc 		ch |= __UNDERSCORE;
31598eb8895Sroy 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
31680b22938Sjdc 		ch |= __ALTCHARSET;
31780b22938Sjdc 
31880b22938Sjdc 	return ch;
31980b22938Sjdc }
32080b22938Sjdc 
32180b22938Sjdc /*
32280b22938Sjdc  * term_attrs --
32380b22938Sjdc  *	Get terminal wide attributes
32480b22938Sjdc  */
32580b22938Sjdc attr_t
32680b22938Sjdc term_attrs(void)
32780b22938Sjdc {
32860683edbSyamt 	attr_t attr = 0;
32960683edbSyamt 
33080b22938Sjdc #ifdef DEBUG
33180b22938Sjdc 	__CTRACE(__CTRACE_ATTR, "term_attrs\n");
33280b22938Sjdc #endif
33398eb8895Sroy 	if (exit_attribute_mode != NULL) {
33498eb8895Sroy 		if (enter_blink_mode != NULL)
335afd69f43Sjdc 			attr |= __BLINK;
33698eb8895Sroy 		if (enter_bold_mode != NULL)
337afd69f43Sjdc 			attr |= __BOLD;
33898eb8895Sroy 		if (enter_dim_mode != NULL)
339afd69f43Sjdc 			attr |= __DIM;
34098eb8895Sroy 		if (enter_secure_mode != NULL)
341afd69f43Sjdc 			attr |= __BLANK;
34298eb8895Sroy 		if (enter_protected_mode != NULL)
343afd69f43Sjdc 			attr |= __PROTECT;
34498eb8895Sroy 		if (enter_reverse_mode != NULL)
345afd69f43Sjdc 			attr |= __REVERSE;
34680b22938Sjdc #ifdef HAVE_WCHAR
34798eb8895Sroy 		if (enter_low_hl_mode != NULL)
34880b22938Sjdc 			attr |= WA_LOW;
34998eb8895Sroy 		if (enter_top_hl_mode != NULL)
35080b22938Sjdc 			attr |= WA_TOP;
35198eb8895Sroy 		if (enter_left_hl_mode != NULL)
35280b22938Sjdc 			attr |= WA_LEFT;
35398eb8895Sroy 		if (enter_right_hl_mode != NULL)
35480b22938Sjdc 			attr |= WA_RIGHT;
35598eb8895Sroy 		if (enter_horizontal_hl_mode != NULL)
35680b22938Sjdc 			attr |= WA_HORIZONTAL;
35798eb8895Sroy 		if (enter_vertical_hl_mode != NULL)
35880b22938Sjdc 			attr |= WA_VERTICAL;
35980b22938Sjdc #endif /* HAVE_WCHAR */
36080b22938Sjdc 	}
36198eb8895Sroy 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
362afd69f43Sjdc 		attr |= __STANDOUT;
36398eb8895Sroy 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
364afd69f43Sjdc 		attr |= __UNDERSCORE;
36598eb8895Sroy 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
366afd69f43Sjdc 		attr |= __ALTCHARSET;
36780b22938Sjdc 
36880b22938Sjdc 	return attr;
36980b22938Sjdc }
37080b22938Sjdc 
37144b007caSuwe 
37244b007caSuwe static int
37344b007caSuwe __wattr_on(WINDOW *win, attr_t attr)
37444b007caSuwe {
37544b007caSuwe 	const TERMINAL *t = win->screen->term;
37644b007caSuwe 
37744b007caSuwe #ifdef DEBUG
37844b007caSuwe 	__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
37944b007caSuwe #endif
38044b007caSuwe 	/* If can enter modes, set the relevent attribute bits. */
38144b007caSuwe 	if (t_exit_attribute_mode(t) != NULL) {
38244b007caSuwe 		if (attr & __BLINK && t_enter_blink_mode(t) != NULL)
38344b007caSuwe 			win->wattr |= __BLINK;
38444b007caSuwe 		if (attr & __BOLD && t_enter_bold_mode(t) != NULL)
38544b007caSuwe 			win->wattr |= __BOLD;
38644b007caSuwe 		if (attr & __DIM && t_enter_dim_mode(t) != NULL)
38744b007caSuwe 			win->wattr |= __DIM;
38844b007caSuwe 		if (attr & __BLANK && t_enter_secure_mode(t) != NULL)
38944b007caSuwe 			win->wattr |= __BLANK;
39044b007caSuwe 		if (attr & __PROTECT && t_enter_protected_mode(t) != NULL)
39144b007caSuwe 			win->wattr |= __PROTECT;
39244b007caSuwe 		if (attr & __REVERSE && t_enter_reverse_mode(t) != NULL)
39344b007caSuwe 			win->wattr |= __REVERSE;
39444b007caSuwe #ifdef HAVE_WCHAR
39544b007caSuwe 		if (attr & WA_LOW && t_enter_low_hl_mode(t) != NULL)
39644b007caSuwe 			win->wattr |= WA_LOW;
39744b007caSuwe 		if (attr & WA_TOP && t_enter_top_hl_mode(t) != NULL)
39844b007caSuwe 			win->wattr |= WA_TOP;
39944b007caSuwe 		if (attr & WA_LEFT && t_enter_left_hl_mode(t) != NULL)
40044b007caSuwe 			win->wattr |= WA_LEFT;
40144b007caSuwe 		if (attr & WA_RIGHT && t_enter_right_hl_mode(t) != NULL)
40244b007caSuwe 			win->wattr |= WA_RIGHT;
40344b007caSuwe 		if (attr & WA_HORIZONTAL && t_enter_horizontal_hl_mode(t) != NULL)
40444b007caSuwe 			win->wattr |= WA_HORIZONTAL;
40544b007caSuwe 		if (attr & WA_VERTICAL && t_enter_vertical_hl_mode(t) != NULL)
40644b007caSuwe 			win->wattr |= WA_VERTICAL;
40744b007caSuwe #endif /* HAVE_WCHAR */
40844b007caSuwe 	}
40944b007caSuwe 	if (attr & __STANDOUT && t_enter_standout_mode(t) != NULL &&
41044b007caSuwe 	    t_exit_standout_mode(t) != NULL)
41144b007caSuwe 		wstandout(win);
41244b007caSuwe 	if (attr & __UNDERSCORE && t_enter_underline_mode(t) != NULL &&
41344b007caSuwe 	    t_exit_underline_mode(t) != NULL)
41444b007caSuwe 		wunderscore(win);
41544b007caSuwe 	if (attr & __COLOR)
41644b007caSuwe 		__wcolor_set(win, attr);
41744b007caSuwe 	return OK;
41844b007caSuwe }
41944b007caSuwe 
42044b007caSuwe 
42144b007caSuwe static int
42244b007caSuwe __wattr_off(WINDOW *win, attr_t attr)
42344b007caSuwe {
42444b007caSuwe 	const TERMINAL *t = win->screen->term;
42544b007caSuwe 
42644b007caSuwe #ifdef DEBUG
42744b007caSuwe 	__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
42844b007caSuwe #endif
42944b007caSuwe 	/* If can do exit modes, unset the relevent attribute bits. */
43044b007caSuwe 	if (t_exit_attribute_mode(t) != NULL) {
43144b007caSuwe 		if (attr & __BLINK)
43244b007caSuwe 			win->wattr &= ~__BLINK;
43344b007caSuwe 		if (attr & __BOLD)
43444b007caSuwe 			win->wattr &= ~__BOLD;
43544b007caSuwe 		if (attr & __DIM)
43644b007caSuwe 			win->wattr &= ~__DIM;
43744b007caSuwe 		if (attr & __BLANK)
43844b007caSuwe 			win->wattr &= ~__BLANK;
43944b007caSuwe 		if (attr & __PROTECT)
44044b007caSuwe 			win->wattr &= ~__PROTECT;
44144b007caSuwe 		if (attr & __REVERSE)
44244b007caSuwe 			win->wattr &= ~__REVERSE;
44344b007caSuwe #ifdef HAVE_WCHAR
44444b007caSuwe 		if (attr & WA_LOW)
44544b007caSuwe 			win->wattr &= ~WA_LOW;
44644b007caSuwe 		if (attr & WA_TOP)
44744b007caSuwe 			win->wattr &= ~WA_TOP;
44844b007caSuwe 		if (attr & WA_LEFT)
44944b007caSuwe 			win->wattr &= ~WA_LEFT;
45044b007caSuwe 		if (attr & WA_RIGHT)
45144b007caSuwe 			win->wattr &= ~WA_RIGHT;
45244b007caSuwe 		if (attr & WA_HORIZONTAL)
45344b007caSuwe 			win->wattr &= ~WA_HORIZONTAL;
45444b007caSuwe 		if (attr & WA_VERTICAL)
45544b007caSuwe 			win->wattr &= ~WA_VERTICAL;
45644b007caSuwe #endif /* HAVE_WCHAR */
45744b007caSuwe 	}
45844b007caSuwe 	if (attr & __STANDOUT)
45944b007caSuwe 		wstandend(win);
46044b007caSuwe 	if (attr & __UNDERSCORE)
46144b007caSuwe 		wunderend(win);
46244b007caSuwe 	if (attr & __COLOR) {
46344b007caSuwe 		if (max_colors != 0)
46444b007caSuwe 			win->wattr &= ~__COLOR;
46544b007caSuwe 	}
46644b007caSuwe 	return OK;
46744b007caSuwe }
46844b007caSuwe 
46944b007caSuwe 
470485cf054Suwe static void
471b5eb0508Sjdc __wcolor_set(WINDOW *win, attr_t attr)
472b5eb0508Sjdc {
473e56dac4eSroy 	const TERMINAL *t = win->screen->term;
474e56dac4eSroy 
475b5eb0508Sjdc 	/* If another color pair is set, turn that off first. */
476b5eb0508Sjdc 	win->wattr &= ~__COLOR;
477b5eb0508Sjdc 	/* If can do color video, set the color pair bits. */
478e56dac4eSroy 	if (t_max_colors(t) != 0 && attr & __COLOR)
479b5eb0508Sjdc 		win->wattr |= attr & __COLOR;
480b5eb0508Sjdc }
481