blob: e66f71605ee27254ca40868502f2b2d946020b66 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +01002 * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05303 * *
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: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
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. *
22 * *
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 *
26 * authorization. *
27 ****************************************************************************/
28
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-on *
Steve Kondikae271bc2015-11-15 02:50:53 +010033 * and: Juergen Pfeifer 2009 *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053034 ****************************************************************************/
35
36/*-----------------------------------------------------------------
37 *
38 * lib_doupdate.c
39 *
40 * The routine doupdate() and its dependents.
41 * All physical output is concentrated here (except _nc_outch()
Steve Kondikae271bc2015-11-15 02:50:53 +010042 * in lib_tputs.c).
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053043 *
44 *-----------------------------------------------------------------*/
45
46#include <curses.priv.h>
47
Steve Kondikae271bc2015-11-15 02:50:53 +010048#ifndef CUR
49#define CUR SP_TERMTYPE
50#endif
51
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053052#if defined __HAIKU__ && defined __BEOS__
53#undef __BEOS__
54#endif
55
56#ifdef __BEOS__
57#undef false
58#undef true
59#include <OS.h>
60#endif
61
62#if defined(TRACE) && HAVE_SYS_TIMES_H && HAVE_TIMES
63#define USE_TRACE_TIMES 1
64#else
65#define USE_TRACE_TIMES 0
66#endif
67
68#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
69#include <sys/time.h>
70#endif
71
72#if USE_TRACE_TIMES
73#include <sys/times.h>
74#endif
75
76#if USE_FUNC_POLL
77#elif HAVE_SELECT
78#if HAVE_SYS_SELECT_H
79#include <sys/select.h>
80#endif
81#endif
82
83#include <ctype.h>
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053084
Steve Kondikae271bc2015-11-15 02:50:53 +010085MODULE_ID("$Id: tty_update.c,v 1.280 2014/08/23 19:25:18 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053086
87/*
88 * This define controls the line-breakout optimization. Every once in a
89 * while during screen refresh, we want to check for input and abort the
90 * update if there's some waiting. CHECK_INTERVAL controls the number of
91 * changed lines to be emitted between input checks.
92 *
93 * Note: Input-check-and-abort is no longer done if the screen is being
94 * updated from scratch. This is a feature, not a bug.
95 */
96#define CHECK_INTERVAL 5
97
Steve Kondikae271bc2015-11-15 02:50:53 +010098#define FILL_BCE(sp) (sp->_coloron && !sp->_default_color && !back_color_erase)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053099
100static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
101static NCURSES_CH_T normal = NewChar(BLANK_TEXT);
102
103/*
104 * Enable checking to see if doupdate and friends are tracking the true
105 * cursor position correctly. NOTE: this is a debugging hack which will
106 * work ONLY on ANSI-compatible terminals!
107 */
108/* #define POSITION_DEBUG */
109
Steve Kondikae271bc2015-11-15 02:50:53 +0100110static NCURSES_INLINE NCURSES_CH_T ClrBlank(NCURSES_SP_DCLx WINDOW *win);
111
112#if NCURSES_SP_FUNCS
113static int ClrBottom(SCREEN *, int total);
114static void ClearScreen(SCREEN *, NCURSES_CH_T blank);
115static void ClrUpdate(SCREEN *);
116static void DelChar(SCREEN *, int count);
117static void InsStr(SCREEN *, NCURSES_CH_T * line, int count);
118static void TransformLine(SCREEN *, int const lineno);
119#else
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530120static int ClrBottom(int total);
121static void ClearScreen(NCURSES_CH_T blank);
122static void ClrUpdate(void);
123static void DelChar(int count);
124static void InsStr(NCURSES_CH_T * line, int count);
125static void TransformLine(int const lineno);
Steve Kondikae271bc2015-11-15 02:50:53 +0100126#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530127
128#ifdef POSITION_DEBUG
129/****************************************************************************
130 *
131 * Debugging code. Only works on ANSI-standard terminals.
132 *
133 ****************************************************************************/
134
135static void
Steve Kondikae271bc2015-11-15 02:50:53 +0100136position_check(NCURSES_SP_DCLx int expected_y, int expected_x, char *legend)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530137/* check to see if the real cursor position matches the virtual */
138{
139 char buf[20];
140 char *s;
141 int y, x;
142
143 if (!_nc_tracing || (expected_y < 0 && expected_x < 0))
144 return;
145
Steve Kondikae271bc2015-11-15 02:50:53 +0100146 NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530147 memset(buf, '\0', sizeof(buf));
Steve Kondikae271bc2015-11-15 02:50:53 +0100148 NCURSES_PUTP2_FLUSH("cpr", "\033[6n"); /* only works on ANSI-compatibles */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530149 *(s = buf) = 0;
150 do {
151 int ask = sizeof(buf) - 1 - (s - buf);
152 int got = read(0, s, ask);
153 if (got == 0)
154 break;
155 s += got;
156 } while (strchr(buf, 'R') == 0);
157 _tracef("probe returned %s", _nc_visbuf(buf));
158
159 /* try to interpret as a position report */
160 if (sscanf(buf, "\033[%d;%dR", &y, &x) != 2) {
161 _tracef("position probe failed in %s", legend);
162 } else {
163 if (expected_x < 0)
164 expected_x = x - 1;
165 if (expected_y < 0)
166 expected_y = y - 1;
167 if (y - 1 != expected_y || x - 1 != expected_x) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100168 NCURSES_SP_NAME(beep) (NCURSES_SP_ARG);
169 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
170 tparm("\033[%d;%dH",
171 expected_y + 1,
172 expected_x + 1),
173 1, NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530174 _tracef("position seen (%d, %d) doesn't match expected one (%d, %d) in %s",
175 y - 1, x - 1, expected_y, expected_x, legend);
176 } else {
177 _tracef("position matches OK in %s", legend);
178 }
179 }
180}
181#else
182#define position_check(expected_y, expected_x, legend) /* nothing */
183#endif /* POSITION_DEBUG */
184
185/****************************************************************************
186 *
187 * Optimized update code
188 *
189 ****************************************************************************/
190
191static NCURSES_INLINE void
Steve Kondikae271bc2015-11-15 02:50:53 +0100192GoTo(NCURSES_SP_DCLx int const row, int const col)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530193{
Steve Kondikae271bc2015-11-15 02:50:53 +0100194 TR(TRACE_MOVE, ("GoTo(%p, %d, %d) from (%d, %d)",
195 (void *) SP_PARM, row, col, SP_PARM->_cursrow, SP_PARM->_curscol));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530196
Steve Kondikae271bc2015-11-15 02:50:53 +0100197 position_check(NCURSES_SP_ARGx
198 SP_PARM->_cursrow,
199 SP_PARM->_curscol, "GoTo");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530200
Steve Kondikae271bc2015-11-15 02:50:53 +0100201 TINFO_MVCUR(NCURSES_SP_ARGx
202 SP_PARM->_cursrow,
203 SP_PARM->_curscol,
204 row, col);
205 position_check(NCURSES_SP_ARGx
206 SP_PARM->_cursrow,
207 SP_PARM->_curscol, "GoTo2");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530208}
209
210static NCURSES_INLINE void
Steve Kondikae271bc2015-11-15 02:50:53 +0100211PutAttrChar(NCURSES_SP_DCLx CARG_CH_T ch)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530212{
213 int chlen = 1;
214 NCURSES_CH_T my_ch;
Steve Kondikae271bc2015-11-15 02:50:53 +0100215#if USE_WIDEC_SUPPORT
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530216 PUTC_DATA;
Steve Kondikae271bc2015-11-15 02:50:53 +0100217#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530218 NCURSES_CH_T tilde;
219 NCURSES_CH_T attr = CHDEREF(ch);
220
221 TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)",
222 _tracech_t(ch),
Steve Kondikae271bc2015-11-15 02:50:53 +0100223 SP_PARM->_cursrow, SP_PARM->_curscol));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530224#if USE_WIDEC_SUPPORT
225 /*
226 * If this is not a valid character, there is nothing more to do.
227 */
228 if (isWidecExt(CHDEREF(ch))) {
229 TR(TRACE_CHARPUT, ("...skip"));
230 return;
231 }
232 /*
233 * Determine the number of character cells which the 'ch' value will use
234 * on the screen. It should be at least one.
235 */
236 if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) {
237 static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
238
239 /*
240 * If the character falls into any of these special cases, do
241 * not force the result to a blank:
242 *
243 * a) it is printable (this works around a bug in wcwidth()).
244 * b) use_legacy_coding() has been called to modify the treatment
245 * of codes 128-255.
246 * c) the acs_map[] has been initialized to allow codes 0-31
247 * to be rendered. This supports Linux console's "PC"
248 * characters. Codes 128-255 are allowed though this is
249 * not checked.
250 */
251 if (is8bits(CharOf(CHDEREF(ch)))
252 && (isprint(CharOf(CHDEREF(ch)))
Steve Kondikae271bc2015-11-15 02:50:53 +0100253 || (SP_PARM->_legacy_coding > 0 && CharOf(CHDEREF(ch)) >= 160)
254 || (SP_PARM->_legacy_coding > 1 && CharOf(CHDEREF(ch)) >= 128)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530255 || (AttrOf(attr) & A_ALTCHARSET
256 && ((CharOfD(ch) < ACS_LEN
Steve Kondikae271bc2015-11-15 02:50:53 +0100257 && SP_PARM->_acs_map != 0
258 && SP_PARM->_acs_map[CharOfD(ch)] != 0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530259 || (CharOfD(ch) >= 128))))) {
260 ;
261 } else {
262 ch = CHREF(blank);
263 TR(TRACE_CHARPUT, ("forced to blank"));
264 }
265 chlen = 1;
266 }
267#endif
268
269 if ((AttrOf(attr) & A_ALTCHARSET)
Steve Kondikae271bc2015-11-15 02:50:53 +0100270 && SP_PARM->_acs_map != 0
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530271 && CharOfD(ch) < ACS_LEN) {
272 my_ch = CHDEREF(ch); /* work around const param */
273#if USE_WIDEC_SUPPORT
274 /*
275 * This is crude & ugly, but works most of the time. It checks if the
276 * acs_chars string specified that we have a mapping for this
277 * character, and uses the wide-character mapping when we expect the
278 * normal one to be broken (by mis-design ;-).
279 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100280 if (SP_PARM->_screen_acs_fix
281 && SP_PARM->_screen_acs_map[CharOf(my_ch)]) {
282 RemAttr(attr, A_ALTCHARSET);
283 my_ch = _nc_wacs[CharOf(my_ch)];
284 } else if (SP_PARM->_screen_unicode
285 && !SP_PARM->_screen_acs_map[CharOf(my_ch)]
286 && _nc_wacs[CharOf(my_ch)].chars[0]) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530287 RemAttr(attr, A_ALTCHARSET);
288 my_ch = _nc_wacs[CharOf(my_ch)];
289 }
290#endif
291 /*
292 * If we (still) have alternate character set, it is the normal 8bit
293 * flavor. The _screen_acs_map[] array tells if the character was
294 * really in acs_chars, needed because of the way wide/normal line
295 * drawing flavors are integrated.
296 */
297 if (AttrOf(attr) & A_ALTCHARSET) {
298 int j = CharOfD(ch);
Steve Kondikae271bc2015-11-15 02:50:53 +0100299 chtype temp = UChar(SP_PARM->_acs_map[j]);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530300
Steve Kondikae271bc2015-11-15 02:50:53 +0100301 if (temp != 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530302 SetChar(my_ch, temp, AttrOf(attr));
Steve Kondikae271bc2015-11-15 02:50:53 +0100303 } else {
304 my_ch = CHDEREF(ch);
305 RemAttr(attr, A_ALTCHARSET);
306 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530307 }
308 ch = CHREF(my_ch);
309 }
310 if (tilde_glitch && (CharOfD(ch) == L('~'))) {
311 SetChar(tilde, L('`'), AttrOf(attr));
312 ch = CHREF(tilde);
313 }
314
Steve Kondikae271bc2015-11-15 02:50:53 +0100315 UpdateAttrs(SP_PARM, attr);
316 PUTC(CHDEREF(ch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530317#if !USE_WIDEC_SUPPORT
Steve Kondikae271bc2015-11-15 02:50:53 +0100318 COUNT_OUTCHARS(1);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530319#endif
Steve Kondikae271bc2015-11-15 02:50:53 +0100320 SP_PARM->_curscol += chlen;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530321 if (char_padding) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100322 NCURSES_PUTP2("char_padding", char_padding);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530323 }
324}
325
326static bool
Steve Kondikae271bc2015-11-15 02:50:53 +0100327check_pending(NCURSES_SP_DCL0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530328/* check for pending input */
329{
330 bool have_pending = FALSE;
331
332 /*
333 * Only carry out this check when the flag is zero, otherwise we'll
334 * have the refreshing slow down drastically (or stop) if there's an
335 * unread character available.
336 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100337 if (SP_PARM->_fifohold != 0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530338 return FALSE;
339
Steve Kondikae271bc2015-11-15 02:50:53 +0100340 if (SP_PARM->_checkfd >= 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530341#if USE_FUNC_POLL
342 struct pollfd fds[1];
Steve Kondikae271bc2015-11-15 02:50:53 +0100343 fds[0].fd = SP_PARM->_checkfd;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530344 fds[0].events = POLLIN;
Steve Kondikae271bc2015-11-15 02:50:53 +0100345 if (poll(fds, (size_t) 1, 0) > 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530346 have_pending = TRUE;
347 }
348#elif defined(__BEOS__)
349 /*
350 * BeOS's select() is declared in socket.h, so the configure script does
351 * not see it. That's just as well, since that function works only for
352 * sockets. This (using snooze and ioctl) was distilled from Be's patch
353 * for ncurses which uses a separate thread to simulate select().
354 *
355 * FIXME: the return values from the ioctl aren't very clear if we get
356 * interrupted.
357 */
358 int n = 0;
359 int howmany = ioctl(0, 'ichr', &n);
360 if (howmany >= 0 && n > 0) {
361 have_pending = TRUE;
362 }
363#elif HAVE_SELECT
364 fd_set fdset;
365 struct timeval ktimeout;
366
367 ktimeout.tv_sec =
368 ktimeout.tv_usec = 0;
369
370 FD_ZERO(&fdset);
Steve Kondikae271bc2015-11-15 02:50:53 +0100371 FD_SET(SP_PARM->_checkfd, &fdset);
372 if (select(SP_PARM->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530373 have_pending = TRUE;
374 }
375#endif
376 }
377 if (have_pending) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100378 SP_PARM->_fifohold = 5;
379 NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530380 }
381 return FALSE;
382}
383
384/* put char at lower right corner */
385static void
Steve Kondikae271bc2015-11-15 02:50:53 +0100386PutCharLR(NCURSES_SP_DCLx const ARG_CH_T ch)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530387{
388 if (!auto_right_margin) {
389 /* we can put the char directly */
Steve Kondikae271bc2015-11-15 02:50:53 +0100390 PutAttrChar(NCURSES_SP_ARGx ch);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530391 } else if (enter_am_mode && exit_am_mode) {
392 /* we can suppress automargin */
Steve Kondikae271bc2015-11-15 02:50:53 +0100393 NCURSES_PUTP2("exit_am_mode", exit_am_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530394
Steve Kondikae271bc2015-11-15 02:50:53 +0100395 PutAttrChar(NCURSES_SP_ARGx ch);
396 SP_PARM->_curscol--;
397 position_check(NCURSES_SP_ARGx
398 SP_PARM->_cursrow,
399 SP_PARM->_curscol,
400 "exit_am_mode");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530401
Steve Kondikae271bc2015-11-15 02:50:53 +0100402 NCURSES_PUTP2("enter_am_mode", enter_am_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530403 } else if ((enter_insert_mode && exit_insert_mode)
404 || insert_character || parm_ich) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100405 GoTo(NCURSES_SP_ARGx
406 screen_lines(SP_PARM) - 1,
407 screen_columns(SP_PARM) - 2);
408 PutAttrChar(NCURSES_SP_ARGx ch);
409 GoTo(NCURSES_SP_ARGx
410 screen_lines(SP_PARM) - 1,
411 screen_columns(SP_PARM) - 2);
412 InsStr(NCURSES_SP_ARGx
413 NewScreen(SP_PARM)->_line[screen_lines(SP_PARM) - 1].text +
414 screen_columns(SP_PARM) - 2, 1);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530415 }
416}
417
418/*
419 * Wrap the cursor position, i.e., advance to the beginning of the next line.
420 */
421static void
Steve Kondikae271bc2015-11-15 02:50:53 +0100422wrap_cursor(NCURSES_SP_DCL0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530423{
424 if (eat_newline_glitch) {
425 /*
426 * xenl can manifest two different ways. The vt100 way is that, when
427 * you'd expect the cursor to wrap, it stays hung at the right margin
428 * (on top of the character just emitted) and doesn't wrap until the
429 * *next* graphic char is emitted. The c100 way is to ignore LF
430 * received just after an am wrap.
431 *
432 * An aggressive way to handle this would be to emit CR/LF after the
433 * char and then assume the wrap is done, you're on the first position
434 * of the next line, and the terminal out of its weird state. Here
435 * it's safe to just tell the code that the cursor is in hyperspace and
436 * let the next mvcur() call straighten things out.
437 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100438 SP_PARM->_curscol = -1;
439 SP_PARM->_cursrow = -1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530440 } else if (auto_right_margin) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100441 SP_PARM->_curscol = 0;
442 SP_PARM->_cursrow++;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530443 /*
444 * We've actually moved - but may have to work around problems with
445 * video attributes not working.
446 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100447 if (!move_standout_mode && AttrOf(SCREEN_ATTRS(SP_PARM))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530448 TR(TRACE_CHARPUT, ("turning off (%#lx) %s before wrapping",
Steve Kondikae271bc2015-11-15 02:50:53 +0100449 (unsigned long) AttrOf(SCREEN_ATTRS(SP_PARM)),
450 _traceattr(AttrOf(SCREEN_ATTRS(SP_PARM)))));
451 (void) VIDATTR(SP_PARM, A_NORMAL, 0);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530452 }
453 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +0100454 SP_PARM->_curscol--;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530455 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100456 position_check(NCURSES_SP_ARGx
457 SP_PARM->_cursrow,
458 SP_PARM->_curscol,
459 "wrap_cursor");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530460}
461
462static NCURSES_INLINE void
Steve Kondikae271bc2015-11-15 02:50:53 +0100463PutChar(NCURSES_SP_DCLx const ARG_CH_T ch)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530464/* insert character, handling automargin stuff */
465{
Steve Kondikae271bc2015-11-15 02:50:53 +0100466 if (SP_PARM->_cursrow == screen_lines(SP_PARM) - 1 &&
467 SP_PARM->_curscol == screen_columns(SP_PARM) - 1) {
468 PutCharLR(NCURSES_SP_ARGx ch);
469 } else {
470 PutAttrChar(NCURSES_SP_ARGx ch);
471 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530472
Steve Kondikae271bc2015-11-15 02:50:53 +0100473 if (SP_PARM->_curscol >= screen_columns(SP_PARM))
474 wrap_cursor(NCURSES_SP_ARG);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530475
Steve Kondikae271bc2015-11-15 02:50:53 +0100476 position_check(NCURSES_SP_ARGx
477 SP_PARM->_cursrow,
478 SP_PARM->_curscol, "PutChar");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530479}
480
481/*
482 * Check whether the given character can be output by clearing commands. This
483 * includes test for being a space and not including any 'bad' attributes, such
484 * as A_REVERSE. All attribute flags which don't affect appearance of a space
485 * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
486 */
487static NCURSES_INLINE bool
Steve Kondikae271bc2015-11-15 02:50:53 +0100488can_clear_with(NCURSES_SP_DCLx ARG_CH_T ch)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530489{
Steve Kondikae271bc2015-11-15 02:50:53 +0100490 if (!back_color_erase && SP_PARM->_coloron) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530491#if NCURSES_EXT_FUNCS
492 int pair;
493
Steve Kondikae271bc2015-11-15 02:50:53 +0100494 if (!SP_PARM->_default_color)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530495 return FALSE;
Steve Kondikae271bc2015-11-15 02:50:53 +0100496 if (SP_PARM->_default_fg != C_MASK || SP_PARM->_default_bg != C_MASK)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530497 return FALSE;
498 if ((pair = GetPair(CHDEREF(ch))) != 0) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100499 NCURSES_COLOR_T fg, bg;
500 if (NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
501 (short) pair,
502 &fg, &bg) == ERR
503 || (fg != C_MASK || bg != C_MASK)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530504 return FALSE;
Steve Kondikae271bc2015-11-15 02:50:53 +0100505 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530506 }
507#else
508 if (AttrOfD(ch) & A_COLOR)
509 return FALSE;
510#endif
511 }
512 return (ISBLANK(CHDEREF(ch)) &&
513 (AttrOfD(ch) & ~(NONBLANK_ATTR | A_COLOR)) == BLANK_ATTR);
514}
515
516/*
517 * Issue a given span of characters from an array.
518 * Must be functionally equivalent to:
519 * for (i = 0; i < num; i++)
520 * PutChar(ntext[i]);
521 * but can leave the cursor positioned at the middle of the interval.
522 *
523 * Returns: 0 - cursor is at the end of interval
524 * 1 - cursor is somewhere in the middle
525 *
526 * This code is optimized using ech and rep.
527 */
528static int
Steve Kondikae271bc2015-11-15 02:50:53 +0100529EmitRange(NCURSES_SP_DCLx const NCURSES_CH_T * ntext, int num)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530530{
531 int i;
532
533 TR(TRACE_CHARPUT, ("EmitRange %d:%s", num, _nc_viscbuf(ntext, num)));
534
535 if (erase_chars || repeat_char) {
536 while (num > 0) {
537 int runcount;
538 NCURSES_CH_T ntext0;
539
540 while (num > 1 && !CharEq(ntext[0], ntext[1])) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100541 PutChar(NCURSES_SP_ARGx CHREF(ntext[0]));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530542 ntext++;
543 num--;
544 }
545 ntext0 = ntext[0];
546 if (num == 1) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100547 PutChar(NCURSES_SP_ARGx CHREF(ntext0));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530548 return 0;
549 }
550 runcount = 2;
551
552 while (runcount < num && CharEq(ntext[runcount], ntext0))
553 runcount++;
554
555 /*
556 * The cost expression in the middle isn't exactly right.
557 * _cup_ch_cost is an upper bound on the cost for moving to the
558 * end of the erased area, but not the cost itself (which we
559 * can't compute without emitting the move). This may result
560 * in erase_chars not getting used in some situations for
561 * which it would be marginally advantageous.
562 */
563 if (erase_chars
Steve Kondikae271bc2015-11-15 02:50:53 +0100564 && runcount > SP_PARM->_ech_cost + SP_PARM->_cup_ch_cost
565 && can_clear_with(NCURSES_SP_ARGx CHREF(ntext0))) {
566 UpdateAttrs(SP_PARM, ntext0);
567 NCURSES_PUTP2("erase_chars", TPARM_1(erase_chars, runcount));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530568
569 /*
570 * If this is the last part of the given interval,
571 * don't bother moving cursor, since it can be the
572 * last update on the line.
573 */
574 if (runcount < num) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100575 GoTo(NCURSES_SP_ARGx
576 SP_PARM->_cursrow,
577 SP_PARM->_curscol + runcount);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530578 } else {
579 return 1; /* cursor stays in the middle */
580 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100581 } else if (repeat_char && runcount > SP_PARM->_rep_cost) {
582 bool wrap_possible = (SP_PARM->_curscol + runcount >=
583 screen_columns(SP_PARM));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530584 int rep_count = runcount;
585
586 if (wrap_possible)
587 rep_count--;
588
Steve Kondikae271bc2015-11-15 02:50:53 +0100589 UpdateAttrs(SP_PARM, ntext0);
590 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
591 TPARM_2(repeat_char,
592 CharOf(ntext0),
593 rep_count),
594 rep_count,
595 NCURSES_SP_NAME(_nc_outch));
596 SP_PARM->_curscol += rep_count;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530597
598 if (wrap_possible)
Steve Kondikae271bc2015-11-15 02:50:53 +0100599 PutChar(NCURSES_SP_ARGx CHREF(ntext0));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530600 } else {
601 for (i = 0; i < runcount; i++)
Steve Kondikae271bc2015-11-15 02:50:53 +0100602 PutChar(NCURSES_SP_ARGx CHREF(ntext[i]));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530603 }
604 ntext += runcount;
605 num -= runcount;
606 }
607 return 0;
608 }
609
610 for (i = 0; i < num; i++)
Steve Kondikae271bc2015-11-15 02:50:53 +0100611 PutChar(NCURSES_SP_ARGx CHREF(ntext[i]));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530612 return 0;
613}
614
615/*
616 * Output the line in the given range [first .. last]
617 *
618 * If there's a run of identical characters that's long enough to justify
619 * cursor movement, use that also.
620 *
621 * Returns: same as EmitRange
622 */
623static int
Steve Kondikae271bc2015-11-15 02:50:53 +0100624PutRange(NCURSES_SP_DCLx
625 const NCURSES_CH_T * otext,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530626 const NCURSES_CH_T * ntext,
627 int row,
628 int first, int last)
629{
630 int i, j, same;
Steve Kondikae271bc2015-11-15 02:50:53 +0100631 int rc;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530632
Steve Kondikae271bc2015-11-15 02:50:53 +0100633 TR(TRACE_CHARPUT, ("PutRange(%p, %p, %p, %d, %d, %d)",
634 (void *) SP_PARM,
635 (const void *) otext,
636 (const void *) ntext,
637 row, first, last));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530638
639 if (otext != ntext
Steve Kondikae271bc2015-11-15 02:50:53 +0100640 && (last - first + 1) > SP_PARM->_inline_cost) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530641 for (j = first, same = 0; j <= last; j++) {
642 if (!same && isWidecExt(otext[j]))
643 continue;
644 if (CharEq(otext[j], ntext[j])) {
645 same++;
646 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +0100647 if (same > SP_PARM->_inline_cost) {
648 EmitRange(NCURSES_SP_ARGx ntext + first, j - same - first);
649 GoTo(NCURSES_SP_ARGx row, first = j);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530650 }
651 same = 0;
652 }
653 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100654 i = EmitRange(NCURSES_SP_ARGx ntext + first, j - same - first);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530655 /*
656 * Always return 1 for the next GoTo() after a PutRange() if we found
657 * identical characters at end of interval
658 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100659 rc = (same == 0 ? i : 1);
660 } else {
661 rc = EmitRange(NCURSES_SP_ARGx ntext + first, last - first + 1);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530662 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100663 return rc;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530664}
665
666/* leave unbracketed here so 'indent' works */
667#define MARK_NOCHANGE(win,row) \
668 win->_line[row].firstchar = _NOCHANGE; \
669 win->_line[row].lastchar = _NOCHANGE; \
670 if_USE_SCROLL_HINTS(win->_line[row].oldindex = row)
671
672NCURSES_EXPORT(int)
Steve Kondikae271bc2015-11-15 02:50:53 +0100673TINFO_DOUPDATE(NCURSES_SP_DCL0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530674{
675 int i;
676 int nonempty;
677#if USE_TRACE_TIMES
678 struct tms before, after;
679#endif /* USE_TRACE_TIMES */
680
Steve Kondikae271bc2015-11-15 02:50:53 +0100681 T((T_CALLED("_nc_tinfo:doupdate(%p)"), (void *) SP_PARM));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530682
Steve Kondikae271bc2015-11-15 02:50:53 +0100683 if (SP_PARM == 0)
684 returnCode(ERR);
685
686#if !USE_REENTRANT
687 /*
688 * It is "legal" but unlikely that an application could assign a new
689 * value to one of the standard windows. Check for that possibility
690 * and try to recover.
691 *
692 * We do not allow applications to assign new values in the reentrant
693 * model.
694 */
695#define SyncScreens(internal,exported) \
696 if (internal == 0) internal = exported; \
697 if (internal != exported) exported = internal
698
699 SyncScreens(CurScreen(SP_PARM), curscr);
700 SyncScreens(NewScreen(SP_PARM), newscr);
701 SyncScreens(StdScreen(SP_PARM), stdscr);
702#endif
703
704 if (CurScreen(SP_PARM) == 0
705 || NewScreen(SP_PARM) == 0
706 || StdScreen(SP_PARM) == 0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530707 returnCode(ERR);
708
709#ifdef TRACE
710 if (USE_TRACEF(TRACE_UPDATE)) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100711 if (CurScreen(SP_PARM)->_clear)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530712 _tracef("curscr is clear");
713 else
Steve Kondikae271bc2015-11-15 02:50:53 +0100714 _tracedump("curscr", CurScreen(SP_PARM));
715 _tracedump("newscr", NewScreen(SP_PARM));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530716 _nc_unlock_global(tracef);
717 }
718#endif /* TRACE */
719
720 _nc_signal_handler(FALSE);
721
Steve Kondikae271bc2015-11-15 02:50:53 +0100722 if (SP_PARM->_fifohold)
723 SP_PARM->_fifohold--;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530724
725#if USE_SIZECHANGE
Steve Kondikae271bc2015-11-15 02:50:53 +0100726 if (SP_PARM->_endwin || _nc_handle_sigwinch(SP_PARM)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530727 /*
728 * This is a transparent extension: XSI does not address it,
729 * and applications need not know that ncurses can do it.
730 *
731 * Check if the terminal size has changed while curses was off
732 * (this can happen in an xterm, for example), and resize the
733 * ncurses data structures accordingly.
734 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100735 _nc_update_screensize(SP_PARM);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530736 }
737#endif
738
Steve Kondikae271bc2015-11-15 02:50:53 +0100739 if (SP_PARM->_endwin) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530740
741 T(("coming back from shell mode"));
Steve Kondikae271bc2015-11-15 02:50:53 +0100742 NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530743
Steve Kondikae271bc2015-11-15 02:50:53 +0100744 NCURSES_SP_NAME(_nc_mvcur_resume) (NCURSES_SP_ARG);
745 NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
746 SP_PARM->_mouse_resume(SP_PARM);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530747
Steve Kondikae271bc2015-11-15 02:50:53 +0100748 SP_PARM->_endwin = FALSE;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530749 }
750#if USE_TRACE_TIMES
751 /* zero the metering machinery */
752 RESET_OUTCHARS();
753 (void) times(&before);
754#endif /* USE_TRACE_TIMES */
755
756 /*
757 * This is the support for magic-cookie terminals. The theory: we scan
758 * the virtual screen looking for attribute turnons. Where we find one,
759 * check to make sure it's realizable by seeing if the required number of
760 * un-attributed blanks are present before and after the attributed range;
761 * try to shift the range boundaries over blanks (not changing the screen
762 * display) so this becomes true. If it is, shift the beginning attribute
763 * change appropriately (the end one, if we've gotten this far, is
764 * guaranteed room for its cookie). If not, nuke the added attributes out
765 * of the span.
766 */
767#if USE_XMC_SUPPORT
768 if (magic_cookie_glitch > 0) {
769 int j, k;
770 attr_t rattr = A_NORMAL;
771
Steve Kondikae271bc2015-11-15 02:50:53 +0100772 for (i = 0; i < screen_lines(SP_PARM); i++) {
773 for (j = 0; j < screen_columns(SP_PARM); j++) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530774 bool failed = FALSE;
Steve Kondikae271bc2015-11-15 02:50:53 +0100775 NCURSES_CH_T *thisline = NewScreen(SP_PARM)->_line[i].text;
776 attr_t thisattr = AttrOf(thisline[j]) & SP_PARM->_xmc_triggers;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530777 attr_t turnon = thisattr & ~rattr;
778
779 /* is an attribute turned on here? */
780 if (turnon == 0) {
781 rattr = thisattr;
782 continue;
783 }
784
785 TR(TRACE_ATTRS, ("At (%d, %d): from %s...", i, j, _traceattr(rattr)));
786 TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon)));
787
788 /*
789 * If the attribute change location is a blank with a "safe"
790 * attribute, undo the attribute turnon. This may ensure
791 * there's enough room to set the attribute before the first
792 * non-blank in the run.
793 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100794#define SAFE(scr,a) (!((a) & (scr)->_xmc_triggers))
795 if (ISBLANK(thisline[j]) && SAFE(SP_PARM, turnon)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530796 RemAttr(thisline[j], turnon);
797 continue;
798 }
799
800 /* check that there's enough room at start of span */
801 for (k = 1; k <= magic_cookie_glitch; k++) {
802 if (j - k < 0
803 || !ISBLANK(thisline[j - k])
Steve Kondikae271bc2015-11-15 02:50:53 +0100804 || !SAFE(SP_PARM, AttrOf(thisline[j - k]))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530805 failed = TRUE;
806 TR(TRACE_ATTRS, ("No room at start in %d,%d%s%s",
807 i, j - k,
808 (ISBLANK(thisline[j - k])
809 ? ""
810 : ":nonblank"),
Steve Kondikae271bc2015-11-15 02:50:53 +0100811 (SAFE(SP_PARM, AttrOf(thisline[j - k]))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530812 ? ""
813 : ":unsafe")));
814 break;
815 }
816 }
817 if (!failed) {
818 bool end_onscreen = FALSE;
819 int m, n = j;
820
821 /* find end of span, if it's onscreen */
Steve Kondikae271bc2015-11-15 02:50:53 +0100822 for (m = i; m < screen_lines(SP_PARM); m++) {
823 for (; n < screen_columns(SP_PARM); n++) {
824 attr_t testattr =
825 AttrOf(NewScreen(SP_PARM)->_line[m].text[n]);
826 if ((testattr & SP_PARM->_xmc_triggers) == rattr) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530827 end_onscreen = TRUE;
828 TR(TRACE_ATTRS,
829 ("Range attributed with %s ends at (%d, %d)",
830 _traceattr(turnon), m, n));
831 goto foundit;
832 }
833 }
834 n = 0;
835 }
836 TR(TRACE_ATTRS,
837 ("Range attributed with %s ends offscreen",
838 _traceattr(turnon)));
839 foundit:;
840
841 if (end_onscreen) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100842 NCURSES_CH_T *lastline =
843 NewScreen(SP_PARM)->_line[m].text;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530844
845 /*
846 * If there are safely-attributed blanks at the end of
847 * the range, shorten the range. This will help ensure
848 * that there is enough room at end of span.
849 */
850 while (n >= 0
851 && ISBLANK(lastline[n])
Steve Kondikae271bc2015-11-15 02:50:53 +0100852 && SAFE(SP_PARM, AttrOf(lastline[n]))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530853 RemAttr(lastline[n--], turnon);
854 }
855
856 /* check that there's enough room at end of span */
857 for (k = 1; k <= magic_cookie_glitch; k++) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100858 if (n + k >= screen_columns(SP_PARM)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530859 || !ISBLANK(lastline[n + k])
Steve Kondikae271bc2015-11-15 02:50:53 +0100860 || !SAFE(SP_PARM, AttrOf(lastline[n + k]))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530861 failed = TRUE;
862 TR(TRACE_ATTRS,
863 ("No room at end in %d,%d%s%s",
864 i, j - k,
865 (ISBLANK(lastline[n + k])
866 ? ""
867 : ":nonblank"),
Steve Kondikae271bc2015-11-15 02:50:53 +0100868 (SAFE(SP_PARM, AttrOf(lastline[n + k]))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530869 ? ""
870 : ":unsafe")));
871 break;
872 }
873 }
874 }
875 }
876
877 if (failed) {
878 int p, q = j;
879
880 TR(TRACE_ATTRS,
881 ("Clearing %s beginning at (%d, %d)",
882 _traceattr(turnon), i, j));
883
884 /* turn off new attributes over span */
Steve Kondikae271bc2015-11-15 02:50:53 +0100885 for (p = i; p < screen_lines(SP_PARM); p++) {
886 for (; q < screen_columns(SP_PARM); q++) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530887 attr_t testattr = AttrOf(newscr->_line[p].text[q]);
Steve Kondikae271bc2015-11-15 02:50:53 +0100888 if ((testattr & SP_PARM->_xmc_triggers) == rattr)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530889 goto foundend;
Steve Kondikae271bc2015-11-15 02:50:53 +0100890 RemAttr(NewScreen(SP_PARM)->_line[p].text[q], turnon);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530891 }
892 q = 0;
893 }
894 foundend:;
895 } else {
896 TR(TRACE_ATTRS,
897 ("Cookie space for %s found before (%d, %d)",
898 _traceattr(turnon), i, j));
899
900 /*
901 * Back up the start of range so there's room for cookies
902 * before the first nonblank character.
903 */
904 for (k = 1; k <= magic_cookie_glitch; k++)
905 AddAttr(thisline[j - k], turnon);
906 }
907
908 rattr = thisattr;
909 }
910 }
911
912#ifdef TRACE
913 /* show altered highlights after magic-cookie check */
914 if (USE_TRACEF(TRACE_UPDATE)) {
915 _tracef("After magic-cookie check...");
Steve Kondikae271bc2015-11-15 02:50:53 +0100916 _tracedump("newscr", NewScreen(SP_PARM));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530917 _nc_unlock_global(tracef);
918 }
919#endif /* TRACE */
920 }
921#endif /* USE_XMC_SUPPORT */
922
923 nonempty = 0;
Steve Kondikae271bc2015-11-15 02:50:53 +0100924 if (CurScreen(SP_PARM)->_clear || NewScreen(SP_PARM)->_clear) { /* force refresh ? */
925 ClrUpdate(NCURSES_SP_ARG);
926 CurScreen(SP_PARM)->_clear = FALSE; /* reset flag */
927 NewScreen(SP_PARM)->_clear = FALSE; /* reset flag */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530928 } else {
929 int changedlines = CHECK_INTERVAL;
930
Steve Kondikae271bc2015-11-15 02:50:53 +0100931 if (check_pending(NCURSES_SP_ARG))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530932 goto cleanup;
933
Steve Kondikae271bc2015-11-15 02:50:53 +0100934 nonempty = min(screen_lines(SP_PARM), NewScreen(SP_PARM)->_maxy + 1);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530935
Steve Kondikae271bc2015-11-15 02:50:53 +0100936 if (SP_PARM->_scrolling) {
937 NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_ARG);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530938 }
939
Steve Kondikae271bc2015-11-15 02:50:53 +0100940 nonempty = ClrBottom(NCURSES_SP_ARGx nonempty);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530941
942 TR(TRACE_UPDATE, ("Transforming lines, nonempty %d", nonempty));
943 for (i = 0; i < nonempty; i++) {
944 /*
945 * Here is our line-breakout optimization.
946 */
947 if (changedlines == CHECK_INTERVAL) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100948 if (check_pending(NCURSES_SP_ARG))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530949 goto cleanup;
950 changedlines = 0;
951 }
952
953 /*
954 * newscr->line[i].firstchar is normally set
955 * by wnoutrefresh. curscr->line[i].firstchar
956 * is normally set by _nc_scroll_window in the
957 * vertical-movement optimization code,
958 */
Steve Kondikae271bc2015-11-15 02:50:53 +0100959 if (NewScreen(SP_PARM)->_line[i].firstchar != _NOCHANGE
960 || CurScreen(SP_PARM)->_line[i].firstchar != _NOCHANGE) {
961 TransformLine(NCURSES_SP_ARGx i);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530962 changedlines++;
963 }
964
965 /* mark line changed successfully */
Steve Kondikae271bc2015-11-15 02:50:53 +0100966 if (i <= NewScreen(SP_PARM)->_maxy) {
967 MARK_NOCHANGE(NewScreen(SP_PARM), i);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530968 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100969 if (i <= CurScreen(SP_PARM)->_maxy) {
970 MARK_NOCHANGE(CurScreen(SP_PARM), i);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530971 }
972 }
973 }
974
975 /* put everything back in sync */
Steve Kondikae271bc2015-11-15 02:50:53 +0100976 for (i = nonempty; i <= NewScreen(SP_PARM)->_maxy; i++) {
977 MARK_NOCHANGE(NewScreen(SP_PARM), i);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530978 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100979 for (i = nonempty; i <= CurScreen(SP_PARM)->_maxy; i++) {
980 MARK_NOCHANGE(CurScreen(SP_PARM), i);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530981 }
982
Steve Kondikae271bc2015-11-15 02:50:53 +0100983 if (!NewScreen(SP_PARM)->_leaveok) {
984 CurScreen(SP_PARM)->_curx = NewScreen(SP_PARM)->_curx;
985 CurScreen(SP_PARM)->_cury = NewScreen(SP_PARM)->_cury;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530986
Steve Kondikae271bc2015-11-15 02:50:53 +0100987 GoTo(NCURSES_SP_ARGx CurScreen(SP_PARM)->_cury, CurScreen(SP_PARM)->_curx);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530988 }
989
990 cleanup:
991 /*
992 * We would like to keep the physical screen in normal mode in case we get
993 * other processes writing to the screen. This goal cannot be met for
994 * magic cookies since it interferes with attributes that may propagate
995 * past the current position.
996 */
997#if USE_XMC_SUPPORT
998 if (magic_cookie_glitch != 0)
999#endif
Steve Kondikae271bc2015-11-15 02:50:53 +01001000 UpdateAttrs(SP_PARM, normal);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301001
Steve Kondikae271bc2015-11-15 02:50:53 +01001002 NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
1003 WINDOW_ATTRS(CurScreen(SP_PARM)) = WINDOW_ATTRS(NewScreen(SP_PARM));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301004
1005#if USE_TRACE_TIMES
1006 (void) times(&after);
1007 TR(TRACE_TIMES,
1008 ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time",
1009 _nc_outchars,
1010 (long) (after.tms_stime - before.tms_stime),
1011 (long) (after.tms_utime - before.tms_utime)));
1012#endif /* USE_TRACE_TIMES */
1013
1014 _nc_signal_handler(TRUE);
1015
1016 returnCode(OK);
1017}
1018
Steve Kondikae271bc2015-11-15 02:50:53 +01001019#if NCURSES_SP_FUNCS && !defined(USE_TERM_DRIVER)
1020NCURSES_EXPORT(int)
1021doupdate(void)
1022{
1023 return TINFO_DOUPDATE(CURRENT_SCREEN);
1024}
1025#endif
1026
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301027/*
1028 * ClrBlank(win)
1029 *
1030 * Returns the attributed character that corresponds to the "cleared"
1031 * screen. If the terminal has the back-color-erase feature, this will be
1032 * colored according to the wbkgd() call.
1033 *
1034 * We treat 'curscr' specially because it isn't supposed to be set directly
1035 * in the wbkgd() call. Assume 'stdscr' for this case.
1036 */
1037#define BCE_ATTRS (A_NORMAL|A_COLOR)
Steve Kondikae271bc2015-11-15 02:50:53 +01001038#define BCE_BKGD(sp,win) (((win) == CurScreen(sp) ? StdScreen(sp) : (win))->_nc_bkgd)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301039
1040static NCURSES_INLINE NCURSES_CH_T
Steve Kondikae271bc2015-11-15 02:50:53 +01001041ClrBlank(NCURSES_SP_DCLx WINDOW *win)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301042{
1043 NCURSES_CH_T blank = blankchar;
1044 if (back_color_erase)
Steve Kondikae271bc2015-11-15 02:50:53 +01001045 AddAttr(blank, (AttrOf(BCE_BKGD(SP_PARM, win)) & BCE_ATTRS));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301046 return blank;
1047}
1048
1049/*
1050** ClrUpdate()
1051**
1052** Update by clearing and redrawing the entire screen.
1053**
1054*/
1055
1056static void
Steve Kondikae271bc2015-11-15 02:50:53 +01001057ClrUpdate(NCURSES_SP_DCL0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301058{
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301059 TR(TRACE_UPDATE, (T_CALLED("ClrUpdate")));
Steve Kondikae271bc2015-11-15 02:50:53 +01001060 if (0 != SP_PARM) {
1061 int i;
1062 NCURSES_CH_T blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
1063 int nonempty = min(screen_lines(SP_PARM),
1064 NewScreen(SP_PARM)->_maxy + 1);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301065
Steve Kondikae271bc2015-11-15 02:50:53 +01001066 ClearScreen(NCURSES_SP_ARGx blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301067
Steve Kondikae271bc2015-11-15 02:50:53 +01001068 TR(TRACE_UPDATE, ("updating screen from scratch"));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301069
Steve Kondikae271bc2015-11-15 02:50:53 +01001070 nonempty = ClrBottom(NCURSES_SP_ARGx nonempty);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301071
Steve Kondikae271bc2015-11-15 02:50:53 +01001072 for (i = 0; i < nonempty; i++)
1073 TransformLine(NCURSES_SP_ARGx i);
1074 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301075 TR(TRACE_UPDATE, (T_RETURN("")));
1076}
1077
1078/*
1079** ClrToEOL(blank)
1080**
1081** Clear to end of current line, starting at the cursor position
1082*/
1083
1084static void
Steve Kondikae271bc2015-11-15 02:50:53 +01001085ClrToEOL(NCURSES_SP_DCLx NCURSES_CH_T blank, int needclear)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301086{
1087 int j;
1088
Steve Kondikae271bc2015-11-15 02:50:53 +01001089 if (CurScreen(SP_PARM) != 0
1090 && SP_PARM->_cursrow >= 0) {
1091 for (j = SP_PARM->_curscol; j < screen_columns(SP_PARM); j++) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301092 if (j >= 0) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001093 NCURSES_CH_T *cp =
1094 &(CurScreen(SP_PARM)->_line[SP_PARM->_cursrow].text[j]);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301095
1096 if (!CharEq(*cp, blank)) {
1097 *cp = blank;
1098 needclear = TRUE;
1099 }
1100 }
1101 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301102 }
1103
1104 if (needclear) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001105 UpdateAttrs(SP_PARM, blank);
1106 if (clr_eol && SP_PARM->_el_cost <= (screen_columns(SP_PARM) - SP_PARM->_curscol)) {
1107 NCURSES_PUTP2("clr_eol", clr_eol);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301108 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +01001109 int count = (screen_columns(SP_PARM) - SP_PARM->_curscol);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301110 while (count-- > 0)
Steve Kondikae271bc2015-11-15 02:50:53 +01001111 PutChar(NCURSES_SP_ARGx CHREF(blank));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301112 }
1113 }
1114}
1115
1116/*
1117** ClrToEOS(blank)
1118**
1119** Clear to end of screen, starting at the cursor position
1120*/
1121
1122static void
Steve Kondikae271bc2015-11-15 02:50:53 +01001123ClrToEOS(NCURSES_SP_DCLx NCURSES_CH_T blank)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301124{
1125 int row, col;
1126
Steve Kondikae271bc2015-11-15 02:50:53 +01001127 row = SP_PARM->_cursrow;
1128 col = SP_PARM->_curscol;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301129
Steve Kondikae271bc2015-11-15 02:50:53 +01001130 if (row < 0)
1131 row = 0;
1132 if (col < 0)
1133 col = 0;
1134
1135 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301136 TPUTS_TRACE("clr_eos");
Steve Kondikae271bc2015-11-15 02:50:53 +01001137 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1138 clr_eos,
1139 screen_lines(SP_PARM) - row,
1140 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301141
Steve Kondikae271bc2015-11-15 02:50:53 +01001142 while (col < screen_columns(SP_PARM))
1143 CurScreen(SP_PARM)->_line[row].text[col++] = blank;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301144
Steve Kondikae271bc2015-11-15 02:50:53 +01001145 for (row++; row < screen_lines(SP_PARM); row++) {
1146 for (col = 0; col < screen_columns(SP_PARM); col++)
1147 CurScreen(SP_PARM)->_line[row].text[col] = blank;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301148 }
1149}
1150
1151/*
1152 * ClrBottom(total)
1153 *
1154 * Test if clearing the end of the screen would satisfy part of the
1155 * screen-update. Do this by scanning backwards through the lines in the
1156 * screen, checking if each is blank, and one or more are changed.
1157 */
1158static int
Steve Kondikae271bc2015-11-15 02:50:53 +01001159ClrBottom(NCURSES_SP_DCLx int total)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301160{
1161 int row;
1162 int col;
1163 int top = total;
Steve Kondikae271bc2015-11-15 02:50:53 +01001164 int last = min(screen_columns(SP_PARM), NewScreen(SP_PARM)->_maxx + 1);
1165 NCURSES_CH_T blank = NewScreen(SP_PARM)->_line[total - 1].text[last - 1];
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301166 bool ok;
1167
Steve Kondikae271bc2015-11-15 02:50:53 +01001168 if (clr_eos && can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301169
1170 for (row = total - 1; row >= 0; row--) {
1171 for (col = 0, ok = TRUE; ok && col < last; col++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001172 ok = (CharEq(NewScreen(SP_PARM)->_line[row].text[col], blank));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301173 }
1174 if (!ok)
1175 break;
1176
1177 for (col = 0; ok && col < last; col++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001178 ok = (CharEq(CurScreen(SP_PARM)->_line[row].text[col], blank));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301179 }
1180 if (!ok)
1181 top = row;
1182 }
1183
1184 /* don't use clr_eos for just one line if clr_eol available */
1185 if (top < total) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001186 GoTo(NCURSES_SP_ARGx top, 0);
1187 ClrToEOS(NCURSES_SP_ARGx blank);
1188 if (SP_PARM->oldhash && SP_PARM->newhash) {
1189 for (row = top; row < screen_lines(SP_PARM); row++)
1190 SP_PARM->oldhash[row] = SP_PARM->newhash[row];
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301191 }
1192 }
1193 }
1194 return top;
1195}
1196
1197#if USE_XMC_SUPPORT
1198#if USE_WIDEC_SUPPORT
Steve Kondikae271bc2015-11-15 02:50:53 +01001199#define check_xmc_transition(sp, a, b) \
1200 ((((a)->attr ^ (b)->attr) & ~((a)->attr) & (sp)->_xmc_triggers) != 0)
1201#define xmc_turn_on(sp,a,b) check_xmc_transition(sp,&(a), &(b))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301202#else
Steve Kondikae271bc2015-11-15 02:50:53 +01001203#define xmc_turn_on(sp,a,b) ((((a)^(b)) & ~(a) & (sp)->_xmc_triggers) != 0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301204#endif
1205
Steve Kondikae271bc2015-11-15 02:50:53 +01001206#define xmc_new(sp,r,c) NewScreen(sp)->_line[r].text[c]
1207#define xmc_turn_off(sp,a,b) xmc_turn_on(sp,b,a)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301208#endif /* USE_XMC_SUPPORT */
1209
1210/*
1211** TransformLine(lineno)
1212**
1213** Transform the given line in curscr to the one in newscr, using
Steve Kondikae271bc2015-11-15 02:50:53 +01001214** Insert/Delete Character if idcok && has_ic().
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301215**
1216** firstChar = position of first different character in line
1217** oLastChar = position of last different character in old line
1218** nLastChar = position of last different character in new line
1219**
1220** move to firstChar
1221** overwrite chars up to min(oLastChar, nLastChar)
1222** if oLastChar < nLastChar
1223** insert newLine[oLastChar+1..nLastChar]
1224** else
1225** delete oLastChar - nLastChar spaces
1226*/
1227
1228static void
Steve Kondikae271bc2015-11-15 02:50:53 +01001229TransformLine(NCURSES_SP_DCLx int const lineno)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301230{
1231 int firstChar, oLastChar, nLastChar;
Steve Kondikae271bc2015-11-15 02:50:53 +01001232 NCURSES_CH_T *newLine = NewScreen(SP_PARM)->_line[lineno].text;
1233 NCURSES_CH_T *oldLine = CurScreen(SP_PARM)->_line[lineno].text;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301234 int n;
1235 bool attrchanged = FALSE;
1236
Steve Kondikae271bc2015-11-15 02:50:53 +01001237 TR(TRACE_UPDATE, (T_CALLED("TransformLine(%p, %d)"), (void *) SP_PARM, lineno));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301238
1239 /* copy new hash value to old one */
Steve Kondikae271bc2015-11-15 02:50:53 +01001240 if (SP_PARM->oldhash && SP_PARM->newhash)
1241 SP_PARM->oldhash[lineno] = SP_PARM->newhash[lineno];
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301242
1243 /*
1244 * If we have colors, there is the possibility of having two color pairs
1245 * that display as the same colors. For instance, Lynx does this. Check
1246 * for this case, and update the old line with the new line's colors when
1247 * they are equivalent.
1248 */
Steve Kondikae271bc2015-11-15 02:50:53 +01001249 if (SP_PARM->_coloron) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301250 int oldPair;
1251 int newPair;
1252
Steve Kondikae271bc2015-11-15 02:50:53 +01001253 for (n = 0; n < screen_columns(SP_PARM); n++) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301254 if (!CharEq(newLine[n], oldLine[n])) {
1255 oldPair = GetPair(oldLine[n]);
1256 newPair = GetPair(newLine[n]);
1257 if (oldPair != newPair
1258 && unColor(oldLine[n]) == unColor(newLine[n])) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001259 if (oldPair < SP_PARM->_pair_limit
1260 && newPair < SP_PARM->_pair_limit
1261 && (SP_PARM->_color_pairs[oldPair] ==
1262 SP_PARM->_color_pairs[newPair])) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301263 SetPair(oldLine[n], GetPair(newLine[n]));
1264 }
1265 }
1266 }
1267 }
1268 }
1269
1270 if (ceol_standout_glitch && clr_eol) {
1271 firstChar = 0;
Steve Kondikae271bc2015-11-15 02:50:53 +01001272 while (firstChar < screen_columns(SP_PARM)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301273 if (!SameAttrOf(newLine[firstChar], oldLine[firstChar])) {
1274 attrchanged = TRUE;
1275 break;
1276 }
1277 firstChar++;
1278 }
1279 }
1280
1281 firstChar = 0;
1282
1283 if (attrchanged) { /* we may have to disregard the whole line */
Steve Kondikae271bc2015-11-15 02:50:53 +01001284 GoTo(NCURSES_SP_ARGx lineno, firstChar);
1285 ClrToEOL(NCURSES_SP_ARGx
1286 ClrBlank(NCURSES_SP_ARGx
1287 CurScreen(SP_PARM)), FALSE);
1288 PutRange(NCURSES_SP_ARGx
1289 oldLine, newLine, lineno, 0,
1290 screen_columns(SP_PARM) - 1);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301291#if USE_XMC_SUPPORT
1292
1293 /*
1294 * This is a very simple loop to paint characters which may have the
1295 * magic cookie glitch embedded. It doesn't know much about video
1296 * attributes which are continued from one line to the next. It
1297 * assumes that we have filtered out requests for attribute changes
1298 * that do not get mapped to blank positions.
1299 *
1300 * FIXME: we are not keeping track of where we put the cookies, so this
1301 * will work properly only once, since we may overwrite a cookie in a
1302 * following operation.
1303 */
1304 } else if (magic_cookie_glitch > 0) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001305 GoTo(NCURSES_SP_ARGx lineno, firstChar);
1306 for (n = 0; n < screen_columns(SP_PARM); n++) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301307 int m = n + magic_cookie_glitch;
1308
1309 /* check for turn-on:
1310 * If we are writing an attributed blank, where the
1311 * previous cell is not attributed.
1312 */
1313 if (ISBLANK(newLine[n])
1314 && ((n > 0
Steve Kondikae271bc2015-11-15 02:50:53 +01001315 && xmc_turn_on(SP_PARM, newLine[n - 1], newLine[n]))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301316 || (n == 0
1317 && lineno > 0
Steve Kondikae271bc2015-11-15 02:50:53 +01001318 && xmc_turn_on(SP_PARM,
1319 xmc_new(SP_PARM, lineno - 1,
1320 screen_columns(SP_PARM) - 1),
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301321 newLine[n])))) {
1322 n = m;
1323 }
1324
Steve Kondikae271bc2015-11-15 02:50:53 +01001325 PutChar(NCURSES_SP_ARGx CHREF(newLine[n]));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301326
1327 /* check for turn-off:
1328 * If we are writing an attributed non-blank, where the
1329 * next cell is blank, and not attributed.
1330 */
1331 if (!ISBLANK(newLine[n])
Steve Kondikae271bc2015-11-15 02:50:53 +01001332 && ((n + 1 < screen_columns(SP_PARM)
1333 && xmc_turn_off(SP_PARM, newLine[n], newLine[n + 1]))
1334 || (n + 1 >= screen_columns(SP_PARM)
1335 && lineno + 1 < screen_lines(SP_PARM)
1336 && xmc_turn_off(SP_PARM,
1337 newLine[n],
1338 xmc_new(SP_PARM, lineno + 1, 0))))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301339 n = m;
1340 }
1341
1342 }
1343#endif
1344 } else {
1345 NCURSES_CH_T blank;
1346
1347 /* it may be cheap to clear leading whitespace with clr_bol */
1348 blank = newLine[0];
Steve Kondikae271bc2015-11-15 02:50:53 +01001349 if (clr_bol && can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301350 int oFirstChar, nFirstChar;
1351
Steve Kondikae271bc2015-11-15 02:50:53 +01001352 for (oFirstChar = 0;
1353 oFirstChar < screen_columns(SP_PARM);
1354 oFirstChar++)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301355 if (!CharEq(oldLine[oFirstChar], blank))
1356 break;
Steve Kondikae271bc2015-11-15 02:50:53 +01001357 for (nFirstChar = 0;
1358 nFirstChar < screen_columns(SP_PARM);
1359 nFirstChar++)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301360 if (!CharEq(newLine[nFirstChar], blank))
1361 break;
1362
1363 if (nFirstChar == oFirstChar) {
1364 firstChar = nFirstChar;
1365 /* find the first differing character */
Steve Kondikae271bc2015-11-15 02:50:53 +01001366 while (firstChar < screen_columns(SP_PARM)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301367 && CharEq(newLine[firstChar], oldLine[firstChar]))
1368 firstChar++;
1369 } else if (oFirstChar > nFirstChar) {
1370 firstChar = nFirstChar;
1371 } else { /* oFirstChar < nFirstChar */
1372 firstChar = oFirstChar;
Steve Kondikae271bc2015-11-15 02:50:53 +01001373 if (SP_PARM->_el1_cost < nFirstChar - oFirstChar) {
1374 if (nFirstChar >= screen_columns(SP_PARM)
1375 && SP_PARM->_el_cost <= SP_PARM->_el1_cost) {
1376 GoTo(NCURSES_SP_ARGx lineno, 0);
1377 UpdateAttrs(SP_PARM, blank);
1378 NCURSES_PUTP2("clr_eol", clr_eol);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301379 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +01001380 GoTo(NCURSES_SP_ARGx lineno, nFirstChar - 1);
1381 UpdateAttrs(SP_PARM, blank);
1382 NCURSES_PUTP2("clr_bol", clr_bol);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301383 }
1384
1385 while (firstChar < nFirstChar)
1386 oldLine[firstChar++] = blank;
1387 }
1388 }
1389 } else {
1390 /* find the first differing character */
Steve Kondikae271bc2015-11-15 02:50:53 +01001391 while (firstChar < screen_columns(SP_PARM)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301392 && CharEq(newLine[firstChar], oldLine[firstChar]))
1393 firstChar++;
1394 }
1395 /* if there wasn't one, we're done */
Steve Kondikae271bc2015-11-15 02:50:53 +01001396 if (firstChar >= screen_columns(SP_PARM)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301397 TR(TRACE_UPDATE, (T_RETURN("")));
1398 return;
1399 }
1400
Steve Kondikae271bc2015-11-15 02:50:53 +01001401 blank = newLine[screen_columns(SP_PARM) - 1];
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301402
Steve Kondikae271bc2015-11-15 02:50:53 +01001403 if (!can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301404 /* find the last differing character */
Steve Kondikae271bc2015-11-15 02:50:53 +01001405 nLastChar = screen_columns(SP_PARM) - 1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301406
1407 while (nLastChar > firstChar
1408 && CharEq(newLine[nLastChar], oldLine[nLastChar]))
1409 nLastChar--;
1410
1411 if (nLastChar >= firstChar) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001412 GoTo(NCURSES_SP_ARGx lineno, firstChar);
1413 PutRange(NCURSES_SP_ARGx
1414 oldLine,
1415 newLine,
1416 lineno,
1417 firstChar,
1418 nLastChar);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301419 memcpy(oldLine + firstChar,
1420 newLine + firstChar,
Steve Kondikae271bc2015-11-15 02:50:53 +01001421 (unsigned) (nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301422 }
1423 TR(TRACE_UPDATE, (T_RETURN("")));
1424 return;
1425 }
1426
1427 /* find last non-blank character on old line */
Steve Kondikae271bc2015-11-15 02:50:53 +01001428 oLastChar = screen_columns(SP_PARM) - 1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301429 while (oLastChar > firstChar && CharEq(oldLine[oLastChar], blank))
1430 oLastChar--;
1431
1432 /* find last non-blank character on new line */
Steve Kondikae271bc2015-11-15 02:50:53 +01001433 nLastChar = screen_columns(SP_PARM) - 1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301434 while (nLastChar > firstChar && CharEq(newLine[nLastChar], blank))
1435 nLastChar--;
1436
1437 if ((nLastChar == firstChar)
Steve Kondikae271bc2015-11-15 02:50:53 +01001438 && (SP_PARM->_el_cost < (oLastChar - nLastChar))) {
1439 GoTo(NCURSES_SP_ARGx lineno, firstChar);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301440 if (!CharEq(newLine[firstChar], blank))
Steve Kondikae271bc2015-11-15 02:50:53 +01001441 PutChar(NCURSES_SP_ARGx CHREF(newLine[firstChar]));
1442 ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301443 } else if ((nLastChar != oLastChar)
1444 && (!CharEq(newLine[nLastChar], oldLine[oLastChar])
Steve Kondikae271bc2015-11-15 02:50:53 +01001445 || !(SP_PARM->_nc_sp_idcok
1446 && NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG)))) {
1447 GoTo(NCURSES_SP_ARGx lineno, firstChar);
1448 if ((oLastChar - nLastChar) > SP_PARM->_el_cost) {
1449 if (PutRange(NCURSES_SP_ARGx
1450 oldLine,
1451 newLine,
1452 lineno,
1453 firstChar,
1454 nLastChar)) {
1455 GoTo(NCURSES_SP_ARGx lineno, nLastChar + 1);
1456 }
1457 ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301458 } else {
1459 n = max(nLastChar, oLastChar);
Steve Kondikae271bc2015-11-15 02:50:53 +01001460 PutRange(NCURSES_SP_ARGx
1461 oldLine,
1462 newLine,
1463 lineno,
1464 firstChar,
1465 n);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301466 }
1467 } else {
1468 int nLastNonblank = nLastChar;
1469 int oLastNonblank = oLastChar;
1470
1471 /* find the last characters that really differ */
1472 /* can be -1 if no characters differ */
1473 while (CharEq(newLine[nLastChar], oldLine[oLastChar])) {
1474 /* don't split a wide char */
1475 if (isWidecExt(newLine[nLastChar]) &&
1476 !CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1]))
1477 break;
1478 nLastChar--;
1479 oLastChar--;
1480 if (nLastChar == -1 || oLastChar == -1)
1481 break;
1482 }
1483
1484 n = min(oLastChar, nLastChar);
1485 if (n >= firstChar) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001486 GoTo(NCURSES_SP_ARGx lineno, firstChar);
1487 PutRange(NCURSES_SP_ARGx
1488 oldLine,
1489 newLine,
1490 lineno,
1491 firstChar,
1492 n);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301493 }
1494
1495 if (oLastChar < nLastChar) {
1496 int m = max(nLastNonblank, oLastNonblank);
1497#if USE_WIDEC_SUPPORT
Steve Kondikae271bc2015-11-15 02:50:53 +01001498 if (n) {
1499 while (isWidecExt(newLine[n + 1]) && n) {
1500 --n;
1501 --oLastChar; /* increase cost */
1502 }
1503 } else if (n >= firstChar &&
1504 isWidecBase(newLine[n])) {
1505 while (isWidecExt(newLine[n + 1])) {
1506 ++n;
1507 ++oLastChar; /* decrease cost */
1508 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301509 }
1510#endif
Steve Kondikae271bc2015-11-15 02:50:53 +01001511 GoTo(NCURSES_SP_ARGx lineno, n + 1);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301512 if ((nLastChar < nLastNonblank)
Steve Kondikae271bc2015-11-15 02:50:53 +01001513 || InsCharCost(SP_PARM, nLastChar - oLastChar) > (m - n)) {
1514 PutRange(NCURSES_SP_ARGx
1515 oldLine,
1516 newLine,
1517 lineno,
1518 n + 1,
1519 m);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301520 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +01001521 InsStr(NCURSES_SP_ARGx &newLine[n + 1], nLastChar - oLastChar);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301522 }
1523 } else if (oLastChar > nLastChar) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001524 GoTo(NCURSES_SP_ARGx lineno, n + 1);
1525 if (DelCharCost(SP_PARM, oLastChar - nLastChar)
1526 > SP_PARM->_el_cost + nLastNonblank - (n + 1)) {
1527 if (PutRange(NCURSES_SP_ARGx oldLine, newLine, lineno,
1528 n + 1, nLastNonblank)) {
1529 GoTo(NCURSES_SP_ARGx lineno, nLastNonblank + 1);
1530 }
1531 ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301532 } else {
1533 /*
1534 * The delete-char sequence will
1535 * effectively shift in blanks from the
1536 * right margin of the screen. Ensure
1537 * that they are the right color by
1538 * setting the video attributes from
1539 * the last character on the row.
1540 */
Steve Kondikae271bc2015-11-15 02:50:53 +01001541 UpdateAttrs(SP_PARM, blank);
1542 DelChar(NCURSES_SP_ARGx oLastChar - nLastChar);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301543 }
1544 }
1545 }
1546 }
1547
1548 /* update the code's internal representation */
Steve Kondikae271bc2015-11-15 02:50:53 +01001549 if (screen_columns(SP_PARM) > firstChar)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301550 memcpy(oldLine + firstChar,
1551 newLine + firstChar,
Steve Kondikae271bc2015-11-15 02:50:53 +01001552 (unsigned) (screen_columns(SP_PARM) - firstChar) * sizeof(NCURSES_CH_T));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301553 TR(TRACE_UPDATE, (T_RETURN("")));
1554 return;
1555}
1556
1557/*
1558** ClearScreen(blank)
1559**
1560** Clear the physical screen and put cursor at home
1561**
1562*/
1563
1564static void
Steve Kondikae271bc2015-11-15 02:50:53 +01001565ClearScreen(NCURSES_SP_DCLx NCURSES_CH_T blank)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301566{
1567 int i, j;
1568 bool fast_clear = (clear_screen || clr_eos || clr_eol);
1569
1570 TR(TRACE_UPDATE, ("ClearScreen() called"));
1571
1572#if NCURSES_EXT_FUNCS
Steve Kondikae271bc2015-11-15 02:50:53 +01001573 if (SP_PARM->_coloron
1574 && !SP_PARM->_default_color) {
1575 NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx
1576 (short) GET_SCREEN_PAIR(SP_PARM),
1577 0,
1578 FALSE,
1579 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301580 if (!back_color_erase) {
1581 fast_clear = FALSE;
1582 }
1583 }
1584#endif
1585
1586 if (fast_clear) {
1587 if (clear_screen) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001588 UpdateAttrs(SP_PARM, blank);
1589 NCURSES_PUTP2("clear_screen", clear_screen);
1590 SP_PARM->_cursrow = SP_PARM->_curscol = 0;
1591 position_check(NCURSES_SP_ARGx
1592 SP_PARM->_cursrow,
1593 SP_PARM->_curscol,
1594 "ClearScreen");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301595 } else if (clr_eos) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001596 SP_PARM->_cursrow = SP_PARM->_curscol = -1;
1597 GoTo(NCURSES_SP_ARGx 0, 0);
1598 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301599 TPUTS_TRACE("clr_eos");
Steve Kondikae271bc2015-11-15 02:50:53 +01001600 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1601 clr_eos,
1602 screen_lines(SP_PARM),
1603 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301604 } else if (clr_eol) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001605 SP_PARM->_cursrow = SP_PARM->_curscol = -1;
1606 UpdateAttrs(SP_PARM, blank);
1607 for (i = 0; i < screen_lines(SP_PARM); i++) {
1608 GoTo(NCURSES_SP_ARGx i, 0);
1609 NCURSES_PUTP2("clr_eol", clr_eol);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301610 }
Steve Kondikae271bc2015-11-15 02:50:53 +01001611 GoTo(NCURSES_SP_ARGx 0, 0);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301612 }
1613 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +01001614 UpdateAttrs(SP_PARM, blank);
1615 for (i = 0; i < screen_lines(SP_PARM); i++) {
1616 GoTo(NCURSES_SP_ARGx i, 0);
1617 for (j = 0; j < screen_columns(SP_PARM); j++)
1618 PutChar(NCURSES_SP_ARGx CHREF(blank));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301619 }
Steve Kondikae271bc2015-11-15 02:50:53 +01001620 GoTo(NCURSES_SP_ARGx 0, 0);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301621 }
1622
Steve Kondikae271bc2015-11-15 02:50:53 +01001623 for (i = 0; i < screen_lines(SP_PARM); i++) {
1624 for (j = 0; j < screen_columns(SP_PARM); j++)
1625 CurScreen(SP_PARM)->_line[i].text[j] = blank;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301626 }
1627
1628 TR(TRACE_UPDATE, ("screen cleared"));
1629}
1630
1631/*
1632** InsStr(line, count)
1633**
1634** Insert the count characters pointed to by line.
1635**
1636*/
1637
1638static void
Steve Kondikae271bc2015-11-15 02:50:53 +01001639InsStr(NCURSES_SP_DCLx NCURSES_CH_T * line, int count)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301640{
Steve Kondikae271bc2015-11-15 02:50:53 +01001641 TR(TRACE_UPDATE, ("InsStr(%p, %p,%d) called",
1642 (void *) SP_PARM,
1643 (void *) line, count));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301644
1645 /* Prefer parm_ich as it has the smallest cost - no need to shift
1646 * the whole line on each character. */
1647 /* The order must match that of InsCharCost. */
1648 if (parm_ich) {
1649 TPUTS_TRACE("parm_ich");
Steve Kondikae271bc2015-11-15 02:50:53 +01001650 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1651 TPARM_1(parm_ich, count),
1652 count,
1653 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301654 while (count) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001655 PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301656 line++;
1657 count--;
1658 }
1659 } else if (enter_insert_mode && exit_insert_mode) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001660 NCURSES_PUTP2("enter_insert_mode", enter_insert_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301661 while (count) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001662 PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301663 if (insert_padding) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001664 NCURSES_PUTP2("insert_padding", insert_padding);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301665 }
1666 line++;
1667 count--;
1668 }
Steve Kondikae271bc2015-11-15 02:50:53 +01001669 NCURSES_PUTP2("exit_insert_mode", exit_insert_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301670 } else {
1671 while (count) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001672 NCURSES_PUTP2("insert_character", insert_character);
1673 PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301674 if (insert_padding) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001675 NCURSES_PUTP2("insert_padding", insert_padding);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301676 }
1677 line++;
1678 count--;
1679 }
1680 }
Steve Kondikae271bc2015-11-15 02:50:53 +01001681 position_check(NCURSES_SP_ARGx
1682 SP_PARM->_cursrow,
1683 SP_PARM->_curscol, "InsStr");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301684}
1685
1686/*
1687** DelChar(count)
1688**
1689** Delete count characters at current position
1690**
1691*/
1692
1693static void
Steve Kondikae271bc2015-11-15 02:50:53 +01001694DelChar(NCURSES_SP_DCLx int count)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301695{
1696 int n;
1697
Steve Kondikae271bc2015-11-15 02:50:53 +01001698 TR(TRACE_UPDATE, ("DelChar(%p, %d) called, position = (%ld,%ld)",
1699 (void *) SP_PARM, count,
1700 (long) NewScreen(SP_PARM)->_cury,
1701 (long) NewScreen(SP_PARM)->_curx));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301702
1703 if (parm_dch) {
1704 TPUTS_TRACE("parm_dch");
Steve Kondikae271bc2015-11-15 02:50:53 +01001705 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1706 TPARM_1(parm_dch, count),
1707 count,
1708 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301709 } else {
1710 for (n = 0; n < count; n++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001711 NCURSES_PUTP2("delete_character", delete_character);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301712 }
1713 }
1714}
1715
1716/*
1717 * Physical-scrolling support
1718 *
1719 * This code was adapted from Keith Bostic's hardware scrolling
1720 * support for 4.4BSD curses. I (esr) translated it to use terminfo
1721 * capabilities, narrowed the call interface slightly, and cleaned
1722 * up some convoluted tests. I also added support for the memory_above
1723 * memory_below, and non_dest_scroll_region capabilities.
1724 *
1725 * For this code to work, we must have either
1726 * change_scroll_region and scroll forward/reverse commands, or
1727 * insert and delete line capabilities.
1728 * When the scrolling region has been set, the cursor has to
1729 * be at the last line of the region to make the scroll up
1730 * happen, or on the first line of region to scroll down.
1731 *
1732 * This code makes one aesthetic decision in the opposite way from
1733 * BSD curses. BSD curses preferred pairs of il/dl operations
1734 * over scrolls, allegedly because il/dl looked faster. We, on
1735 * the other hand, prefer scrolls because (a) they're just as fast
1736 * on many terminals and (b) using them avoids bouncing an
1737 * unchanged bottom section of the screen up and down, which is
1738 * visually nasty.
1739 *
1740 * (lav): added more cases, used dl/il when bot==maxy and in csr case.
1741 *
1742 * I used assumption that capabilities il/il1/dl/dl1 work inside
1743 * changed scroll region not shifting screen contents outside of it.
1744 * If there are any terminals behaving different way, it would be
1745 * necessary to add some conditions to scroll_csr_forward/backward.
1746 */
1747
1748/* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */
1749static int
Steve Kondikae271bc2015-11-15 02:50:53 +01001750scroll_csr_forward(NCURSES_SP_DCLx
1751 int n,
1752 int top,
1753 int bot,
1754 int miny,
1755 int maxy,
1756 NCURSES_CH_T blank)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301757{
1758 int i;
1759
1760 if (n == 1 && scroll_forward && top == miny && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001761 GoTo(NCURSES_SP_ARGx bot, 0);
1762 UpdateAttrs(SP_PARM, blank);
1763 NCURSES_PUTP2("scroll_forward", scroll_forward);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301764 } else if (n == 1 && delete_line && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001765 GoTo(NCURSES_SP_ARGx top, 0);
1766 UpdateAttrs(SP_PARM, blank);
1767 NCURSES_PUTP2("delete_line", delete_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301768 } else if (parm_index && top == miny && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001769 GoTo(NCURSES_SP_ARGx bot, 0);
1770 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301771 TPUTS_TRACE("parm_index");
Steve Kondikae271bc2015-11-15 02:50:53 +01001772 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1773 TPARM_2(parm_index, n, 0),
1774 n,
1775 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301776 } else if (parm_delete_line && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001777 GoTo(NCURSES_SP_ARGx top, 0);
1778 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301779 TPUTS_TRACE("parm_delete_line");
Steve Kondikae271bc2015-11-15 02:50:53 +01001780 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1781 TPARM_2(parm_delete_line, n, 0),
1782 n,
1783 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301784 } else if (scroll_forward && top == miny && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001785 GoTo(NCURSES_SP_ARGx bot, 0);
1786 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301787 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001788 NCURSES_PUTP2("scroll_forward", scroll_forward);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301789 }
1790 } else if (delete_line && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001791 GoTo(NCURSES_SP_ARGx top, 0);
1792 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301793 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001794 NCURSES_PUTP2("delete_line", delete_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301795 }
1796 } else
1797 return ERR;
1798
1799#if NCURSES_EXT_FUNCS
Steve Kondikae271bc2015-11-15 02:50:53 +01001800 if (FILL_BCE(SP_PARM)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301801 int j;
1802 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001803 GoTo(NCURSES_SP_ARGx bot - i, 0);
1804 for (j = 0; j < screen_columns(SP_PARM); j++)
1805 PutChar(NCURSES_SP_ARGx CHREF(blank));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301806 }
1807 }
1808#endif
1809 return OK;
1810}
1811
1812/* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */
1813/* n > 0 */
1814static int
Steve Kondikae271bc2015-11-15 02:50:53 +01001815scroll_csr_backward(NCURSES_SP_DCLx
1816 int n,
1817 int top,
1818 int bot,
1819 int miny,
1820 int maxy,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301821 NCURSES_CH_T blank)
1822{
1823 int i;
1824
1825 if (n == 1 && scroll_reverse && top == miny && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001826 GoTo(NCURSES_SP_ARGx top, 0);
1827 UpdateAttrs(SP_PARM, blank);
1828 NCURSES_PUTP2("scroll_reverse", scroll_reverse);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301829 } else if (n == 1 && insert_line && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001830 GoTo(NCURSES_SP_ARGx top, 0);
1831 UpdateAttrs(SP_PARM, blank);
1832 NCURSES_PUTP2("insert_line", insert_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301833 } else if (parm_rindex && top == miny && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001834 GoTo(NCURSES_SP_ARGx top, 0);
1835 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301836 TPUTS_TRACE("parm_rindex");
Steve Kondikae271bc2015-11-15 02:50:53 +01001837 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1838 TPARM_2(parm_rindex, n, 0),
1839 n,
1840 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301841 } else if (parm_insert_line && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001842 GoTo(NCURSES_SP_ARGx top, 0);
1843 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301844 TPUTS_TRACE("parm_insert_line");
Steve Kondikae271bc2015-11-15 02:50:53 +01001845 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1846 TPARM_2(parm_insert_line, n, 0),
1847 n,
1848 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301849 } else if (scroll_reverse && top == miny && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001850 GoTo(NCURSES_SP_ARGx top, 0);
1851 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301852 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001853 NCURSES_PUTP2("scroll_reverse", scroll_reverse);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301854 }
1855 } else if (insert_line && bot == maxy) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001856 GoTo(NCURSES_SP_ARGx top, 0);
1857 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301858 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001859 NCURSES_PUTP2("insert_line", insert_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301860 }
1861 } else
1862 return ERR;
1863
1864#if NCURSES_EXT_FUNCS
Steve Kondikae271bc2015-11-15 02:50:53 +01001865 if (FILL_BCE(SP_PARM)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301866 int j;
1867 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001868 GoTo(NCURSES_SP_ARGx top + i, 0);
1869 for (j = 0; j < screen_columns(SP_PARM); j++)
1870 PutChar(NCURSES_SP_ARGx CHREF(blank));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301871 }
1872 }
1873#endif
1874 return OK;
1875}
1876
1877/* scroll by using delete_line at del and insert_line at ins */
1878/* n > 0 */
1879static int
Steve Kondikae271bc2015-11-15 02:50:53 +01001880scroll_idl(NCURSES_SP_DCLx int n, int del, int ins, NCURSES_CH_T blank)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301881{
1882 int i;
1883
1884 if (!((parm_delete_line || delete_line) && (parm_insert_line || insert_line)))
1885 return ERR;
1886
Steve Kondikae271bc2015-11-15 02:50:53 +01001887 GoTo(NCURSES_SP_ARGx del, 0);
1888 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301889 if (n == 1 && delete_line) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001890 NCURSES_PUTP2("delete_line", delete_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301891 } else if (parm_delete_line) {
1892 TPUTS_TRACE("parm_delete_line");
Steve Kondikae271bc2015-11-15 02:50:53 +01001893 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1894 TPARM_2(parm_delete_line, n, 0),
1895 n,
1896 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301897 } else { /* if (delete_line) */
1898 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001899 NCURSES_PUTP2("delete_line", delete_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301900 }
1901 }
1902
Steve Kondikae271bc2015-11-15 02:50:53 +01001903 GoTo(NCURSES_SP_ARGx ins, 0);
1904 UpdateAttrs(SP_PARM, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301905 if (n == 1 && insert_line) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001906 NCURSES_PUTP2("insert_line", insert_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301907 } else if (parm_insert_line) {
1908 TPUTS_TRACE("parm_insert_line");
Steve Kondikae271bc2015-11-15 02:50:53 +01001909 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
1910 TPARM_2(parm_insert_line, n, 0),
1911 n,
1912 NCURSES_SP_NAME(_nc_outch));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301913 } else { /* if (insert_line) */
1914 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001915 NCURSES_PUTP2("insert_line", insert_line);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301916 }
1917 }
1918
1919 return OK;
1920}
1921
1922/*
1923 * Note: some terminals require the cursor to be within the scrolling margins
1924 * before setting them. Generally, the cursor must be at the appropriate end
1925 * of the scrolling margins when issuing an indexing operation (it is not
1926 * apparent whether it must also be at the left margin; we do this just to be
1927 * safe). To make the related cursor movement a little faster, we use the
1928 * save/restore cursor capabilities if the terminal has them.
1929 */
1930NCURSES_EXPORT(int)
Steve Kondikae271bc2015-11-15 02:50:53 +01001931NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_DCLx
1932 int n,
1933 int top,
1934 int bot,
1935 int maxy)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301936/* scroll region from top to bot by n lines */
1937{
Steve Kondikae271bc2015-11-15 02:50:53 +01001938 NCURSES_CH_T blank;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301939 int i;
1940 bool cursor_saved = FALSE;
1941 int res;
1942
Steve Kondikae271bc2015-11-15 02:50:53 +01001943 TR(TRACE_MOVE, ("_nc_scrolln(%p, %d, %d, %d, %d)",
1944 (void *) SP_PARM, n, top, bot, maxy));
1945
1946 if (!IsValidScreen(SP_PARM))
1947 return (ERR);
1948
1949 blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301950
1951#if USE_XMC_SUPPORT
1952 /*
1953 * If we scroll, we might remove a cookie.
1954 */
1955 if (magic_cookie_glitch > 0) {
1956 return (ERR);
1957 }
1958#endif
1959
1960 if (n > 0) { /* scroll up (forward) */
1961 /*
1962 * Explicitly clear if stuff pushed off top of region might
1963 * be saved by the terminal.
1964 */
Steve Kondikae271bc2015-11-15 02:50:53 +01001965 res = scroll_csr_forward(NCURSES_SP_ARGx n, top, bot, 0, maxy, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301966
1967 if (res == ERR && change_scroll_region) {
1968 if ((((n == 1 && scroll_forward) || parm_index)
Steve Kondikae271bc2015-11-15 02:50:53 +01001969 && (SP_PARM->_cursrow == bot || SP_PARM->_cursrow == bot - 1))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301970 && save_cursor && restore_cursor) {
1971 cursor_saved = TRUE;
Steve Kondikae271bc2015-11-15 02:50:53 +01001972 NCURSES_PUTP2("save_cursor", save_cursor);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301973 }
Steve Kondikae271bc2015-11-15 02:50:53 +01001974 NCURSES_PUTP2("change_scroll_region",
1975 TPARM_2(change_scroll_region, top, bot));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301976 if (cursor_saved) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001977 NCURSES_PUTP2("restore_cursor", restore_cursor);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301978 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +01001979 SP_PARM->_cursrow = SP_PARM->_curscol = -1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301980 }
1981
Steve Kondikae271bc2015-11-15 02:50:53 +01001982 res = scroll_csr_forward(NCURSES_SP_ARGx n, top, bot, top, bot, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301983
Steve Kondikae271bc2015-11-15 02:50:53 +01001984 NCURSES_PUTP2("change_scroll_region",
1985 TPARM_2(change_scroll_region, 0, maxy));
1986 SP_PARM->_cursrow = SP_PARM->_curscol = -1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301987 }
1988
Steve Kondikae271bc2015-11-15 02:50:53 +01001989 if (res == ERR && SP_PARM->_nc_sp_idlok)
1990 res = scroll_idl(NCURSES_SP_ARGx n, top, bot - n + 1, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301991
1992 /*
1993 * Clear the newly shifted-in text.
1994 */
1995 if (res != ERR
1996 && (non_dest_scroll_region || (memory_below && bot == maxy))) {
1997 static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
1998 if (bot == maxy && clr_eos) {
Steve Kondikae271bc2015-11-15 02:50:53 +01001999 GoTo(NCURSES_SP_ARGx bot - n + 1, 0);
2000 ClrToEOS(NCURSES_SP_ARGx blank2);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302001 } else {
2002 for (i = 0; i < n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01002003 GoTo(NCURSES_SP_ARGx bot - i, 0);
2004 ClrToEOL(NCURSES_SP_ARGx blank2, FALSE);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302005 }
2006 }
2007 }
2008
2009 } else { /* (n < 0) - scroll down (backward) */
Steve Kondikae271bc2015-11-15 02:50:53 +01002010 res = scroll_csr_backward(NCURSES_SP_ARGx -n, top, bot, 0, maxy, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302011
2012 if (res == ERR && change_scroll_region) {
Steve Kondikae271bc2015-11-15 02:50:53 +01002013 if (top != 0
2014 && (SP_PARM->_cursrow == top ||
2015 SP_PARM->_cursrow == top - 1)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302016 && save_cursor && restore_cursor) {
2017 cursor_saved = TRUE;
Steve Kondikae271bc2015-11-15 02:50:53 +01002018 NCURSES_PUTP2("save_cursor", save_cursor);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302019 }
Steve Kondikae271bc2015-11-15 02:50:53 +01002020 NCURSES_PUTP2("change_scroll_region",
2021 TPARM_2(change_scroll_region, top, bot));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302022 if (cursor_saved) {
Steve Kondikae271bc2015-11-15 02:50:53 +01002023 NCURSES_PUTP2("restore_cursor", restore_cursor);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302024 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +01002025 SP_PARM->_cursrow = SP_PARM->_curscol = -1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302026 }
2027
Steve Kondikae271bc2015-11-15 02:50:53 +01002028 res = scroll_csr_backward(NCURSES_SP_ARGx
2029 -n, top, bot, top, bot, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302030
Steve Kondikae271bc2015-11-15 02:50:53 +01002031 NCURSES_PUTP2("change_scroll_region",
2032 TPARM_2(change_scroll_region, 0, maxy));
2033 SP_PARM->_cursrow = SP_PARM->_curscol = -1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302034 }
2035
Steve Kondikae271bc2015-11-15 02:50:53 +01002036 if (res == ERR && SP_PARM->_nc_sp_idlok)
2037 res = scroll_idl(NCURSES_SP_ARGx -n, bot + n + 1, top, blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302038
2039 /*
2040 * Clear the newly shifted-in text.
2041 */
2042 if (res != ERR
2043 && (non_dest_scroll_region || (memory_above && top == 0))) {
2044 static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
2045 for (i = 0; i < -n; i++) {
Steve Kondikae271bc2015-11-15 02:50:53 +01002046 GoTo(NCURSES_SP_ARGx i + top, 0);
2047 ClrToEOL(NCURSES_SP_ARGx blank2, FALSE);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302048 }
2049 }
2050 }
2051
2052 if (res == ERR)
2053 return (ERR);
2054
Steve Kondikae271bc2015-11-15 02:50:53 +01002055 _nc_scroll_window(CurScreen(SP_PARM), n,
2056 (NCURSES_SIZE_T) top,
2057 (NCURSES_SIZE_T) bot,
2058 blank);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302059
2060 /* shift hash values too - they can be reused */
Steve Kondikae271bc2015-11-15 02:50:53 +01002061 NCURSES_SP_NAME(_nc_scroll_oldhash) (NCURSES_SP_ARGx n, top, bot);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302062
2063 return (OK);
2064}
2065
Steve Kondikae271bc2015-11-15 02:50:53 +01002066#if NCURSES_SP_FUNCS
2067NCURSES_EXPORT(int)
2068_nc_scrolln(int n, int top, int bot, int maxy)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302069{
Steve Kondikae271bc2015-11-15 02:50:53 +01002070 return NCURSES_SP_NAME(_nc_scrolln) (CURRENT_SCREEN, n, top, bot, maxy);
2071}
2072#endif
2073
2074NCURSES_EXPORT(void)
2075NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_DCL0)
2076{
2077 assert(SP_PARM);
2078
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302079 /* make sure terminal is in a sane known state */
Steve Kondikae271bc2015-11-15 02:50:53 +01002080 SetAttr(SCREEN_ATTRS(SP_PARM), A_NORMAL);
2081 NewScreen(SP_PARM)->_clear = TRUE;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302082
2083 /* reset color pairs and definitions */
Steve Kondikae271bc2015-11-15 02:50:53 +01002084 if (SP_PARM->_coloron || SP_PARM->_color_defs)
2085 NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302086
2087 /* restore user-defined colors, if any */
Steve Kondikae271bc2015-11-15 02:50:53 +01002088 if (SP_PARM->_color_defs < 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302089 int n;
Steve Kondikae271bc2015-11-15 02:50:53 +01002090 SP_PARM->_color_defs = -(SP_PARM->_color_defs);
2091 for (n = 0; n < SP_PARM->_color_defs; ++n) {
2092 if (SP_PARM->_color_table[n].init) {
2093 NCURSES_SP_NAME(init_color) (NCURSES_SP_ARGx
2094 (short) n,
2095 SP_PARM->_color_table[n].r,
2096 SP_PARM->_color_table[n].g,
2097 SP_PARM->_color_table[n].b);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302098 }
2099 }
2100 }
2101
2102 if (exit_attribute_mode)
Steve Kondikae271bc2015-11-15 02:50:53 +01002103 NCURSES_PUTP2("exit_attribute_mode", exit_attribute_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302104 else {
2105 /* turn off attributes */
2106 if (exit_alt_charset_mode)
Steve Kondikae271bc2015-11-15 02:50:53 +01002107 NCURSES_PUTP2("exit_alt_charset_mode", exit_alt_charset_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302108 if (exit_standout_mode)
Steve Kondikae271bc2015-11-15 02:50:53 +01002109 NCURSES_PUTP2("exit_standout_mode", exit_standout_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302110 if (exit_underline_mode)
Steve Kondikae271bc2015-11-15 02:50:53 +01002111 NCURSES_PUTP2("exit_underline_mode", exit_underline_mode);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302112 }
2113 if (exit_insert_mode)
Steve Kondikae271bc2015-11-15 02:50:53 +01002114 NCURSES_PUTP2("exit_insert_mode", exit_insert_mode);
2115 if (enter_am_mode && exit_am_mode) {
2116 if (auto_right_margin) {
2117 NCURSES_PUTP2("enter_am_mode", enter_am_mode);
2118 } else {
2119 NCURSES_PUTP2("exit_am_mode", exit_am_mode);
2120 }
2121 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302122}
2123
Steve Kondikae271bc2015-11-15 02:50:53 +01002124#if NCURSES_SP_FUNCS
2125NCURSES_EXPORT(void)
2126_nc_screen_resume(void)
2127{
2128 NCURSES_SP_NAME(_nc_screen_resume) (CURRENT_SCREEN);
2129}
2130#endif
2131
2132NCURSES_EXPORT(void)
2133NCURSES_SP_NAME(_nc_screen_init) (NCURSES_SP_DCL0)
2134{
2135 NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
2136}
2137
2138#if NCURSES_SP_FUNCS
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302139NCURSES_EXPORT(void)
2140_nc_screen_init(void)
2141{
Steve Kondikae271bc2015-11-15 02:50:53 +01002142 NCURSES_SP_NAME(_nc_screen_init) (CURRENT_SCREEN);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302143}
Steve Kondikae271bc2015-11-15 02:50:53 +01002144#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302145
2146/* wrap up screen handling */
2147NCURSES_EXPORT(void)
Steve Kondikae271bc2015-11-15 02:50:53 +01002148NCURSES_SP_NAME(_nc_screen_wrap) (NCURSES_SP_DCL0)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302149{
Steve Kondikae271bc2015-11-15 02:50:53 +01002150 if (SP_PARM != 0) {
2151
2152 UpdateAttrs(SP_PARM, normal);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302153#if NCURSES_EXT_FUNCS
Steve Kondikae271bc2015-11-15 02:50:53 +01002154 if (SP_PARM->_coloron
2155 && !SP_PARM->_default_color) {
2156 static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
2157 SP_PARM->_default_color = TRUE;
2158 NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx
2159 -1,
2160 0,
2161 FALSE,
2162 NCURSES_SP_NAME(_nc_outch));
2163 SP_PARM->_default_color = FALSE;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302164
Steve Kondikae271bc2015-11-15 02:50:53 +01002165 TINFO_MVCUR(NCURSES_SP_ARGx
2166 SP_PARM->_cursrow,
2167 SP_PARM->_curscol,
2168 screen_lines(SP_PARM) - 1,
2169 0);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302170
Steve Kondikae271bc2015-11-15 02:50:53 +01002171 ClrToEOL(NCURSES_SP_ARGx blank, TRUE);
2172 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302173#endif
Steve Kondikae271bc2015-11-15 02:50:53 +01002174 if (SP_PARM->_color_defs) {
2175 NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
2176 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302177 }
2178}
2179
Steve Kondikae271bc2015-11-15 02:50:53 +01002180#if NCURSES_SP_FUNCS
2181NCURSES_EXPORT(void)
2182_nc_screen_wrap(void)
2183{
2184 NCURSES_SP_NAME(_nc_screen_wrap) (CURRENT_SCREEN);
2185}
2186#endif
2187
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302188#if USE_XMC_SUPPORT
2189NCURSES_EXPORT(void)
Steve Kondikae271bc2015-11-15 02:50:53 +01002190NCURSES_SP_NAME(_nc_do_xmc_glitch) (NCURSES_SP_DCLx attr_t previous)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302191{
Steve Kondikae271bc2015-11-15 02:50:53 +01002192 if (SP_PARM != 0) {
2193 attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP_PARM)));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302194
Steve Kondikae271bc2015-11-15 02:50:53 +01002195 while (chg != 0) {
2196 if (chg & 1) {
2197 SP_PARM->_curscol += magic_cookie_glitch;
2198 if (SP_PARM->_curscol >= SP_PARM->_columns)
2199 wrap_cursor(NCURSES_SP_ARG);
2200 TR(TRACE_UPDATE, ("bumped to %d,%d after cookie",
2201 SP_PARM->_cursrow, SP_PARM->_curscol));
2202 }
2203 chg >>= 1;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302204 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302205 }
2206}
Steve Kondikae271bc2015-11-15 02:50:53 +01002207
2208#if NCURSES_SP_FUNCS
2209NCURSES_EXPORT(void)
2210_nc_do_xmc_glitch(attr_t previous)
2211{
2212 NCURSES_SP_NAME(_nc_do_xmc_glitch) (CURRENT_SCREEN, previous);
2213}
2214#endif
2215
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302216#endif /* USE_XMC_SUPPORT */