1 /****************************************************************************
2 * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-2004 *
33 ****************************************************************************/
35 /*-----------------------------------------------------------------
39 * The routine doupdate() and its dependents.
40 * All physical output is concentrated here (except _nc_outch()
43 *-----------------------------------------------------------------*/
45 #include <curses.priv.h>
53 #if defined(TRACE) && HAVE_SYS_TIMES_H && HAVE_TIMES
54 #define USE_TRACE_TIMES 1
56 #define USE_TRACE_TIMES 0
59 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
64 #include <sys/times.h>
70 #include <sys/select.h>
77 MODULE_ID("$Id: tty_update.c,v 1.205 2004/02/07 18:02:42 tom Exp $")
80 * This define controls the line-breakout optimization. Every once in a
81 * while during screen refresh, we want to check for input and abort the
82 * update if there's some waiting. CHECK_INTERVAL controls the number of
83 * changed lines to be emitted between input checks.
85 * Note: Input-check-and-abort is no longer done if the screen is being
86 * updated from scratch. This is a feature, not a bug.
88 #define CHECK_INTERVAL 5
90 #define FILL_BCE() (SP->_coloron && !SP->_default_color && !back_color_erase)
93 * Enable checking to see if doupdate and friends are tracking the true
94 * cursor position correctly. NOTE: this is a debugging hack which will
95 * work ONLY on ANSI-compatible terminals!
97 /* #define POSITION_DEBUG */
99 static inline NCURSES_CH_T ClrBlank(WINDOW *win);
100 static int ClrBottom(int total);
101 static void ClearScreen(NCURSES_CH_T blank);
102 static void ClrUpdate(void);
103 static void DelChar(int count);
104 static void InsStr(NCURSES_CH_T * line, int count);
105 static void TransformLine(int const lineno);
107 #ifdef POSITION_DEBUG
108 /****************************************************************************
110 * Debugging code. Only works on ANSI-standard terminals.
112 ****************************************************************************/
115 position_check(int expected_y, int expected_x, char *legend)
116 /* check to see if the real cursor position matches the virtual */
122 if (!_nc_tracing || (expected_y < 0 && expected_x < 0))
126 memset(buf, '\0', sizeof(buf));
127 putp("\033[6n"); /* only works on ANSI-compatibles */
131 int ask = sizeof(buf) - 1 - (s - buf);
132 int got = read(0, s, ask);
136 } while (strchr(buf, 'R') == 0);
137 _tracef("probe returned %s", _nc_visbuf(buf));
139 /* try to interpret as a position report */
140 if (sscanf(buf, "\033[%d;%dR", &y, &x) != 2) {
141 _tracef("position probe failed in %s", legend);
147 if (y - 1 != expected_y || x - 1 != expected_x) {
149 tputs(tparm("\033[%d;%dH", expected_y + 1, expected_x + 1), 1, _nc_outch);
150 _tracef("position seen (%d, %d) doesn't match expected one (%d, %d) in %s",
151 y - 1, x - 1, expected_y, expected_x, legend);
153 _tracef("position matches OK in %s", legend);
158 #define position_check(expected_y, expected_x, legend) /* nothing */
159 #endif /* POSITION_DEBUG */
161 /****************************************************************************
163 * Optimized update code
165 ****************************************************************************/
168 GoTo(int const row, int const col)
170 TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)",
171 row, col, SP->_cursrow, SP->_curscol));
173 position_check(SP->_cursrow, SP->_curscol, "GoTo");
175 mvcur(SP->_cursrow, SP->_curscol, row, col);
176 position_check(SP->_cursrow, SP->_curscol, "GoTo2");
180 PutAttrChar(CARG_CH_T ch)
186 NCURSES_ATTR_T attr = AttrOfD(ch);
188 TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)",
190 SP->_cursrow, SP->_curscol));
191 #if USE_WIDEC_SUPPORT
193 * If this is not a valid character, there is nothing more to do.
195 if (isnac(CHDEREF(ch)))
198 * Determine the number of character cells which the 'ch' value will use
199 * on the screen. It should be at least one.
201 if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) {
202 static NCURSES_CH_T blank = NewChar(BLANK_TEXT);
204 if (isprint(CharOf(CHDEREF(ch)))
205 || (SP->_posix_locale && CharOf(CHDEREF(ch)) >= 160)) {
209 TR(TRACE_CHARPUT, ("forced to blank"));
215 if ((attr & A_ALTCHARSET)
217 && CharOfD(ch) < ACS_LEN) {
218 my_ch = CHDEREF(ch); /* work around const param */
219 #if USE_WIDEC_SUPPORT
221 * This is crude & ugly, but works most of the time. It checks if the
222 * acs_chars string specified that we have a mapping for this
223 * character, and uses the wide-character mapping when we expect the
224 * normal one to be broken (by mis-design ;-).
226 if (SP->_screen_acs_fix
227 && SP->_acs_map[CharOf(my_ch)] & A_ALTCHARSET) {
228 attr &= ~(A_ALTCHARSET);
229 my_ch = _nc_wacs[CharOf(my_ch)];
232 if (attr & A_ALTCHARSET) {
233 chtype temp = UChar(SP->_acs_map[CharOfD(ch)]);
235 SetChar(my_ch, temp, attr);
236 RemAttr(my_ch, A_ALTCHARSET);
240 if (tilde_glitch && (CharOfD(ch) == L('~'))) {
241 SetChar(tilde, L('`'), attr);
246 #if !USE_WIDEC_SUPPORT
247 /* FIXME - we do this special case for signal handling, should see how to
248 * make it work for wide characters.
250 if (SP->_outch != 0) {
251 SP->_outch(UChar(ch));
255 PUTC(CHDEREF(ch), SP->_ofp); /* macro's fastest... */
258 SP->_curscol += chlen;
260 TPUTS_TRACE("char_padding");
267 /* check for pending input */
269 bool have_pending = FALSE;
272 * Only carry out this check when the flag is zero, otherwise we'll
273 * have the refreshing slow down drastically (or stop) if there's an
274 * unread character available.
276 if (SP->_fifohold != 0)
279 if (SP->_checkfd >= 0) {
281 struct pollfd fds[1];
282 fds[0].fd = SP->_checkfd;
283 fds[0].events = POLLIN;
284 if (poll(fds, 1, 0) > 0) {
287 #elif defined(__BEOS__)
289 * BeOS's select() is declared in socket.h, so the configure script does
290 * not see it. That's just as well, since that function works only for
291 * sockets. This (using snooze and ioctl) was distilled from Be's patch
292 * for ncurses which uses a separate thread to simulate select().
294 * FIXME: the return values from the ioctl aren't very clear if we get
298 int howmany = ioctl(0, 'ichr', &n);
299 if (howmany >= 0 && n > 0) {
304 struct timeval ktimeout;
307 ktimeout.tv_usec = 0;
310 FD_SET(SP->_checkfd, &fdset);
311 if (select(SP->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) {
323 /* put char at lower right corner */
325 PutCharLR(const ARG_CH_T ch)
327 if (!auto_right_margin) {
328 /* we can put the char directly */
330 } else if (enter_am_mode && exit_am_mode) {
331 /* we can suppress automargin */
332 TPUTS_TRACE("exit_am_mode");
337 position_check(SP->_cursrow, SP->_curscol, "exit_am_mode");
339 TPUTS_TRACE("enter_am_mode");
341 } else if ((enter_insert_mode && exit_insert_mode)
342 || insert_character || parm_ich) {
343 GoTo(screen_lines - 1, screen_columns - 2);
345 GoTo(screen_lines - 1, screen_columns - 2);
346 InsStr(newscr->_line[screen_lines - 1].text + screen_columns - 2, 1);
353 if (eat_newline_glitch) {
355 * xenl can manifest two different ways. The vt100
356 * way is that, when you'd expect the cursor to wrap,
357 * it stays hung at the right margin (on top of the
358 * character just emitted) and doesn't wrap until the
359 * *next* graphic char is emitted. The c100 way is
360 * to ignore LF received just after an am wrap.
362 * An aggressive way to handle this would be to
363 * emit CR/LF after the char and then assume the wrap
364 * is done, you're on the first position of the next
365 * line, and the terminal out of its weird state.
366 * Here it's safe to just tell the code that the
367 * cursor is in hyperspace and let the next mvcur()
368 * call straighten things out.
372 } else if (auto_right_margin) {
378 position_check(SP->_cursrow, SP->_curscol, "wrap_cursor");
382 PutChar(const ARG_CH_T ch)
383 /* insert character, handling automargin stuff */
385 if (SP->_cursrow == screen_lines - 1 && SP->_curscol == screen_columns - 1)
390 if (SP->_curscol >= screen_columns)
393 position_check(SP->_cursrow, SP->_curscol, "PutChar");
397 * Check whether the given character can be output by clearing commands. This
398 * includes test for being a space and not including any 'bad' attributes, such
399 * as A_REVERSE. All attribute flags which don't affect appearance of a space
400 * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
403 can_clear_with(ARG_CH_T ch)
405 if (!back_color_erase && SP->_coloron) {
406 #if NCURSES_EXT_FUNCS
407 if (!SP->_default_color)
409 if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK)
411 if (AttrOfD(ch) & A_COLOR) {
413 pair_content(PAIR_NUMBER(AttrOfD(ch)), &fg, &bg);
414 if (fg != C_MASK || bg != C_MASK)
418 if (AttrOfD(ch) & A_COLOR)
422 return (ISBLANK(CHDEREF(ch)) &&
423 (AttrOfD(ch) & ~(NONBLANK_ATTR | A_COLOR)) == BLANK_ATTR);
427 * Issue a given span of characters from an array.
428 * Must be functionally equivalent to:
429 * for (i = 0; i < num; i++)
431 * but can leave the cursor positioned at the middle of the interval.
433 * Returns: 0 - cursor is at the end of interval
434 * 1 - cursor is somewhere in the middle
436 * This code is optimized using ech and rep.
439 EmitRange(const NCURSES_CH_T * ntext, int num)
443 if (erase_chars || repeat_char) {
448 while (num > 1 && !CharEq(ntext[0], ntext[1])) {
449 PutChar(CHREF(ntext[0]));
455 PutChar(CHREF(ntext0));
460 while (runcount < num && CharEq(ntext[runcount], ntext0))
464 * The cost expression in the middle isn't exactly right.
465 * _cup_ch_cost is an upper bound on the cost for moving to the
466 * end of the erased area, but not the cost itself (which we
467 * can't compute without emitting the move). This may result
468 * in erase_chars not getting used in some situations for
469 * which it would be marginally advantageous.
472 && runcount > SP->_ech_cost + SP->_cup_ch_cost
473 && can_clear_with(CHREF(ntext0))) {
474 UpdateAttrs(AttrOf(ntext0));
475 putp(tparm(erase_chars, runcount));
478 * If this is the last part of the given interval,
479 * don't bother moving cursor, since it can be the
480 * last update on the line.
482 if (runcount < num) {
483 GoTo(SP->_cursrow, SP->_curscol + runcount);
485 return 1; /* cursor stays in the middle */
487 } else if (repeat_char && runcount > SP->_rep_cost) {
488 bool wrap_possible = (SP->_curscol + runcount >= screen_columns);
489 int rep_count = runcount;
494 UpdateAttrs(AttrOf(ntext0));
495 tputs(tparm(repeat_char, CharOf(ntext0), rep_count),
496 rep_count, _nc_outch);
497 SP->_curscol += rep_count;
500 PutChar(CHREF(ntext0));
502 for (i = 0; i < runcount; i++)
503 PutChar(CHREF(ntext[i]));
511 for (i = 0; i < num; i++)
512 PutChar(CHREF(ntext[i]));
517 * Output the line in the given range [first .. last]
519 * If there's a run of identical characters that's long enough to justify
520 * cursor movement, use that also.
522 * Returns: same as EmitRange
525 PutRange(const NCURSES_CH_T * otext,
526 const NCURSES_CH_T * ntext,
532 TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)",
533 otext, ntext, row, first, last));
536 && (last - first + 1) > SP->_inline_cost) {
537 for (j = first, same = 0; j <= last; j++) {
538 if (!same && isnac(otext[j]))
540 if (CharEq(otext[j], ntext[j])) {
543 if (same > SP->_inline_cost) {
544 EmitRange(ntext + first, j - same - first);
545 GoTo(row, first = j);
550 i = EmitRange(ntext + first, j - same - first);
552 * Always return 1 for the next GoTo() after a PutRange() if we found
553 * identical characters at end of interval
555 return (same == 0 ? i : 1);
557 return EmitRange(ntext + first, last - first + 1);
560 /* leave unbracketed here so 'indent' works */
561 #define MARK_NOCHANGE(win,row) \
562 win->_line[row].firstchar = _NOCHANGE; \
563 win->_line[row].lastchar = _NOCHANGE; \
564 if_USE_SCROLL_HINTS(win->_line[row].oldindex = row)
572 struct tms before, after;
573 #endif /* USE_TRACE_TIMES */
575 T((T_CALLED("doupdate()")));
578 if (_nc_tracing & TRACE_UPDATE) {
580 _tracef("curscr is clear");
582 _tracedump("curscr", curscr);
583 _tracedump("newscr", newscr);
587 _nc_signal_handler(FALSE);
593 if (SP->_endwin || SP->_sig_winch) {
595 * This is a transparent extension: XSI does not address it,
596 * and applications need not know that ncurses can do it.
598 * Check if the terminal size has changed while curses was off
599 * (this can happen in an xterm, for example), and resize the
600 * ncurses data structures accordingly.
602 _nc_update_screensize();
608 T(("coming back from shell mode"));
613 SP->_mouse_resume(SP);
618 /* zero the metering machinery */
620 (void) times(&before);
621 #endif /* USE_TRACE_TIMES */
624 * This is the support for magic-cookie terminals. The
625 * theory: we scan the virtual screen looking for attribute
626 * turnons. Where we find one, check to make sure it's
627 * realizable by seeing if the required number of
628 * un-attributed blanks are present before and after the
629 * attributed range; try to shift the range boundaries over
630 * blanks (not changing the screen display) so this becomes
631 * true. If it is, shift the beginning attribute change
632 * appropriately (the end one, if we've gotten this far, is
633 * guaranteed room for its cookie). If not, nuke the added
634 * attributes out of the span.
637 if (magic_cookie_glitch > 0) {
639 attr_t rattr = A_NORMAL;
641 for (i = 0; i < screen_lines; i++) {
642 for (j = 0; j < screen_columns; j++) {
644 attr_t turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr;
646 /* is an attribute turned on here? */
648 rattr = AttrOf(newscr->_line[i].text[j]);
652 TR(TRACE_ATTRS, ("At (%d, %d): from %s...", i, j, _traceattr(rattr)));
653 TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon)));
656 * If the attribute change location is a blank with a
657 * "safe" attribute, undo the attribute turnon. This may
658 * ensure there's enough room to set the attribute before
659 * the first non-blank in the run.
661 #define SAFE(a) (!((a) & (attr_t)~NONBLANK_ATTR))
662 if (ISBLANK(newscr->_line[i].text[j]) && SAFE(turnon)) {
663 RemAttr(newscr->_line[i].text[j], turnon);
667 /* check that there's enough room at start of span */
668 for (k = 1; k <= magic_cookie_glitch; k++) {
670 || !ISBLANK(newscr->_line[i].text[j - k])
671 || !SAFE(AttrOf(newscr->_line[i].text[j - k])))
675 bool end_onscreen = FALSE;
678 /* find end of span, if it's onscreen */
679 for (m = i; m < screen_lines; m++) {
680 for (; n < screen_columns; n++) {
681 if (AttrOf(newscr->_line[m].text[n]) == rattr) {
684 ("Range attributed with %s ends at (%d, %d)",
685 _traceattr(turnon), m, n));
692 ("Range attributed with %s ends offscreen",
693 _traceattr(turnon)));
697 NCURSES_CH_T *lastline = newscr->_line[m].text;
700 * If there are safely-attributed blanks at the
701 * end of the range, shorten the range. This will
702 * help ensure that there is enough room at end
706 && ISBLANK(lastline[n])
707 && SAFE(AttrOf(lastline[n])))
708 RemAttr(lastline[n--], turnon);
710 /* check that there's enough room at end of span */
711 for (k = 1; k <= magic_cookie_glitch; k++)
712 if (n + k >= screen_columns
713 || !ISBLANK(lastline[n + k])
714 || !SAFE(AttrOf(lastline[n + k])))
723 ("Clearing %s beginning at (%d, %d)",
724 _traceattr(turnon), i, j));
726 /* turn off new attributes over span */
727 for (p = i; p < screen_lines; p++) {
728 for (; q < screen_columns; q++) {
729 if (AttrOf(newscr->_line[p].text[q]) == rattr)
731 RemAttr(newscr->_line[p].text[q], turnon);
738 ("Cookie space for %s found before (%d, %d)",
739 _traceattr(turnon), i, j));
742 * back up the start of range so there's room
743 * for cookies before the first nonblank character
745 for (k = 1; k <= magic_cookie_glitch; k++)
746 AddAttr(newscr->_line[i].text[j - k], turnon);
749 rattr = AttrOf(newscr->_line[i].text[j]);
754 /* show altered highlights after magic-cookie check */
755 if (_nc_tracing & TRACE_UPDATE) {
756 _tracef("After magic-cookie check...");
757 _tracedump("newscr", newscr);
761 #endif /* USE_XMC_SUPPORT */
764 if (curscr->_clear || newscr->_clear) { /* force refresh ? */
765 TR(TRACE_UPDATE, ("clearing and updating from scratch"));
767 curscr->_clear = FALSE; /* reset flag */
768 newscr->_clear = FALSE; /* reset flag */
770 int changedlines = CHECK_INTERVAL;
775 nonempty = min(screen_lines, newscr->_maxy + 1);
777 if (SP->_scrolling) {
778 _nc_scroll_optimize();
781 nonempty = ClrBottom(nonempty);
783 TR(TRACE_UPDATE, ("Transforming lines, nonempty %d", nonempty));
784 for (i = 0; i < nonempty; i++) {
786 * Here is our line-breakout optimization.
788 if (changedlines == CHECK_INTERVAL) {
795 * newscr->line[i].firstchar is normally set
796 * by wnoutrefresh. curscr->line[i].firstchar
797 * is normally set by _nc_scroll_window in the
798 * vertical-movement optimization code,
800 if (newscr->_line[i].firstchar != _NOCHANGE
801 || curscr->_line[i].firstchar != _NOCHANGE) {
806 /* mark line changed successfully */
807 if (i <= newscr->_maxy) {
808 MARK_NOCHANGE(newscr, i);
810 if (i <= curscr->_maxy) {
811 MARK_NOCHANGE(curscr, i);
816 /* put everything back in sync */
817 for (i = nonempty; i <= newscr->_maxy; i++) {
818 MARK_NOCHANGE(newscr, i);
820 for (i = nonempty; i <= curscr->_maxy; i++) {
821 MARK_NOCHANGE(curscr, i);
824 if (!newscr->_leaveok) {
825 curscr->_curx = newscr->_curx;
826 curscr->_cury = newscr->_cury;
828 GoTo(curscr->_cury, curscr->_curx);
833 * Keep the physical screen in normal mode in case we get other
834 * processes writing to the screen.
836 UpdateAttrs(A_NORMAL);
839 curscr->_attrs = newscr->_attrs;
842 (void) times(&after);
844 ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time",
846 (long) (after.tms_stime - before.tms_stime),
847 (long) (after.tms_utime - before.tms_utime)));
848 #endif /* USE_TRACE_TIMES */
850 _nc_signal_handler(TRUE);
858 * Returns the attributed character that corresponds to the "cleared"
859 * screen. If the terminal has the back-color-erase feature, this will be
860 * colored according to the wbkgd() call.
862 * We treat 'curscr' specially because it isn't supposed to be set directly
863 * in the wbkgd() call. Assume 'stdscr' for this case.
865 #define BCE_ATTRS (A_NORMAL|A_COLOR)
866 #define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_nc_bkgd)
868 static inline NCURSES_CH_T
869 ClrBlank(WINDOW *win)
871 NCURSES_CH_T blank = NewChar(BLANK_TEXT);
872 if (back_color_erase)
873 AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS));
880 ** Update by clearing and redrawing the entire screen.
888 NCURSES_CH_T blank = ClrBlank(stdscr);
889 int nonempty = min(screen_lines, newscr->_maxy + 1);
891 TR(TRACE_UPDATE, ("ClrUpdate() called"));
895 TR(TRACE_UPDATE, ("updating screen from scratch"));
897 nonempty = ClrBottom(nonempty);
899 for (i = 0; i < nonempty; i++)
906 ** Clear to end of current line, starting at the cursor position
910 ClrToEOL(NCURSES_CH_T blank, bool needclear)
915 && SP->_cursrow >= 0) {
916 for (j = SP->_curscol; j < screen_columns; j++) {
918 NCURSES_CH_T *cp = &(curscr->_line[SP->_cursrow].text[j]);
920 if (!CharEq(*cp, blank)) {
931 UpdateAttrs(AttrOf(blank));
932 TPUTS_TRACE("clr_eol");
933 if (clr_eol && SP->_el_cost <= (screen_columns - SP->_curscol)) {
936 int count = (screen_columns - SP->_curscol);
938 PutChar(CHREF(blank));
946 ** Clear to end of screen, starting at the cursor position
950 ClrToEOS(NCURSES_CH_T blank)
957 UpdateAttrs(AttrOf(blank));
958 TPUTS_TRACE("clr_eos");
959 tputs(clr_eos, screen_lines - row, _nc_outch);
961 while (col < screen_columns)
962 curscr->_line[row].text[col++] = blank;
964 for (row++; row < screen_lines; row++) {
965 for (col = 0; col < screen_columns; col++)
966 curscr->_line[row].text[col] = blank;
973 * Test if clearing the end of the screen would satisfy part of the
974 * screen-update. Do this by scanning backwards through the lines in the
975 * screen, checking if each is blank, and one or more are changed.
983 int last = min(screen_columns, newscr->_maxx + 1);
984 NCURSES_CH_T blank = newscr->_line[total - 1].text[last - 1];
987 if (clr_eos && can_clear_with(CHREF(blank))) {
989 for (row = total - 1; row >= 0; row--) {
990 for (col = 0, ok = TRUE; ok && col < last; col++) {
991 ok = (CharEq(newscr->_line[row].text[col], blank));
996 for (col = 0; ok && col < last; col++) {
997 ok = (CharEq(curscr->_line[row].text[col], blank));
1003 /* don't use clr_eos for just one line if clr_eol available */
1007 if (SP->oldhash && SP->newhash) {
1008 for (row = top; row < screen_lines; row++)
1009 SP->oldhash[row] = SP->newhash[row];
1017 #if USE_WIDEC_SUPPORT
1019 check_xmc_transition(NCURSES_CH_T * a, NCURSES_CH_T * b)
1021 if (((a->attr ^ b->attr) & ~(a->attr) & SP->_xmc_triggers) != 0) {
1026 #define xmc_turn_on(a,b) check_xmc_transition(&(a), &(b))
1028 #define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0)
1031 #define xmc_new(r,c) newscr->_line[r].text[c]
1032 #define xmc_turn_off(a,b) xmc_turn_on(b,a)
1033 #endif /* USE_XMC_SUPPORT */
1036 ** TransformLine(lineno)
1038 ** Transform the given line in curscr to the one in newscr, using
1039 ** Insert/Delete Character if _nc_idcok && has_ic().
1041 ** firstChar = position of first different character in line
1042 ** oLastChar = position of last different character in old line
1043 ** nLastChar = position of last different character in new line
1045 ** move to firstChar
1046 ** overwrite chars up to min(oLastChar, nLastChar)
1047 ** if oLastChar < nLastChar
1048 ** insert newLine[oLastChar+1..nLastChar]
1050 ** delete oLastChar - nLastChar spaces
1054 TransformLine(int const lineno)
1056 int firstChar, oLastChar, nLastChar;
1057 NCURSES_CH_T *newLine = newscr->_line[lineno].text;
1058 NCURSES_CH_T *oldLine = curscr->_line[lineno].text;
1060 bool attrchanged = FALSE;
1062 TR(TRACE_UPDATE, ("TransformLine(%d) called", lineno));
1064 /* copy new hash value to old one */
1065 if (SP->oldhash && SP->newhash)
1066 SP->oldhash[lineno] = SP->newhash[lineno];
1068 #define ColorOf(n) (AttrOf(n) & A_COLOR)
1069 #define unColor(n) (AttrOf(n) & ALL_BUT_COLOR)
1071 * If we have colors, there is the possibility of having two color pairs
1072 * that display as the same colors. For instance, Lynx does this. Check
1073 * for this case, and update the old line with the new line's colors when
1074 * they are equivalent.
1082 for (n = 0; n < screen_columns; n++) {
1083 if (!CharEq(newLine[n], oldLine[n])) {
1084 oldColor = ColorOf(oldLine[n]);
1085 newColor = ColorOf(newLine[n]);
1086 if (oldColor != newColor
1087 && unColor(oldLine[n]) == unColor(newLine[n])) {
1088 oldPair = PAIR_NUMBER(oldColor);
1089 newPair = PAIR_NUMBER(newColor);
1090 if (oldPair < COLOR_PAIRS
1091 && newPair < COLOR_PAIRS
1092 && SP->_color_pairs[oldPair] == SP->_color_pairs[newPair]) {
1093 RemAttr(oldLine[n], A_COLOR);
1094 AddAttr(oldLine[n], ColorOf(newLine[n]));
1101 if (ceol_standout_glitch && clr_eol) {
1103 while (firstChar < screen_columns) {
1104 if (AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) {
1114 if (attrchanged) { /* we may have to disregard the whole line */
1115 GoTo(lineno, firstChar);
1116 ClrToEOL(ClrBlank(curscr), FALSE);
1117 PutRange(oldLine, newLine, lineno, 0, (screen_columns - 1));
1121 * This is a very simple loop to paint characters which may have the
1122 * magic cookie glitch embedded. It doesn't know much about video
1123 * attributes which are continued from one line to the next. It
1124 * assumes that we have filtered out requests for attribute changes
1125 * that do not get mapped to blank positions.
1127 * FIXME: we are not keeping track of where we put the cookies, so this
1128 * will work properly only once, since we may overwrite a cookie in a
1129 * following operation.
1131 } else if (magic_cookie_glitch > 0) {
1132 GoTo(lineno, firstChar);
1133 for (n = 0; n < screen_columns; n++) {
1134 int m = n + magic_cookie_glitch;
1136 /* check for turn-on:
1137 * If we are writing an attributed blank, where the
1138 * previous cell is not attributed.
1140 if (ISBLANK(newLine[n])
1142 && xmc_turn_on(newLine[n - 1], newLine[n]))
1145 && xmc_turn_on(xmc_new(lineno - 1, screen_columns - 1),
1150 PutChar(CHREF(newLine[n]));
1152 /* check for turn-off:
1153 * If we are writing an attributed non-blank, where the
1154 * next cell is blank, and not attributed.
1156 if (!ISBLANK(newLine[n])
1157 && ((n + 1 < screen_columns
1158 && xmc_turn_off(newLine[n], newLine[n + 1]))
1159 || (n + 1 >= screen_columns
1160 && lineno + 1 < screen_lines
1161 && xmc_turn_off(newLine[n], xmc_new(lineno + 1, 0))))) {
1170 /* it may be cheap to clear leading whitespace with clr_bol */
1172 if (clr_bol && can_clear_with(CHREF(blank))) {
1173 int oFirstChar, nFirstChar;
1175 for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++)
1176 if (!CharEq(oldLine[oFirstChar], blank))
1178 for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++)
1179 if (!CharEq(newLine[nFirstChar], blank))
1182 if (nFirstChar == oFirstChar) {
1183 firstChar = nFirstChar;
1184 /* find the first differing character */
1185 while (firstChar < screen_columns
1186 && CharEq(newLine[firstChar], oldLine[firstChar]))
1188 } else if (oFirstChar > nFirstChar) {
1189 firstChar = nFirstChar;
1190 } else { /* oFirstChar < nFirstChar */
1191 firstChar = oFirstChar;
1192 if (SP->_el1_cost < nFirstChar - oFirstChar) {
1193 if (nFirstChar >= screen_columns
1194 && SP->_el_cost <= SP->_el1_cost) {
1196 UpdateAttrs(AttrOf(blank));
1197 TPUTS_TRACE("clr_eol");
1200 GoTo(lineno, nFirstChar - 1);
1201 UpdateAttrs(AttrOf(blank));
1202 TPUTS_TRACE("clr_bol");
1206 while (firstChar < nFirstChar)
1207 oldLine[firstChar++] = blank;
1211 /* find the first differing character */
1212 while (firstChar < screen_columns
1213 && CharEq(newLine[firstChar], oldLine[firstChar]))
1216 /* if there wasn't one, we're done */
1217 if (firstChar >= screen_columns)
1220 blank = newLine[screen_columns - 1];
1222 if (!can_clear_with(CHREF(blank))) {
1223 /* find the last differing character */
1224 nLastChar = screen_columns - 1;
1226 while (nLastChar > firstChar
1227 && CharEq(newLine[nLastChar], oldLine[nLastChar]))
1230 if (nLastChar >= firstChar) {
1231 GoTo(lineno, firstChar);
1232 PutRange(oldLine, newLine, lineno, firstChar, nLastChar);
1233 memcpy(oldLine + firstChar,
1234 newLine + firstChar,
1235 (nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T));
1240 /* find last non-blank character on old line */
1241 oLastChar = screen_columns - 1;
1242 while (oLastChar > firstChar && CharEq(oldLine[oLastChar], blank))
1245 /* find last non-blank character on new line */
1246 nLastChar = screen_columns - 1;
1247 while (nLastChar > firstChar && CharEq(newLine[nLastChar], blank))
1250 if ((nLastChar == firstChar)
1251 && (SP->_el_cost < (oLastChar - nLastChar))) {
1252 GoTo(lineno, firstChar);
1253 if (!CharEq(newLine[firstChar], blank))
1254 PutChar(CHREF(newLine[firstChar]));
1255 ClrToEOL(blank, FALSE);
1256 } else if ((nLastChar != oLastChar)
1257 && (!CharEq(newLine[nLastChar], oldLine[oLastChar])
1258 || !(_nc_idcok && has_ic()))) {
1259 GoTo(lineno, firstChar);
1260 if ((oLastChar - nLastChar) > SP->_el_cost) {
1261 if (PutRange(oldLine, newLine, lineno, firstChar, nLastChar))
1262 GoTo(lineno, nLastChar + 1);
1263 ClrToEOL(blank, FALSE);
1265 n = max(nLastChar, oLastChar);
1266 PutRange(oldLine, newLine, lineno, firstChar, n);
1269 int nLastNonblank = nLastChar;
1270 int oLastNonblank = oLastChar;
1272 /* find the last characters that really differ */
1273 /* can be -1 if no characters differ */
1274 while (CharEq(newLine[nLastChar], oldLine[oLastChar])) {
1275 /* don't split a wide char */
1276 if (isnac(newLine[nLastChar]) &&
1277 !CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1]))
1281 if (nLastChar == -1 || oLastChar == -1)
1285 n = min(oLastChar, nLastChar);
1286 if (n >= firstChar) {
1287 GoTo(lineno, firstChar);
1288 PutRange(oldLine, newLine, lineno, firstChar, n);
1291 if (oLastChar < nLastChar) {
1292 int m = max(nLastNonblank, oLastNonblank);
1293 GoTo(lineno, n + 1);
1294 if (InsCharCost(nLastChar - oLastChar)
1296 PutRange(oldLine, newLine, lineno, n + 1, m);
1298 InsStr(&newLine[n + 1], nLastChar - oLastChar);
1300 } else if (oLastChar > nLastChar) {
1301 GoTo(lineno, n + 1);
1302 if (DelCharCost(oLastChar - nLastChar)
1303 > SP->_el_cost + nLastNonblank - (n + 1)) {
1304 if (PutRange(oldLine, newLine, lineno,
1305 n + 1, nLastNonblank))
1306 GoTo(lineno, nLastNonblank + 1);
1307 ClrToEOL(blank, FALSE);
1310 * The delete-char sequence will
1311 * effectively shift in blanks from the
1312 * right margin of the screen. Ensure
1313 * that they are the right color by
1314 * setting the video attributes from
1315 * the last character on the row.
1317 UpdateAttrs(AttrOf(blank));
1318 DelChar(oLastChar - nLastChar);
1324 /* update the code's internal representation */
1325 if (screen_columns > firstChar)
1326 memcpy(oldLine + firstChar,
1327 newLine + firstChar,
1328 (screen_columns - firstChar) * sizeof(NCURSES_CH_T));
1332 ** ClearScreen(blank)
1334 ** Clear the physical screen and put cursor at home
1339 ClearScreen(NCURSES_CH_T blank)
1342 bool fast_clear = (clear_screen || clr_eos || clr_eol);
1344 TR(TRACE_UPDATE, ("ClearScreen() called"));
1346 #if NCURSES_EXT_FUNCS
1348 && !SP->_default_color) {
1349 _nc_do_color((int) COLOR_PAIR(SP->_current_attr), 0, FALSE, _nc_outch);
1350 if (!back_color_erase) {
1358 UpdateAttrs(AttrOf(blank));
1359 TPUTS_TRACE("clear_screen");
1361 SP->_cursrow = SP->_curscol = 0;
1362 position_check(SP->_cursrow, SP->_curscol, "ClearScreen");
1363 } else if (clr_eos) {
1364 SP->_cursrow = SP->_curscol = -1;
1367 UpdateAttrs(AttrOf(blank));
1368 TPUTS_TRACE("clr_eos");
1369 tputs(clr_eos, screen_lines, _nc_outch);
1370 } else if (clr_eol) {
1371 SP->_cursrow = SP->_curscol = -1;
1373 UpdateAttrs(AttrOf(blank));
1374 for (i = 0; i < screen_lines; i++) {
1376 TPUTS_TRACE("clr_eol");
1382 UpdateAttrs(AttrOf(blank));
1383 for (i = 0; i < screen_lines; i++) {
1385 for (j = 0; j < screen_columns; j++)
1386 PutChar(CHREF(blank));
1391 for (i = 0; i < screen_lines; i++) {
1392 for (j = 0; j < screen_columns; j++)
1393 curscr->_line[i].text[j] = blank;
1396 TR(TRACE_UPDATE, ("screen cleared"));
1400 ** InsStr(line, count)
1402 ** Insert the count characters pointed to by line.
1407 InsStr(NCURSES_CH_T * line, int count)
1409 TR(TRACE_UPDATE, ("InsStr(%p,%d) called", line, count));
1411 /* Prefer parm_ich as it has the smallest cost - no need to shift
1412 * the whole line on each character. */
1413 /* The order must match that of InsCharCost. */
1415 TPUTS_TRACE("parm_ich");
1416 tputs(tparm(parm_ich, count), count, _nc_outch);
1418 PutAttrChar(CHREF(*line));
1422 } else if (enter_insert_mode && exit_insert_mode) {
1423 TPUTS_TRACE("enter_insert_mode");
1424 putp(enter_insert_mode);
1426 PutAttrChar(CHREF(*line));
1427 if (insert_padding) {
1428 TPUTS_TRACE("insert_padding");
1429 putp(insert_padding);
1434 TPUTS_TRACE("exit_insert_mode");
1435 putp(exit_insert_mode);
1438 TPUTS_TRACE("insert_character");
1439 putp(insert_character);
1440 PutAttrChar(CHREF(*line));
1441 if (insert_padding) {
1442 TPUTS_TRACE("insert_padding");
1443 putp(insert_padding);
1449 position_check(SP->_cursrow, SP->_curscol, "InsStr");
1455 ** Delete count characters at current position
1464 TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%d,%d)", count,
1465 newscr->_cury, newscr->_curx));
1468 TPUTS_TRACE("parm_dch");
1469 tputs(tparm(parm_dch, count), count, _nc_outch);
1471 for (n = 0; n < count; n++) {
1472 TPUTS_TRACE("delete_character");
1473 putp(delete_character);
1479 * Physical-scrolling support
1481 * This code was adapted from Keith Bostic's hardware scrolling
1482 * support for 4.4BSD curses. I (esr) translated it to use terminfo
1483 * capabilities, narrowed the call interface slightly, and cleaned
1484 * up some convoluted tests. I also added support for the memory_above
1485 * memory_below, and non_dest_scroll_region capabilities.
1487 * For this code to work, we must have either
1488 * change_scroll_region and scroll forward/reverse commands, or
1489 * insert and delete line capabilities.
1490 * When the scrolling region has been set, the cursor has to
1491 * be at the last line of the region to make the scroll up
1492 * happen, or on the first line of region to scroll down.
1494 * This code makes one aesthetic decision in the opposite way from
1495 * BSD curses. BSD curses preferred pairs of il/dl operations
1496 * over scrolls, allegedly because il/dl looked faster. We, on
1497 * the other hand, prefer scrolls because (a) they're just as fast
1498 * on many terminals and (b) using them avoids bouncing an
1499 * unchanged bottom section of the screen up and down, which is
1502 * (lav): added more cases, used dl/il when bot==maxy and in csr case.
1504 * I used assumption that capabilities il/il1/dl/dl1 work inside
1505 * changed scroll region not shifting screen contents outside of it.
1506 * If there are any terminals behaving different way, it would be
1507 * necessary to add some conditions to scroll_csr_forward/backward.
1510 /* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */
1512 scroll_csr_forward(int n, int top, int bot, int miny, int maxy, NCURSES_CH_T blank)
1516 if (n == 1 && scroll_forward && top == miny && bot == maxy) {
1518 UpdateAttrs(AttrOf(blank));
1519 TPUTS_TRACE("scroll_forward");
1520 putp(scroll_forward);
1521 } else if (n == 1 && delete_line && bot == maxy) {
1523 UpdateAttrs(AttrOf(blank));
1524 TPUTS_TRACE("delete_line");
1526 } else if (parm_index && top == miny && bot == maxy) {
1528 UpdateAttrs(AttrOf(blank));
1529 TPUTS_TRACE("parm_index");
1530 tputs(tparm(parm_index, n, 0), n, _nc_outch);
1531 } else if (parm_delete_line && bot == maxy) {
1533 UpdateAttrs(AttrOf(blank));
1534 TPUTS_TRACE("parm_delete_line");
1535 tputs(tparm(parm_delete_line, n, 0), n, _nc_outch);
1536 } else if (scroll_forward && top == miny && bot == maxy) {
1538 UpdateAttrs(AttrOf(blank));
1539 for (i = 0; i < n; i++) {
1540 TPUTS_TRACE("scroll_forward");
1541 putp(scroll_forward);
1543 } else if (delete_line && bot == maxy) {
1545 UpdateAttrs(AttrOf(blank));
1546 for (i = 0; i < n; i++) {
1547 TPUTS_TRACE("delete_line");
1553 #if NCURSES_EXT_FUNCS
1556 for (i = 0; i < n; i++) {
1558 for (j = 0; j < screen_columns; j++)
1559 PutChar(CHREF(blank));
1566 /* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */
1569 scroll_csr_backward(int n, int top, int bot, int miny, int maxy,
1574 if (n == 1 && scroll_reverse && top == miny && bot == maxy) {
1576 UpdateAttrs(AttrOf(blank));
1577 TPUTS_TRACE("scroll_reverse");
1578 putp(scroll_reverse);
1579 } else if (n == 1 && insert_line && bot == maxy) {
1581 UpdateAttrs(AttrOf(blank));
1582 TPUTS_TRACE("insert_line");
1584 } else if (parm_rindex && top == miny && bot == maxy) {
1586 UpdateAttrs(AttrOf(blank));
1587 TPUTS_TRACE("parm_rindex");
1588 tputs(tparm(parm_rindex, n, 0), n, _nc_outch);
1589 } else if (parm_insert_line && bot == maxy) {
1591 UpdateAttrs(AttrOf(blank));
1592 TPUTS_TRACE("parm_insert_line");
1593 tputs(tparm(parm_insert_line, n, 0), n, _nc_outch);
1594 } else if (scroll_reverse && top == miny && bot == maxy) {
1596 UpdateAttrs(AttrOf(blank));
1597 for (i = 0; i < n; i++) {
1598 TPUTS_TRACE("scroll_reverse");
1599 putp(scroll_reverse);
1601 } else if (insert_line && bot == maxy) {
1603 UpdateAttrs(AttrOf(blank));
1604 for (i = 0; i < n; i++) {
1605 TPUTS_TRACE("insert_line");
1611 #if NCURSES_EXT_FUNCS
1614 for (i = 0; i < n; i++) {
1616 for (j = 0; j < screen_columns; j++)
1617 PutChar(CHREF(blank));
1624 /* scroll by using delete_line at del and insert_line at ins */
1627 scroll_idl(int n, int del, int ins, NCURSES_CH_T blank)
1631 if (!((parm_delete_line || delete_line) && (parm_insert_line || insert_line)))
1635 UpdateAttrs(AttrOf(blank));
1636 if (n == 1 && delete_line) {
1637 TPUTS_TRACE("delete_line");
1639 } else if (parm_delete_line) {
1640 TPUTS_TRACE("parm_delete_line");
1641 tputs(tparm(parm_delete_line, n, 0), n, _nc_outch);
1642 } else { /* if (delete_line) */
1643 for (i = 0; i < n; i++) {
1644 TPUTS_TRACE("delete_line");
1650 UpdateAttrs(AttrOf(blank));
1651 if (n == 1 && insert_line) {
1652 TPUTS_TRACE("insert_line");
1654 } else if (parm_insert_line) {
1655 TPUTS_TRACE("parm_insert_line");
1656 tputs(tparm(parm_insert_line, n, 0), n, _nc_outch);
1657 } else { /* if (insert_line) */
1658 for (i = 0; i < n; i++) {
1659 TPUTS_TRACE("insert_line");
1668 * Note: some terminals require the cursor to be within the scrolling margins
1669 * before setting them. Generally, the cursor must be at the appropriate end
1670 * of the scrolling margins when issuing an indexing operation (it is not
1671 * apparent whether it must also be at the left margin; we do this just to be
1672 * safe). To make the related cursor movement a little faster, we use the
1673 * save/restore cursor capabilities if the terminal has them.
1676 _nc_scrolln(int n, int top, int bot, int maxy)
1677 /* scroll region from top to bot by n lines */
1679 NCURSES_CH_T blank = ClrBlank(stdscr);
1681 bool cursor_saved = FALSE;
1684 TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy));
1688 * If we scroll, we might remove a cookie.
1690 if (magic_cookie_glitch > 0) {
1695 if (n > 0) { /* scroll up (forward) */
1697 * Explicitly clear if stuff pushed off top of region might
1698 * be saved by the terminal.
1700 res = scroll_csr_forward(n, top, bot, 0, maxy, blank);
1702 if (res == ERR && change_scroll_region) {
1703 if ((((n == 1 && scroll_forward) || parm_index)
1704 && (SP->_cursrow == bot || SP->_cursrow == bot - 1))
1705 && save_cursor && restore_cursor) {
1706 cursor_saved = TRUE;
1707 TPUTS_TRACE("save_cursor");
1710 TPUTS_TRACE("change_scroll_region");
1711 putp(tparm(change_scroll_region, top, bot));
1713 TPUTS_TRACE("restore_cursor");
1714 putp(restore_cursor);
1716 SP->_cursrow = SP->_curscol = -1;
1719 res = scroll_csr_forward(n, top, bot, top, bot, blank);
1721 TPUTS_TRACE("change_scroll_region");
1722 putp(tparm(change_scroll_region, 0, maxy));
1723 SP->_cursrow = SP->_curscol = -1;
1726 if (res == ERR && _nc_idlok)
1727 res = scroll_idl(n, top, bot - n + 1, blank);
1730 * Clear the newly shifted-in text.
1733 && (non_dest_scroll_region || (memory_below && bot == maxy))) {
1734 NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
1735 if (bot == maxy && clr_eos) {
1736 GoTo(bot - n + 1, 0);
1739 for (i = 0; i < n; i++) {
1741 ClrToEOL(blank2, FALSE);
1746 } else { /* (n < 0) - scroll down (backward) */
1747 res = scroll_csr_backward(-n, top, bot, 0, maxy, blank);
1749 if (res == ERR && change_scroll_region) {
1750 if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top - 1)
1751 && save_cursor && restore_cursor) {
1752 cursor_saved = TRUE;
1753 TPUTS_TRACE("save_cursor");
1756 TPUTS_TRACE("change_scroll_region");
1757 putp(tparm(change_scroll_region, top, bot));
1759 TPUTS_TRACE("restore_cursor");
1760 putp(restore_cursor);
1762 SP->_cursrow = SP->_curscol = -1;
1765 res = scroll_csr_backward(-n, top, bot, top, bot, blank);
1767 TPUTS_TRACE("change_scroll_region");
1768 putp(tparm(change_scroll_region, 0, maxy));
1769 SP->_cursrow = SP->_curscol = -1;
1772 if (res == ERR && _nc_idlok)
1773 res = scroll_idl(-n, bot + n + 1, top, blank);
1776 * Clear the newly shifted-in text.
1779 && (non_dest_scroll_region || (memory_above && top == 0))) {
1780 NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
1781 for (i = 0; i < -n; i++) {
1783 ClrToEOL(blank2, FALSE);
1791 _nc_scroll_window(curscr, n, top, bot, blank);
1793 /* shift hash values too - they can be reused */
1794 _nc_scroll_oldhash(n, top, bot);
1799 NCURSES_EXPORT(void)
1800 _nc_screen_resume(void)
1802 /* make sure terminal is in a sane known state */
1803 SP->_current_attr = A_NORMAL;
1804 newscr->_clear = TRUE;
1806 /* reset color pairs and definitions */
1807 if (SP->_coloron || SP->_color_defs)
1810 /* restore user-defined colors, if any */
1811 if (SP->_color_defs < 0) {
1813 SP->_color_defs = -(SP->_color_defs);
1814 for (n = 0; n < SP->_color_defs; ++n) {
1815 if (SP->_color_table[n].init) {
1817 SP->_color_table[n].r,
1818 SP->_color_table[n].g,
1819 SP->_color_table[n].b);
1824 if (exit_attribute_mode)
1825 putp(exit_attribute_mode);
1827 /* turn off attributes */
1828 if (exit_alt_charset_mode)
1829 putp(exit_alt_charset_mode);
1830 if (exit_standout_mode)
1831 putp(exit_standout_mode);
1832 if (exit_underline_mode)
1833 putp(exit_underline_mode);
1835 if (exit_insert_mode)
1836 putp(exit_insert_mode);
1837 if (enter_am_mode && exit_am_mode)
1838 putp(auto_right_margin ? enter_am_mode : exit_am_mode);
1841 NCURSES_EXPORT(void)
1842 _nc_screen_init(void)
1844 _nc_screen_resume();
1847 /* wrap up screen handling */
1848 NCURSES_EXPORT(void)
1849 _nc_screen_wrap(void)
1851 UpdateAttrs(A_NORMAL);
1852 #if NCURSES_EXT_FUNCS
1854 && !SP->_default_color) {
1855 NCURSES_CH_T blank = NewChar(BLANK_TEXT);
1856 SP->_default_color = TRUE;
1857 _nc_do_color(-1, 0, FALSE, _nc_outch);
1858 SP->_default_color = FALSE;
1860 mvcur(SP->_cursrow, SP->_curscol, screen_lines - 1, 0);
1862 ClrToEOL(blank, TRUE);
1865 if (SP->_color_defs) {
1871 NCURSES_EXPORT(void)
1872 _nc_do_xmc_glitch(attr_t previous)
1874 attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr);
1878 SP->_curscol += magic_cookie_glitch;
1879 if (SP->_curscol >= SP->_columns)
1881 TR(TRACE_UPDATE, ("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol));
1886 #endif /* USE_XMC_SUPPORT */