xref: /netbsd-src/lib/libcurses/attributes.c (revision 6348e3f32a4431b45d07e1da16fd7b12725a45e7)
1*6348e3f3Sblymn /*	$NetBSD: attributes.c,v 1.36 2024/12/23 02:58:03 blymn 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*6348e3f3Sblymn __RCSID("$NetBSD: attributes.c,v 1.36 2024/12/23 02:58:03 blymn 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
467e8b9e03Suwe #ifdef HAVE_WCHAR
47aaf74682Sblymn /*
48b5eb0508Sjdc  * attr_get --
4980b22938Sjdc  *	Get wide attributes and color pair from stdscr
50b5eb0508Sjdc  */
51b5eb0508Sjdc /* ARGSUSED */
52b5eb0508Sjdc int
5319b437abSuwe attr_get(attr_t *attr, short *pair, void *opts)
54b5eb0508Sjdc {
5519b437abSuwe 	return wattr_get(stdscr, attr, pair, opts);
56b5eb0508Sjdc }
57b5eb0508Sjdc 
58b5eb0508Sjdc /*
59b5eb0508Sjdc  * attr_on --
6080b22938Sjdc  *	Test and set wide attributes on stdscr
61b5eb0508Sjdc  */
62b5eb0508Sjdc /* ARGSUSED */
63b5eb0508Sjdc int
6419b437abSuwe attr_on(attr_t attr, void *opts)
65b5eb0508Sjdc {
6619b437abSuwe 	return wattr_on(stdscr, attr, opts);
67b5eb0508Sjdc }
68b5eb0508Sjdc 
69b5eb0508Sjdc /*
70b5eb0508Sjdc  * attr_off --
7180b22938Sjdc  *	Test and unset wide attributes on stdscr
72b5eb0508Sjdc  */
73b5eb0508Sjdc /* ARGSUSED */
74b5eb0508Sjdc int
7519b437abSuwe attr_off(attr_t attr, void *opts)
76b5eb0508Sjdc {
7719b437abSuwe 	return wattr_off(stdscr, attr, opts);
78b5eb0508Sjdc }
79b5eb0508Sjdc 
80b5eb0508Sjdc /*
81b5eb0508Sjdc  * attr_set --
8280b22938Sjdc  *	Set wide attributes and color pair on stdscr
83b5eb0508Sjdc  */
84b5eb0508Sjdc /* ARGSUSED */
85b5eb0508Sjdc int
8619b437abSuwe attr_set(attr_t attr, short pair, void *opts)
87b5eb0508Sjdc {
8819b437abSuwe 	return wattr_set(stdscr, attr, pair, opts);
89b5eb0508Sjdc }
90b5eb0508Sjdc 
91b5eb0508Sjdc /*
92b5eb0508Sjdc  * color_set --
93b5eb0508Sjdc  *	Set color pair on stdscr
94b5eb0508Sjdc  */
95b5eb0508Sjdc /* ARGSUSED */
96b5eb0508Sjdc int
9719b437abSuwe color_set(short pair, void *opts)
98b5eb0508Sjdc {
9919b437abSuwe 	return wcolor_set(stdscr, pair, opts);
100b5eb0508Sjdc }
1017e8b9e03Suwe #endif /* HAVE_WCHAR */
102b5eb0508Sjdc 
103b5eb0508Sjdc /*
1044cb1d6d3Sjdc  * attron --
105aaf74682Sblymn  *	Test and set attributes on stdscr
106aaf74682Sblymn  */
107aaf74682Sblymn int
108aaf74682Sblymn attron(int attr)
109aaf74682Sblymn {
11080d62aa1Suwe 	return wattron(stdscr, attr);
111aaf74682Sblymn }
112aaf74682Sblymn 
113aaf74682Sblymn /*
1144cb1d6d3Sjdc  * attroff --
115aaf74682Sblymn  *	Test and unset attributes on stdscr.
116aaf74682Sblymn  */
117aaf74682Sblymn int
118aaf74682Sblymn attroff(int attr)
119aaf74682Sblymn {
12080d62aa1Suwe 	return wattroff(stdscr, attr);
121aaf74682Sblymn }
122aaf74682Sblymn 
123aaf74682Sblymn /*
1244cb1d6d3Sjdc  * attrset --
125aaf74682Sblymn  *	Set specific attribute modes.
126aaf74682Sblymn  *	Unset others.  On stdscr.
127aaf74682Sblymn  */
128aaf74682Sblymn int
129aaf74682Sblymn attrset(int attr)
130aaf74682Sblymn {
131aaf74682Sblymn 	return wattrset(stdscr, attr);
132aaf74682Sblymn }
133b5eb0508Sjdc #endif	/* _CURSES_USE_MACROS */
134aaf74682Sblymn 
1357e8b9e03Suwe 
1367e8b9e03Suwe #ifdef HAVE_WCHAR
137b5eb0508Sjdc /*
138b5eb0508Sjdc  * wattr_get --
13980b22938Sjdc  *	Get wide attributes and colour pair from window
140b5eb0508Sjdc  *	Note that attributes also includes colour.
141b5eb0508Sjdc  */
142b5eb0508Sjdc /* ARGSUSED */
143b5eb0508Sjdc int
14419b437abSuwe wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opts)
145b5eb0508Sjdc {
1464b1b7fd7Sblymn 	if (__predict_false(win == NULL))
1474b1b7fd7Sblymn 		return ERR;
1484b1b7fd7Sblymn 
1491f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win);
150e124de36Sblymn 	if (attr != NULL) {
151b5eb0508Sjdc 		*attr = win->wattr;
152e124de36Sblymn #ifdef HAVE_WCHAR
153e124de36Sblymn 		*attr &= WA_ATTRIBUTES;
154e124de36Sblymn #endif
155e124de36Sblymn 	}
156e124de36Sblymn 
157b5eb0508Sjdc 	if (pair != NULL)
158b5eb0508Sjdc 		*pair = PAIR_NUMBER(win->wattr);
159b5eb0508Sjdc 	return OK;
160b5eb0508Sjdc }
161b5eb0508Sjdc 
162b5eb0508Sjdc /*
163b5eb0508Sjdc  * wattr_on --
16480b22938Sjdc  *	Test and set wide attributes on window
165b5eb0508Sjdc  */
166b5eb0508Sjdc int
16719b437abSuwe wattr_on(WINDOW *win, attr_t attr, void *opts)
168b5eb0508Sjdc {
16919b437abSuwe 	if (__predict_false(opts != NULL))
17044b007caSuwe 		return ERR;
171e56dac4eSroy 
17244b007caSuwe 	return __wattr_on(win, attr);
173b5eb0508Sjdc }
174b5eb0508Sjdc 
175b5eb0508Sjdc /*
176b5eb0508Sjdc  * wattr_off --
17780b22938Sjdc  *	Test and unset wide attributes on window
178b5eb0508Sjdc  *
179b5eb0508Sjdc  *	Note that the 'me' sequence unsets all attributes.  We handle
180b5eb0508Sjdc  *	which attributes should really be set in refresh.c:makech().
181b5eb0508Sjdc  */
182b5eb0508Sjdc int
18319b437abSuwe wattr_off(WINDOW *win, attr_t attr, void *opts)
184b5eb0508Sjdc {
18519b437abSuwe 	if (__predict_false(opts != NULL))
18644b007caSuwe 		return ERR;
187e56dac4eSroy 
18844b007caSuwe 	return __wattr_off(win, attr);
189b5eb0508Sjdc }
19044b007caSuwe 
191b5eb0508Sjdc 
192b5eb0508Sjdc /*
193b5eb0508Sjdc  * wattr_set --
19480b22938Sjdc  *	Set wide attributes and color pair on window
195b5eb0508Sjdc  */
196b5eb0508Sjdc int
19719b437abSuwe wattr_set(WINDOW *win, attr_t attr, short pair, void *opts)
198b5eb0508Sjdc {
1991f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
2001f221324Sjdc 	    win, attr, pair);
201*6348e3f3Sblymn 
20219b437abSuwe 	if (__predict_false(opts != NULL))
20344b007caSuwe 		return ERR;
20444b007caSuwe 
205b5eb0508Sjdc 	/*
206b5eb0508Sjdc 	 * This overwrites any colour setting from the attributes
207b5eb0508Sjdc 	 * and is compatible with ncurses.
208b5eb0508Sjdc 	 */
209e124de36Sblymn 	attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
21044b007caSuwe 
2113981bd4fSuwe 	__wattr_off(win, WA_ATTRIBUTES);
21244b007caSuwe 	__wattr_on(win, attr);
213b5eb0508Sjdc 	return OK;
214b5eb0508Sjdc }
215aaf74682Sblymn 
216586d4ce1Smrg /*
217485cf054Suwe  * wcolor_set --
218485cf054Suwe  *	Set color pair on window
219485cf054Suwe  */
220485cf054Suwe /* ARGSUSED */
221485cf054Suwe int
22219b437abSuwe wcolor_set(WINDOW *win, short pair, void *opts)
223485cf054Suwe {
224485cf054Suwe 	__CTRACE(__CTRACE_COLOR, "wolor_set: win %p, pair %d\n", win, pair);
225*6348e3f3Sblymn 
226*6348e3f3Sblymn 	if (__predict_false(opts != NULL))
227*6348e3f3Sblymn 		return ERR;
228*6348e3f3Sblymn 
229485cf054Suwe 	__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
230485cf054Suwe 	return OK;
231485cf054Suwe }
2327e8b9e03Suwe #endif /* HAVE_WCHAR */
2337e8b9e03Suwe 
234485cf054Suwe 
235485cf054Suwe /*
236485cf054Suwe  * getattrs --
237485cf054Suwe  *	Get window attributes.
238485cf054Suwe  */
239485cf054Suwe chtype
240485cf054Suwe getattrs(WINDOW *win)
241485cf054Suwe {
2424b1b7fd7Sblymn 	if (__predict_false(win == NULL))
2434b1b7fd7Sblymn 		return ERR;
2444b1b7fd7Sblymn 
245485cf054Suwe 	__CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
246485cf054Suwe 	return((chtype) win->wattr);
247485cf054Suwe }
248485cf054Suwe 
249485cf054Suwe /*
2504cb1d6d3Sjdc  * wattron --
251586d4ce1Smrg  *	Test and set attributes.
252586d4ce1Smrg  */
253586d4ce1Smrg int
254aaf74682Sblymn wattron(WINDOW *win, int attr)
255586d4ce1Smrg {
2561f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr);
25744b007caSuwe 	return __wattr_on(win, (attr_t) attr);
258586d4ce1Smrg }
259586d4ce1Smrg 
260586d4ce1Smrg /*
2614cb1d6d3Sjdc  * wattroff --
262586d4ce1Smrg  *	Test and unset attributes.
263586d4ce1Smrg  */
264586d4ce1Smrg int
265aaf74682Sblymn wattroff(WINDOW *win, int attr)
266586d4ce1Smrg {
2671f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr);
26844b007caSuwe 	return __wattr_off(win, (attr_t) attr);
269586d4ce1Smrg }
270586d4ce1Smrg 
271586d4ce1Smrg /*
2724cb1d6d3Sjdc  * wattrset --
273586d4ce1Smrg  *	Set specific attribute modes.
274586d4ce1Smrg  *	Unset others.
275586d4ce1Smrg  */
276586d4ce1Smrg int
277aaf74682Sblymn wattrset(WINDOW *win, int attr)
278586d4ce1Smrg {
2791f221324Sjdc 	__CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr);
28044b007caSuwe 	__wattr_off(win, __ATTRIBUTES);
28144b007caSuwe 	__wattr_on(win, (attr_t) attr);
282b5eb0508Sjdc 	return OK;
283b5eb0508Sjdc }
284b5eb0508Sjdc 
285b5eb0508Sjdc /*
28680b22938Sjdc  * termattrs --
28780b22938Sjdc  *	Get terminal attributes
28880b22938Sjdc  */
28980b22938Sjdc chtype
29080b22938Sjdc termattrs(void)
29180b22938Sjdc {
29260683edbSyamt 	chtype ch = 0;
29360683edbSyamt 
29480b22938Sjdc 	__CTRACE(__CTRACE_ATTR, "termattrs\n");
29598eb8895Sroy 	if (exit_attribute_mode != NULL) {
296bcc3426fSblymn 	__CTRACE(__CTRACE_ATTR, "termattrs: have exit attribute mode\n");
29798eb8895Sroy 		if (enter_blink_mode != NULL)
29880b22938Sjdc 			ch |= __BLINK;
29998eb8895Sroy 		if (enter_bold_mode != NULL)
30080b22938Sjdc 			ch |= __BOLD;
30198eb8895Sroy 		if (enter_dim_mode != NULL)
30280b22938Sjdc 			ch |= __DIM;
30398eb8895Sroy 		if (enter_secure_mode != NULL)
30480b22938Sjdc 			ch |= __BLANK;
30598eb8895Sroy 		if (enter_protected_mode != NULL)
30680b22938Sjdc 			ch |= __PROTECT;
30798eb8895Sroy 		if (enter_reverse_mode != NULL)
30880b22938Sjdc 			ch |= __REVERSE;
30980b22938Sjdc 	}
31098eb8895Sroy 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
31180b22938Sjdc 		ch |= __STANDOUT;
31298eb8895Sroy 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
31380b22938Sjdc 		ch |= __UNDERSCORE;
31498eb8895Sroy 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
31580b22938Sjdc 		ch |= __ALTCHARSET;
31680b22938Sjdc 
31780b22938Sjdc 	return ch;
31880b22938Sjdc }
31980b22938Sjdc 
3207e8b9e03Suwe 
3217e8b9e03Suwe #ifdef HAVE_WCHAR
32280b22938Sjdc /*
32380b22938Sjdc  * term_attrs --
32480b22938Sjdc  *	Get terminal wide attributes
32580b22938Sjdc  */
32680b22938Sjdc attr_t
32780b22938Sjdc term_attrs(void)
32880b22938Sjdc {
32960683edbSyamt 	attr_t attr = 0;
33060683edbSyamt 
33180b22938Sjdc 	__CTRACE(__CTRACE_ATTR, "term_attrs\n");
33298eb8895Sroy 	if (exit_attribute_mode != NULL) {
33398eb8895Sroy 		if (enter_blink_mode != NULL)
334afd69f43Sjdc 			attr |= __BLINK;
33598eb8895Sroy 		if (enter_bold_mode != NULL)
336afd69f43Sjdc 			attr |= __BOLD;
33798eb8895Sroy 		if (enter_dim_mode != NULL)
338afd69f43Sjdc 			attr |= __DIM;
33998eb8895Sroy 		if (enter_secure_mode != NULL)
340afd69f43Sjdc 			attr |= __BLANK;
34198eb8895Sroy 		if (enter_protected_mode != NULL)
342afd69f43Sjdc 			attr |= __PROTECT;
34398eb8895Sroy 		if (enter_reverse_mode != NULL)
344afd69f43Sjdc 			attr |= __REVERSE;
34580b22938Sjdc #ifdef HAVE_WCHAR
34698eb8895Sroy 		if (enter_low_hl_mode != NULL)
34780b22938Sjdc 			attr |= WA_LOW;
34898eb8895Sroy 		if (enter_top_hl_mode != NULL)
34980b22938Sjdc 			attr |= WA_TOP;
35098eb8895Sroy 		if (enter_left_hl_mode != NULL)
35180b22938Sjdc 			attr |= WA_LEFT;
35298eb8895Sroy 		if (enter_right_hl_mode != NULL)
35380b22938Sjdc 			attr |= WA_RIGHT;
35498eb8895Sroy 		if (enter_horizontal_hl_mode != NULL)
35580b22938Sjdc 			attr |= WA_HORIZONTAL;
35698eb8895Sroy 		if (enter_vertical_hl_mode != NULL)
35780b22938Sjdc 			attr |= WA_VERTICAL;
35880b22938Sjdc #endif /* HAVE_WCHAR */
35980b22938Sjdc 	}
36098eb8895Sroy 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
361afd69f43Sjdc 		attr |= __STANDOUT;
36298eb8895Sroy 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
363afd69f43Sjdc 		attr |= __UNDERSCORE;
36498eb8895Sroy 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
365afd69f43Sjdc 		attr |= __ALTCHARSET;
36680b22938Sjdc 
36780b22938Sjdc 	return attr;
36880b22938Sjdc }
3697e8b9e03Suwe #endif /* HAVE_WCHAR */
37080b22938Sjdc 
37144b007caSuwe 
37244b007caSuwe static int
37344b007caSuwe __wattr_on(WINDOW *win, attr_t attr)
37444b007caSuwe {
3754b1b7fd7Sblymn 	const TERMINAL *t;
3764b1b7fd7Sblymn 
3774b1b7fd7Sblymn 	if (__predict_false(win == NULL))
3784b1b7fd7Sblymn 		return ERR;
3794b1b7fd7Sblymn 
3804b1b7fd7Sblymn 	t = win->screen->term;
38144b007caSuwe 
38244b007caSuwe 	__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
3836012d766Sandvar 	/* If can enter modes, set the relevant attribute bits. */
38444b007caSuwe 	if (t_exit_attribute_mode(t) != NULL) {
38544b007caSuwe 		if (attr & __BLINK && t_enter_blink_mode(t) != NULL)
38644b007caSuwe 			win->wattr |= __BLINK;
38744b007caSuwe 		if (attr & __BOLD && t_enter_bold_mode(t) != NULL)
38844b007caSuwe 			win->wattr |= __BOLD;
38944b007caSuwe 		if (attr & __DIM && t_enter_dim_mode(t) != NULL)
39044b007caSuwe 			win->wattr |= __DIM;
39144b007caSuwe 		if (attr & __BLANK && t_enter_secure_mode(t) != NULL)
39244b007caSuwe 			win->wattr |= __BLANK;
39344b007caSuwe 		if (attr & __PROTECT && t_enter_protected_mode(t) != NULL)
39444b007caSuwe 			win->wattr |= __PROTECT;
39544b007caSuwe 		if (attr & __REVERSE && t_enter_reverse_mode(t) != NULL)
39644b007caSuwe 			win->wattr |= __REVERSE;
39744b007caSuwe #ifdef HAVE_WCHAR
39844b007caSuwe 		if (attr & WA_LOW && t_enter_low_hl_mode(t) != NULL)
39944b007caSuwe 			win->wattr |= WA_LOW;
40044b007caSuwe 		if (attr & WA_TOP && t_enter_top_hl_mode(t) != NULL)
40144b007caSuwe 			win->wattr |= WA_TOP;
40244b007caSuwe 		if (attr & WA_LEFT && t_enter_left_hl_mode(t) != NULL)
40344b007caSuwe 			win->wattr |= WA_LEFT;
40444b007caSuwe 		if (attr & WA_RIGHT && t_enter_right_hl_mode(t) != NULL)
40544b007caSuwe 			win->wattr |= WA_RIGHT;
40644b007caSuwe 		if (attr & WA_HORIZONTAL && t_enter_horizontal_hl_mode(t) != NULL)
40744b007caSuwe 			win->wattr |= WA_HORIZONTAL;
40844b007caSuwe 		if (attr & WA_VERTICAL && t_enter_vertical_hl_mode(t) != NULL)
40944b007caSuwe 			win->wattr |= WA_VERTICAL;
41044b007caSuwe #endif /* HAVE_WCHAR */
41144b007caSuwe 	}
41244b007caSuwe 	if (attr & __STANDOUT && t_enter_standout_mode(t) != NULL &&
41344b007caSuwe 	    t_exit_standout_mode(t) != NULL)
41444b007caSuwe 		wstandout(win);
41544b007caSuwe 	if (attr & __UNDERSCORE && t_enter_underline_mode(t) != NULL &&
41644b007caSuwe 	    t_exit_underline_mode(t) != NULL)
41744b007caSuwe 		wunderscore(win);
41844b007caSuwe 	if (attr & __COLOR)
41944b007caSuwe 		__wcolor_set(win, attr);
42044b007caSuwe 	return OK;
42144b007caSuwe }
42244b007caSuwe 
42344b007caSuwe 
42444b007caSuwe static int
42544b007caSuwe __wattr_off(WINDOW *win, attr_t attr)
42644b007caSuwe {
4274b1b7fd7Sblymn 	const TERMINAL *t;
4284b1b7fd7Sblymn 
4294b1b7fd7Sblymn 	if (__predict_false(win == NULL))
4304b1b7fd7Sblymn 		return ERR;
4314b1b7fd7Sblymn 
4324b1b7fd7Sblymn 	t = win->screen->term;
43344b007caSuwe 
43444b007caSuwe 	__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
4356012d766Sandvar 	/* If can do exit modes, unset the relevant attribute bits. */
43644b007caSuwe 	if (t_exit_attribute_mode(t) != NULL) {
43744b007caSuwe 		if (attr & __BLINK)
43844b007caSuwe 			win->wattr &= ~__BLINK;
43944b007caSuwe 		if (attr & __BOLD)
44044b007caSuwe 			win->wattr &= ~__BOLD;
44144b007caSuwe 		if (attr & __DIM)
44244b007caSuwe 			win->wattr &= ~__DIM;
44344b007caSuwe 		if (attr & __BLANK)
44444b007caSuwe 			win->wattr &= ~__BLANK;
44544b007caSuwe 		if (attr & __PROTECT)
44644b007caSuwe 			win->wattr &= ~__PROTECT;
44744b007caSuwe 		if (attr & __REVERSE)
44844b007caSuwe 			win->wattr &= ~__REVERSE;
44944b007caSuwe #ifdef HAVE_WCHAR
45044b007caSuwe 		if (attr & WA_LOW)
45144b007caSuwe 			win->wattr &= ~WA_LOW;
45244b007caSuwe 		if (attr & WA_TOP)
45344b007caSuwe 			win->wattr &= ~WA_TOP;
45444b007caSuwe 		if (attr & WA_LEFT)
45544b007caSuwe 			win->wattr &= ~WA_LEFT;
45644b007caSuwe 		if (attr & WA_RIGHT)
45744b007caSuwe 			win->wattr &= ~WA_RIGHT;
45844b007caSuwe 		if (attr & WA_HORIZONTAL)
45944b007caSuwe 			win->wattr &= ~WA_HORIZONTAL;
46044b007caSuwe 		if (attr & WA_VERTICAL)
46144b007caSuwe 			win->wattr &= ~WA_VERTICAL;
46244b007caSuwe #endif /* HAVE_WCHAR */
46344b007caSuwe 	}
46444b007caSuwe 	if (attr & __STANDOUT)
46544b007caSuwe 		wstandend(win);
46644b007caSuwe 	if (attr & __UNDERSCORE)
46744b007caSuwe 		wunderend(win);
46844b007caSuwe 	if (attr & __COLOR) {
46944b007caSuwe 		if (max_colors != 0)
47044b007caSuwe 			win->wattr &= ~__COLOR;
47144b007caSuwe 	}
47244b007caSuwe 	return OK;
47344b007caSuwe }
47444b007caSuwe 
47544b007caSuwe 
476485cf054Suwe static void
477b5eb0508Sjdc __wcolor_set(WINDOW *win, attr_t attr)
478b5eb0508Sjdc {
4794b1b7fd7Sblymn 	const TERMINAL *t;
4804b1b7fd7Sblymn 
4814b1b7fd7Sblymn 	if (__predict_false(win == NULL))
4824b1b7fd7Sblymn 		return;
4834b1b7fd7Sblymn 
4844b1b7fd7Sblymn 	t = win->screen->term;
485e56dac4eSroy 
486b5eb0508Sjdc 	/* If another color pair is set, turn that off first. */
487b5eb0508Sjdc 	win->wattr &= ~__COLOR;
488b5eb0508Sjdc 	/* If can do color video, set the color pair bits. */
489301bf8ccSblymn 	if (t_max_colors(t) != 0)
490b5eb0508Sjdc 		win->wattr |= attr & __COLOR;
491b5eb0508Sjdc }
492