soc/intel/xeon_sp/util: Enhance lock_pam0123
[coreboot2.git] / payloads / libpayload / curses / PDCurses / pdcurses / attr.c
blob123cb908591237b38959ba091b93a2ee8d0ba37f
1 /* Public Domain Curses */
3 #include <curspriv.h>
5 RCSID("$Id: attr.c,v 1.41 2008/07/13 16:08:17 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: attr
11 Synopsis:
12 int attroff(chtype attrs);
13 int wattroff(WINDOW *win, chtype attrs);
14 int attron(chtype attrs);
15 int wattron(WINDOW *win, chtype attrs);
16 int attrset(chtype attrs);
17 int wattrset(WINDOW *win, chtype attrs);
18 int standend(void);
19 int wstandend(WINDOW *win);
20 int standout(void);
21 int wstandout(WINDOW *win);
23 int color_set(short color_pair, void *opts);
24 int wcolor_set(WINDOW *win, short color_pair, void *opts);
26 int attr_get(attr_t *attrs, short *color_pair, void *opts);
27 int attr_off(attr_t attrs, void *opts);
28 int attr_on(attr_t attrs, void *opts);
29 int attr_set(attr_t attrs, short color_pair, void *opts);
30 int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair,
31 void *opts);
32 int wattr_off(WINDOW *win, attr_t attrs, void *opts);
33 int wattr_on(WINDOW *win, attr_t attrs, void *opts);
34 int wattr_set(WINDOW *win, attr_t attrs, short color_pair,
35 void *opts);
37 int chgat(int n, attr_t attr, short color, const void *opts);
38 int mvchgat(int y, int x, int n, attr_t attr, short color,
39 const void *opts);
40 int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr,
41 short color, const void *opts);
42 int wchgat(WINDOW *win, int n, attr_t attr, short color,
43 const void *opts);
45 chtype getattrs(WINDOW *win);
47 Description:
48 These functions manipulate the current attributes and/or colors
49 of the named window. These attributes can be any combination
50 of A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE.
52 These constants are defined in <curses.h> and can be combined
53 with the bitwise-OR operator (|).
55 The current attributes of a window are applied to all chtypes
56 that are written into the window with waddch(). Attributes are
57 a property of the chtype, and move with the character through
58 any scrolling or insert/delete operations.
60 attrset() sets the current attributes of the given window to
61 attrs. attroff() turns off the named attributes without
62 affecting any other attributes; attron() turns them on.
63 color_set() sets the window color to the value of color_pair.
65 standout() is the same as attron(A_STANDOUT). standend() is the
66 same as attrset(A_NORMAL); that is, it turns off all attributes.
68 Return Value:
69 All functions return OK on success and ERR on error.
71 Portability X/Open BSD SYS V
72 attroff Y Y Y
73 wattroff Y Y Y
74 attron Y Y Y
75 wattron Y Y Y
76 attrset Y Y Y
77 wattrset Y Y Y
78 standend Y Y Y
79 wstandend Y Y Y
80 standout Y Y Y
81 wstandout Y Y Y
82 color_set Y
83 wcolor_set Y
84 attr_get Y
85 wattr_get Y
86 attr_on Y
87 wattr_on Y
88 attr_off Y
89 wattr_off Y
90 attr_set Y
91 wattr_set Y
92 chgat Y
93 wchgat Y
94 mvchgat Y
95 mvwchgat Y
96 getattrs -
98 **man-end****************************************************************/
100 int wattroff(WINDOW *win, chtype attrs)
102 PDC_LOG(("wattroff() - called\n"));
104 if (!win)
105 return ERR;
107 win->_attrs &= (~attrs & A_ATTRIBUTES);
109 return OK;
112 int attroff(chtype attrs)
114 PDC_LOG(("attroff() - called\n"));
116 return wattroff(stdscr, attrs);
119 int wattron(WINDOW *win, chtype attrs)
121 chtype newcolr, oldcolr, newattr, oldattr;
123 PDC_LOG(("wattron() - called\n"));
125 if (!win)
126 return ERR;
128 if ((win->_attrs & A_COLOR) && (attrs & A_COLOR))
130 oldcolr = win->_attrs & A_COLOR;
131 oldattr = win->_attrs ^ oldcolr;
132 newcolr = attrs & A_COLOR;
133 newattr = (attrs & A_ATTRIBUTES) ^ newcolr;
134 newattr |= oldattr;
135 win->_attrs = newattr | newcolr;
137 else
138 win->_attrs |= (attrs & A_ATTRIBUTES);
140 return OK;
143 int attron(chtype attrs)
145 PDC_LOG(("attron() - called\n"));
147 return wattron(stdscr, attrs);
150 int wattrset(WINDOW *win, chtype attrs)
152 PDC_LOG(("wattrset() - called\n"));
154 if (!win)
155 return ERR;
157 win->_attrs = attrs & A_ATTRIBUTES;
159 return OK;
162 int attrset(chtype attrs)
164 PDC_LOG(("attrset() - called\n"));
166 return wattrset(stdscr, attrs);
169 int standend(void)
171 PDC_LOG(("standend() - called\n"));
173 return wattrset(stdscr, A_NORMAL);
176 int standout(void)
178 PDC_LOG(("standout() - called\n"));
180 return wattrset(stdscr, A_STANDOUT);
183 int wstandend(WINDOW *win)
185 PDC_LOG(("wstandend() - called\n"));
187 return wattrset(win, A_NORMAL);
190 int wstandout(WINDOW *win)
192 PDC_LOG(("wstandout() - called\n"));
194 return wattrset(win, A_STANDOUT);
197 chtype getattrs(WINDOW *win)
199 return win ? win->_attrs : 0;
202 int wcolor_set(WINDOW *win, short color_pair, void *opts)
204 PDC_LOG(("wcolor_set() - called\n"));
206 if (!win)
207 return ERR;
209 win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair);
211 return OK;
214 int color_set(short color_pair, void *opts)
216 PDC_LOG(("color_set() - called\n"));
218 return wcolor_set(stdscr, color_pair, opts);
221 int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts)
223 PDC_LOG(("wattr_get() - called\n"));
225 if (!win)
226 return ERR;
228 if (attrs)
229 *attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR);
231 if (color_pair)
232 *color_pair = PAIR_NUMBER(win->_attrs);
234 return OK;
237 int attr_get(attr_t *attrs, short *color_pair, void *opts)
239 PDC_LOG(("attr_get() - called\n"));
241 return wattr_get(stdscr, attrs, color_pair, opts);
244 int wattr_off(WINDOW *win, attr_t attrs, void *opts)
246 PDC_LOG(("wattr_off() - called\n"));
248 return wattroff(win, attrs);
251 int attr_off(attr_t attrs, void *opts)
253 PDC_LOG(("attr_off() - called\n"));
255 return wattroff(stdscr, attrs);
258 int wattr_on(WINDOW *win, attr_t attrs, void *opts)
260 PDC_LOG(("wattr_off() - called\n"));
262 return wattron(win, attrs);
265 int attr_on(attr_t attrs, void *opts)
267 PDC_LOG(("attr_on() - called\n"));
269 return wattron(stdscr, attrs);
272 int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts)
274 PDC_LOG(("wattr_set() - called\n"));
276 if (!win)
277 return ERR;
279 win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair);
281 return OK;
284 int attr_set(attr_t attrs, short color_pair, void *opts)
286 PDC_LOG(("attr_get() - called\n"));
288 return wattr_set(stdscr, attrs, color_pair, opts);
291 int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
293 chtype *dest, newattr;
294 int startpos, endpos;
296 PDC_LOG(("wchgat() - called\n"));
298 if (!win)
299 return ERR;
301 newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color);
303 startpos = win->_curx;
304 endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1;
305 dest = win->_y[win->_cury];
307 for (n = startpos; n <= endpos; n++)
308 dest[n] = (dest[n] & A_CHARTEXT) | newattr;
310 n = win->_cury;
312 if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
313 win->_firstch[n] = startpos;
315 if (endpos > win->_lastch[n])
316 win->_lastch[n] = endpos;
318 PDC_sync(win);
320 return OK;
323 int chgat(int n, attr_t attr, short color, const void *opts)
325 PDC_LOG(("chgat() - called\n"));
327 return wchgat(stdscr, n, attr, color, opts);
330 int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts)
332 PDC_LOG(("mvchgat() - called\n"));
334 if (move(y, x) == ERR)
335 return ERR;
337 return wchgat(stdscr, n, attr, color, opts);
340 int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color,
341 const void *opts)
343 PDC_LOG(("mvwchgat() - called\n"));
345 if (wmove(win, y, x) == ERR)
346 return ERR;
348 return wchgat(win, n, attr, color, opts);