1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
28*0Sstevel@tonic-gate /* All Rights Reserved */
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
32*0Sstevel@tonic-gate * The Regents of the University of California
33*0Sstevel@tonic-gate * All Rights Reserved
34*0Sstevel@tonic-gate *
35*0Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
36*0Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
37*0Sstevel@tonic-gate * contributors.
38*0Sstevel@tonic-gate */
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate /*LINTLIBRARY*/
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate #include <sys/types.h>
45*0Sstevel@tonic-gate #include <stdlib.h>
46*0Sstevel@tonic-gate #include "curses_inc.h"
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate #ifdef PC6300PLUS
49*0Sstevel@tonic-gate #include <fcntl.h>
50*0Sstevel@tonic-gate #include <sys/console.h>
51*0Sstevel@tonic-gate #endif
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate #define NUM_OF_SPECIFIC_TURN_OFFS 3
54*0Sstevel@tonic-gate extern chtype bit_attributes[];
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate int Oldcolors[] = { COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
57*0Sstevel@tonic-gate COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE };
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate void
vidupdate(chtype newmode,chtype oldmode,int (* outc)(char))60*0Sstevel@tonic-gate vidupdate(chtype newmode, chtype oldmode, int (*outc)(char))
61*0Sstevel@tonic-gate {
62*0Sstevel@tonic-gate bool color_terminal = (cur_term->_pairs_tbl) ? TRUE : FALSE;
63*0Sstevel@tonic-gate chtype oldvideo = (oldmode & A_ATTRIBUTES) & ~A_COLOR;
64*0Sstevel@tonic-gate chtype newvideo = (newmode & A_ATTRIBUTES) & ~A_COLOR;
65*0Sstevel@tonic-gate int _change_video(chtype, chtype, int (*)(char));
66*0Sstevel@tonic-gate void _change_color(short, int (*)(char));
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate /* if colors are used, extract the color related information from */
69*0Sstevel@tonic-gate /* the old and new modes and then erase color-pairs fields in */
70*0Sstevel@tonic-gate /* both arguments. */
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate if (color_terminal) {
73*0Sstevel@tonic-gate /* LINTED */
74*0Sstevel@tonic-gate short oldcolor = (short) PAIR_NUMBER(oldmode & A_COLOR);
75*0Sstevel@tonic-gate /* LINTED */
76*0Sstevel@tonic-gate short newcolor = (short) PAIR_NUMBER(newmode & A_COLOR);
77*0Sstevel@tonic-gate chtype turn_off = A_COLOR;
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate /* erase information about video attributes that could not */
80*0Sstevel@tonic-gate /* have been used with colors */
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate if (oldcolor == 0)
83*0Sstevel@tonic-gate oldvideo &= ~turn_off;
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate if (no_color_video != -1)
86*0Sstevel@tonic-gate turn_off |= (((chtype) no_color_video) << 16);
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate if (oldcolor != 0)
89*0Sstevel@tonic-gate oldvideo &= ~turn_off;
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate /* if the new mode contains color information, then first */
93*0Sstevel@tonic-gate /* deal with video attributes, and then with colors. This */
94*0Sstevel@tonic-gate /* way color information will overwrite video information. */
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate if (newcolor != 0) {
97*0Sstevel@tonic-gate /* erase information about video attributes that */
98*0Sstevel@tonic-gate /* should not be used with colors */
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate newvideo &= ~turn_off;
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate /* if the new and the old video modes became */
103*0Sstevel@tonic-gate /* the same don't bother with them */
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate if (newvideo != oldvideo) {
106*0Sstevel@tonic-gate if ((_change_video(newvideo, oldvideo,
107*0Sstevel@tonic-gate outc)) == -1) {
108*0Sstevel@tonic-gate _Color_pair *cur_pair =
109*0Sstevel@tonic-gate &cur_term->_cur_pair;
110*0Sstevel@tonic-gate oldcolor = -1;
111*0Sstevel@tonic-gate cur_pair->background =
112*0Sstevel@tonic-gate cur_pair->foreground = -1;
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate }
115*0Sstevel@tonic-gate if (newcolor != oldcolor)
116*0Sstevel@tonic-gate _change_color(newcolor, outc);
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gate /* new mode doesn't contain any color information. Deal */
120*0Sstevel@tonic-gate /* with colors first (possibly turning of the colors that */
121*0Sstevel@tonic-gate /* were contained in the oldmode, and then deal with video. */
122*0Sstevel@tonic-gate /* This way video attributes will overwrite colors. */
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate else {
125*0Sstevel@tonic-gate if (newcolor != oldcolor)
126*0Sstevel@tonic-gate _change_color(newcolor, outc);
127*0Sstevel@tonic-gate if (newvideo != oldvideo)
128*0Sstevel@tonic-gate (void) _change_video(newvideo, oldvideo, outc);
129*0Sstevel@tonic-gate }
130*0Sstevel@tonic-gate } else
131*0Sstevel@tonic-gate (void) _change_video(newvideo, oldvideo, outc);
132*0Sstevel@tonic-gate }
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate int
_change_video(chtype newmode,chtype oldmode,int (* outc)(char))136*0Sstevel@tonic-gate _change_video(chtype newmode, chtype oldmode, int (*outc)(char))
137*0Sstevel@tonic-gate {
138*0Sstevel@tonic-gate int rc = 0;
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate /* If you have set_attributes let the terminfo writer */
141*0Sstevel@tonic-gate /* worry about it. */
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate if (!set_attributes) {
144*0Sstevel@tonic-gate /*
145*0Sstevel@tonic-gate * The trick is that we want to pre-process the new and oldmode
146*0Sstevel@tonic-gate * so that we now know what they will really translate to on
147*0Sstevel@tonic-gate * the physical screen.
148*0Sstevel@tonic-gate * In the case where some attributes are being faked
149*0Sstevel@tonic-gate * we get rid of the attributes being asked for and just have
150*0Sstevel@tonic-gate * STANDOUT mode set. Therefore, if STANDOUT and UNDERLINE were
151*0Sstevel@tonic-gate * on the screen but UNDERLINE was being faked to STANDOUT; and
152*0Sstevel@tonic-gate * the new mode is just UNDERLINE, we will get rid of any faked
153*0Sstevel@tonic-gate * modes and be left with and oldmode of STANDOUT and a new mode
154*0Sstevel@tonic-gate * of STANDOUT, in which case the check for newmode and oldmode
155*0Sstevel@tonic-gate * being equal will be true.
156*0Sstevel@tonic-gate *
157*0Sstevel@tonic-gate *
158*0Sstevel@tonic-gate * This test is similar to the concept explained above.
159*0Sstevel@tonic-gate * counter is the maximum attributes allowed on a terminal.
160*0Sstevel@tonic-gate * For instance, on an hp/tvi950 without set_attributes
161*0Sstevel@tonic-gate * the last video sequence sent will be the one the terminal
162*0Sstevel@tonic-gate * will be in (on that spot). Therefore, in setupterm.c
163*0Sstevel@tonic-gate * if ceol_standout_glitch or magic_cookie_glitch is set
164*0Sstevel@tonic-gate * max_attributes is set to 1. This is because on those terminals
165*0Sstevel@tonic-gate * only one attribute can be on at once. So, we pre-process the
166*0Sstevel@tonic-gate * oldmode and the newmode and only leave the bits that are
167*0Sstevel@tonic-gate * significant. In other words, if on an hp you ask for STANDOUT
168*0Sstevel@tonic-gate * and UNDERLINE it will become only STANDOUT since that is the
169*0Sstevel@tonic-gate * first bit that is looked at. If then the user goes from
170*0Sstevel@tonic-gate * STANDOUT and UNDERLINE to STANDOUT and REVERSE the oldmode will
171*0Sstevel@tonic-gate * become STANDOUT and the newmode will become STANDOUT.
172*0Sstevel@tonic-gate *
173*0Sstevel@tonic-gate * This also helps the code below in that on a hp or tvi950 only
174*0Sstevel@tonic-gate * one bit will ever be set so that no code has to be added to
175*0Sstevel@tonic-gate * cut out early in case two attributes were asked for.
176*0Sstevel@tonic-gate */
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate chtype check_faked, modes[2];
179*0Sstevel@tonic-gate int counter = max_attributes, i, j, tempmode;
180*0Sstevel@tonic-gate int k = (cur_term->sgr_mode == oldmode) ? 1 : 2;
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate modes[0] = newmode;
183*0Sstevel@tonic-gate modes[1] = oldmode;
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate while (k-- > 0) {
186*0Sstevel@tonic-gate if ((check_faked = (modes[k] &
187*0Sstevel@tonic-gate cur_term->sgr_faked)) != A_NORMAL) {
188*0Sstevel@tonic-gate modes[k] &= ~check_faked;
189*0Sstevel@tonic-gate modes[k] |= A_STANDOUT;
190*0Sstevel@tonic-gate }
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate if ((j = counter) >= 0) {
193*0Sstevel@tonic-gate tempmode = A_NORMAL;
194*0Sstevel@tonic-gate if (j > 0) {
195*0Sstevel@tonic-gate for (i = 0; i < NUM_ATTRIBUTES; i++) {
196*0Sstevel@tonic-gate if (modes[k] &
197*0Sstevel@tonic-gate bit_attributes[i]) {
198*0Sstevel@tonic-gate tempmode |=
199*0Sstevel@tonic-gate bit_attributes[i];
200*0Sstevel@tonic-gate if (--j == 0)
201*0Sstevel@tonic-gate break;
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate }
204*0Sstevel@tonic-gate }
205*0Sstevel@tonic-gate modes[k] = tempmode;
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate newmode = modes[0];
209*0Sstevel@tonic-gate oldmode = modes[1];
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate if (newmode == oldmode)
213*0Sstevel@tonic-gate return (rc);
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate #ifdef DEBUG
216*0Sstevel@tonic-gate if (outf)
217*0Sstevel@tonic-gate fprintf(outf, "vidupdate oldmode=%o, newmode=%o\n",
218*0Sstevel@tonic-gate oldmode, newmode);
219*0Sstevel@tonic-gate #endif
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate if (set_attributes) {
222*0Sstevel@tonic-gate (void) tputs(tparm(set_attributes,
223*0Sstevel@tonic-gate newmode & A_STANDOUT,
224*0Sstevel@tonic-gate newmode & A_UNDERLINE,
225*0Sstevel@tonic-gate newmode & A_REVERSE,
226*0Sstevel@tonic-gate newmode & A_BLINK,
227*0Sstevel@tonic-gate newmode & A_DIM,
228*0Sstevel@tonic-gate newmode & A_BOLD,
229*0Sstevel@tonic-gate newmode & A_INVIS,
230*0Sstevel@tonic-gate newmode & A_PROTECT,
231*0Sstevel@tonic-gate newmode & A_ALTCHARSET),
232*0Sstevel@tonic-gate 1, outc);
233*0Sstevel@tonic-gate rc = -1;
234*0Sstevel@tonic-gate } else {
235*0Sstevel@tonic-gate chtype turn_on, turn_off;
236*0Sstevel@tonic-gate int i;
237*0Sstevel@tonic-gate
238*0Sstevel@tonic-gate /*
239*0Sstevel@tonic-gate * If we are going to turn something on anyway and we are
240*0Sstevel@tonic-gate * on a glitchy terminal, don't bother turning it off
241*0Sstevel@tonic-gate * since by turning something on you turn everything else off.
242*0Sstevel@tonic-gate */
243*0Sstevel@tonic-gate
244*0Sstevel@tonic-gate if ((ceol_standout_glitch || magic_cookie_glitch >= 0) &&
245*0Sstevel@tonic-gate ((turn_on = ((oldmode ^ newmode) & newmode)) !=
246*0Sstevel@tonic-gate A_NORMAL)) {
247*0Sstevel@tonic-gate goto turn_on_code;
248*0Sstevel@tonic-gate }
249*0Sstevel@tonic-gate
250*0Sstevel@tonic-gate if ((turn_off = (oldmode & newmode) ^ oldmode) != A_NORMAL) {
251*0Sstevel@tonic-gate /*
252*0Sstevel@tonic-gate * Check for things to turn off.
253*0Sstevel@tonic-gate * First see if we are going to turn off something
254*0Sstevel@tonic-gate * that doesn't have a specific turn off capability.
255*0Sstevel@tonic-gate *
256*0Sstevel@tonic-gate * Then check to see if, even though there may be a specific
257*0Sstevel@tonic-gate * turn off sequence, this terminal doesn't have one or
258*0Sstevel@tonic-gate * the turn off sequence also turns off something else.
259*0Sstevel@tonic-gate */
260*0Sstevel@tonic-gate if ((turn_off & ~(A_ALTCHARSET | A_STANDOUT | A_UNDERLINE)) ||
261*0Sstevel@tonic-gate (turn_off != (turn_off & cur_term->check_turn_off))) {
262*0Sstevel@tonic-gate (void) tputs(tparm_p0(exit_attribute_mode), 1, outc);
263*0Sstevel@tonic-gate rc = -1;
264*0Sstevel@tonic-gate oldmode = A_NORMAL;
265*0Sstevel@tonic-gate } else {
266*0Sstevel@tonic-gate for (i = 0; i < NUM_OF_SPECIFIC_TURN_OFFS; i++) {
267*0Sstevel@tonic-gate if (turn_off & bit_attributes[i]) {
268*0Sstevel@tonic-gate (void) tputs(tparm_p0
269*0Sstevel@tonic-gate (cur_term->turn_off_seq[i]),
270*0Sstevel@tonic-gate 1, outc);
271*0Sstevel@tonic-gate oldmode &= ~bit_attributes[i];
272*0Sstevel@tonic-gate rc = -1;
273*0Sstevel@tonic-gate }
274*0Sstevel@tonic-gate }
275*0Sstevel@tonic-gate }
276*0Sstevel@tonic-gate }
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gate if ((turn_on = ((oldmode ^ newmode) & newmode)) != A_NORMAL) {
279*0Sstevel@tonic-gate turn_on_code:
280*0Sstevel@tonic-gate
281*0Sstevel@tonic-gate /* Check for modes to turn on. */
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate for (i = 0; i < NUM_ATTRIBUTES; i++)
284*0Sstevel@tonic-gate if (turn_on & bit_attributes[i]) {
285*0Sstevel@tonic-gate (void) tputs(tparm_p0(cur_term->turn_on_seq[i]),
286*0Sstevel@tonic-gate 1, outc);
287*0Sstevel@tonic-gate rc = -1;
288*0Sstevel@tonic-gate /*
289*0Sstevel@tonic-gate * Keep turning off the bit(s) that we just
290*0Sstevel@tonic-gate * sent to the screen. As soon as turn_on
291*0Sstevel@tonic-gate * reaches A_NORMAL we don't have to turn
292*0Sstevel@tonic-gate * anything else on and we can
293*0Sstevel@tonic-gate * break out of the loop.
294*0Sstevel@tonic-gate */
295*0Sstevel@tonic-gate if ((turn_on &= ~bit_attributes[i]) ==
296*0Sstevel@tonic-gate A_NORMAL)
297*0Sstevel@tonic-gate break;
298*0Sstevel@tonic-gate }
299*0Sstevel@tonic-gate }
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate if (magic_cookie_glitch > 0)
302*0Sstevel@tonic-gate (void) tputs(cursor_left, 1, outc);
303*0Sstevel@tonic-gate }
304*0Sstevel@tonic-gate cur_term->sgr_mode = newmode;
305*0Sstevel@tonic-gate return (rc);
306*0Sstevel@tonic-gate }
307*0Sstevel@tonic-gate
308*0Sstevel@tonic-gate
309*0Sstevel@tonic-gate void
_change_color(short newcolor,int (* outc)(char))310*0Sstevel@tonic-gate _change_color(short newcolor, int (*outc)(char))
311*0Sstevel@tonic-gate {
312*0Sstevel@tonic-gate #ifndef PC6300PLUS
313*0Sstevel@tonic-gate {
314*0Sstevel@tonic-gate _Color_pair *ptp = cur_term->_pairs_tbl;
315*0Sstevel@tonic-gate /* pairs table pointer */
316*0Sstevel@tonic-gate _Color_pair *cur_pair = &cur_term->_cur_pair;
317*0Sstevel@tonic-gate
318*0Sstevel@tonic-gate /* MORE: we may have to change some stuff, depending on whether */
319*0Sstevel@tonic-gate /* HP terminals will be changing the background, or not */
320*0Sstevel@tonic-gate
321*0Sstevel@tonic-gate if (newcolor == 0) {
322*0Sstevel@tonic-gate if (orig_pair)
323*0Sstevel@tonic-gate (void) tputs(tparm_p0(orig_pair), 1, outc);
324*0Sstevel@tonic-gate if (set_a_background || set_a_foreground ||
325*0Sstevel@tonic-gate set_background || set_foreground) {
326*0Sstevel@tonic-gate cur_pair->background = -1;
327*0Sstevel@tonic-gate cur_pair->foreground = -1;
328*0Sstevel@tonic-gate }
329*0Sstevel@tonic-gate return;
330*0Sstevel@tonic-gate }
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate /* if we are on HP type terminal, just send an escape sequence */
333*0Sstevel@tonic-gate /* to use desired color pair (we could have done some optimization: */
334*0Sstevel@tonic-gate /* check if both the foreground and background of newcolor match */
335*0Sstevel@tonic-gate /* the ones of cur_term->_cur_pair. but that will happen only when */
336*0Sstevel@tonic-gate /* two color pairs are defined exacly the same, and probably not */
337*0Sstevel@tonic-gate /* worth the effort). */
338*0Sstevel@tonic-gate
339*0Sstevel@tonic-gate if (set_color_pair)
340*0Sstevel@tonic-gate (void) tputs(tparm_p1(set_color_pair, newcolor), 1, outc);
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate /* on Tek model we can do some optimization. */
343*0Sstevel@tonic-gate
344*0Sstevel@tonic-gate else {
345*0Sstevel@tonic-gate if (ptp[newcolor].background != cur_pair->background) {
346*0Sstevel@tonic-gate if (set_a_background)
347*0Sstevel@tonic-gate (void) tputs(tparm_p1(set_a_background,
348*0Sstevel@tonic-gate ptp[newcolor].background), 1, outc);
349*0Sstevel@tonic-gate else if (set_background)
350*0Sstevel@tonic-gate (void) tputs(tparm_p1(set_background,
351*0Sstevel@tonic-gate Oldcolors[ptp[newcolor].background]),
352*0Sstevel@tonic-gate 1, outc);
353*0Sstevel@tonic-gate cur_pair->background = ptp[newcolor].background;
354*0Sstevel@tonic-gate }
355*0Sstevel@tonic-gate if (ptp[newcolor].foreground != cur_pair->foreground) {
356*0Sstevel@tonic-gate if (set_a_foreground)
357*0Sstevel@tonic-gate (void) tputs(tparm_p1(set_a_foreground,
358*0Sstevel@tonic-gate ptp[newcolor].foreground), 1, outc);
359*0Sstevel@tonic-gate else if (set_foreground)
360*0Sstevel@tonic-gate (void) tputs(tparm_p1(set_foreground,
361*0Sstevel@tonic-gate Oldcolors[ptp[newcolor].foreground]),
362*0Sstevel@tonic-gate 1, outc);
363*0Sstevel@tonic-gate cur_pair->foreground = ptp[newcolor].foreground;
364*0Sstevel@tonic-gate }
365*0Sstevel@tonic-gate }
366*0Sstevel@tonic-gate }
367*0Sstevel@tonic-gate #else
368*0Sstevel@tonic-gate {
369*0Sstevel@tonic-gate /* the following code is for PC6300 PLUS: it uses BOLD terminfo */
370*0Sstevel@tonic-gate /* entry for turning on colors, and SGR0 for turning them off. */
371*0Sstevel@tonic-gate /* Every time a new color-pair is used, we are forced to do an */
372*0Sstevel@tonic-gate /* ioctl read, and the send 'enter_bold_mode' escape sequence. */
373*0Sstevel@tonic-gate /* This could be improved by using */
374*0Sstevel@tonic-gate /* DIM, UNDERLINE, and REVERSE in addition to BOLD */
375*0Sstevel@tonic-gate
376*0Sstevel@tonic-gate struct console con;
377*0Sstevel@tonic-gate _Color_pair *ptp = cur_term->_pairs_tbl;
378*0Sstevel@tonic-gate /* pairs table pointer */
379*0Sstevel@tonic-gate back = ptp[newcolor].background;
380*0Sstevel@tonic-gate fore = ptp[newcolor].foreground;
381*0Sstevel@tonic-gate
382*0Sstevel@tonic-gate (void) fflush(SP->term_file);
383*0Sstevel@tonic-gate ioctl(cur_term->Filedes, CONIOGETDATA, &con);
384*0Sstevel@tonic-gate #define BOLD 4
385*0Sstevel@tonic-gate con.l[con.page].colors[BOLD] =
386*0Sstevel@tonic-gate ((back + back + (fore > 5)) * 8 + fore) & 0177;
387*0Sstevel@tonic-gate ioctl(cur_term->Filedes, CONIOSETDATA, &con);
388*0Sstevel@tonic-gate (void) tputs(enter_bold_mode, 1, outc);
389*0Sstevel@tonic-gate }
390*0Sstevel@tonic-gate #endif
391*0Sstevel@tonic-gate }
392