ncursesw-morphos/ncurses/tty/tty_update.c

2216 lines
62 KiB
C
Raw Normal View History

1998-03-01 12:21:12 +08:00
/****************************************************************************
* Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
1998-03-01 12:21:12 +08:00
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
2005-10-10 02:41:57 +08:00
* and: Thomas E. Dickey 1996-on *
* and: Juergen Pfeifer 2009 *
1998-03-01 12:21:12 +08:00
****************************************************************************/
1997-05-15 12:00:00 +08:00
/*-----------------------------------------------------------------
*
* lib_doupdate.c
*
2004-02-09 10:15:26 +08:00
* The routine doupdate() and its dependents.
* All physical output is concentrated here (except _nc_outch()
* in lib_tputs.c).
1997-05-15 12:00:00 +08:00
*
*-----------------------------------------------------------------*/
#define NEED_NCURSES_CH_T 1
2002-10-13 11:35:53 +08:00
#include <curses.priv.h>
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
#if defined __HAIKU__ && defined __BEOS__
#undef __BEOS__
#endif
1999-10-24 12:32:42 +08:00
#ifdef __BEOS__
2002-10-13 11:35:53 +08:00
#undef false
#undef true
1999-10-24 12:32:42 +08:00
#include <OS.h>
#endif
1997-05-15 12:00:00 +08:00
#if defined(TRACE) && HAVE_SYS_TIMES_H && HAVE_TIMES
#define USE_TRACE_TIMES 1
#else
#define USE_TRACE_TIMES 0
#endif
1998-03-01 12:21:12 +08:00
#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
1997-05-15 12:00:00 +08:00
#include <sys/time.h>
#endif
#if USE_TRACE_TIMES
#include <sys/times.h>
#endif
#if USE_FUNC_POLL
#elif HAVE_SELECT
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#endif
2004-02-09 10:15:26 +08:00
#include <ctype.h>
1997-05-15 12:00:00 +08:00
MODULE_ID("$Id: tty_update.c,v 1.258 2009/06/27 19:16:17 tom Exp $")
1997-05-15 12:00:00 +08:00
/*
* This define controls the line-breakout optimization. Every once in a
* while during screen refresh, we want to check for input and abort the
* update if there's some waiting. CHECK_INTERVAL controls the number of
* changed lines to be emitted between input checks.
*
* Note: Input-check-and-abort is no longer done if the screen is being
* updated from scratch. This is a feature, not a bug.
*/
1998-03-01 12:21:12 +08:00
#define CHECK_INTERVAL 5
1997-05-15 12:00:00 +08:00
#define FILL_BCE(sp) (sp->_coloron && !sp->_default_color && !back_color_erase)
2000-07-09 10:46:08 +08:00
2006-12-18 12:32:42 +08:00
static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
static NCURSES_CH_T normal = NewChar(BLANK_TEXT);
2005-10-10 02:41:57 +08:00
1997-05-15 12:00:00 +08:00
/*
* Enable checking to see if doupdate and friends are tracking the true
* cursor position correctly. NOTE: this is a debugging hack which will
* work ONLY on ANSI-compatible terminals!
*/
/* #define POSITION_DEBUG */
static NCURSES_INLINE NCURSES_CH_T ClrBlank(NCURSES_SP_DCLx WINDOW *win);
#if NCURSES_SP_FUNCS
static int ClrBottom(SCREEN *, int total);
static void ClearScreen(SCREEN *, NCURSES_CH_T blank);
static void ClrUpdate(SCREEN *);
static void DelChar(SCREEN *, int count);
static void InsStr(SCREEN *, NCURSES_CH_T * line, int count);
static void TransformLine(SCREEN *, int const lineno);
#else
static int ClrBottom(int total);
static void ClearScreen(NCURSES_CH_T blank);
static void ClrUpdate(void);
static void DelChar(int count);
static void InsStr(NCURSES_CH_T * line, int count);
2000-07-09 10:46:08 +08:00
static void TransformLine(int const lineno);
#endif
1997-05-15 12:00:00 +08:00
#ifdef POSITION_DEBUG
/****************************************************************************
*
* Debugging code. Only works on ANSI-standard terminals.
*
****************************************************************************/
2000-07-09 10:46:08 +08:00
static void
position_check(NCURSES_SP_DCLx int expected_y, int expected_x, char *legend)
1997-05-15 12:00:00 +08:00
/* check to see if the real cursor position matches the virtual */
{
2000-07-09 10:46:08 +08:00
char buf[20];
2000-10-21 12:42:11 +08:00
char *s;
1997-05-15 12:00:00 +08:00
int y, x;
1999-10-24 12:32:42 +08:00
if (!_nc_tracing || (expected_y < 0 && expected_x < 0))
1997-05-15 12:00:00 +08:00
return;
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
1997-05-15 12:00:00 +08:00
memset(buf, '\0', sizeof(buf));
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx "\033[6n"); /* only works on ANSI-compatibles */
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
2000-10-21 12:42:11 +08:00
*(s = buf) = 0;
do {
int ask = sizeof(buf) - 1 - (s - buf);
int got = read(0, s, ask);
if (got == 0)
break;
s += got;
} while (strchr(buf, 'R') == 0);
1997-05-15 12:00:00 +08:00
_tracef("probe returned %s", _nc_visbuf(buf));
/* try to interpret as a position report */
1999-10-24 12:32:42 +08:00
if (sscanf(buf, "\033[%d;%dR", &y, &x) != 2) {
1997-05-15 12:00:00 +08:00
_tracef("position probe failed in %s", legend);
1999-10-24 12:32:42 +08:00
} else {
if (expected_x < 0)
expected_x = x - 1;
if (expected_y < 0)
expected_y = y - 1;
if (y - 1 != expected_y || x - 1 != expected_x) {
NCURSES_SP_NAME(beep) (NCURSES_SP_ARG);
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
tparm("\033[%d;%dH",
expected_y + 1,
expected_x + 1),
1, NCURSES_SP_NAME(_nc_outch));
1999-10-24 12:32:42 +08:00
_tracef("position seen (%d, %d) doesn't match expected one (%d, %d) in %s",
2000-10-21 12:42:11 +08:00
y - 1, x - 1, expected_y, expected_x, legend);
1999-10-24 12:32:42 +08:00
} else {
_tracef("position matches OK in %s", legend);
}
}
1997-05-15 12:00:00 +08:00
}
1999-10-24 12:32:42 +08:00
#else
#define position_check(sp, expected_y, expected_x, legend) /* nothing */
1997-05-15 12:00:00 +08:00
#endif /* POSITION_DEBUG */
/****************************************************************************
*
* Optimized update code
*
****************************************************************************/
2006-12-18 12:32:42 +08:00
static NCURSES_INLINE void
GoTo(NCURSES_SP_DCLx int const row, int const col)
1997-05-15 12:00:00 +08:00
{
TR(TRACE_MOVE, ("GoTo(%p, %d, %d) from (%d, %d)",
SP_PARM, row, col, SP_PARM->_cursrow, SP_PARM->_curscol));
1997-05-15 12:00:00 +08:00
position_check(SP_PARM, SP_PARM->_cursrow, SP_PARM->_curscol, "GoTo");
1997-05-15 12:00:00 +08:00
NCURSES_SP_NAME(mvcur) (NCURSES_SP_ARGx SP_PARM->_cursrow,
SP_PARM->_curscol, row, col);
position_check(SP_PARM, SP_PARM->_cursrow, SP_PARM->_curscol, "GoTo2");
1997-05-15 12:00:00 +08:00
}
2006-12-18 12:32:42 +08:00
static NCURSES_INLINE void
PutAttrChar(NCURSES_SP_DCLx CARG_CH_T ch)
1997-05-15 12:00:00 +08:00
{
2004-02-09 10:15:26 +08:00
int chlen = 1;
NCURSES_CH_T my_ch;
2002-10-13 11:35:53 +08:00
PUTC_DATA;
NCURSES_CH_T tilde;
2005-10-10 02:41:57 +08:00
NCURSES_CH_T attr = CHDEREF(ch);
2004-02-09 10:15:26 +08:00
TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)",
_tracech_t(ch),
SP_PARM->_cursrow, SP_PARM->_curscol));
2004-02-09 10:15:26 +08:00
#if USE_WIDEC_SUPPORT
/*
* If this is not a valid character, there is nothing more to do.
*/
2005-10-10 02:41:57 +08:00
if (isWidecExt(CHDEREF(ch))) {
TR(TRACE_CHARPUT, ("...skip"));
2004-02-09 10:15:26 +08:00
return;
2005-10-10 02:41:57 +08:00
}
2004-02-09 10:15:26 +08:00
/*
* Determine the number of character cells which the 'ch' value will use
* on the screen. It should be at least one.
*/
if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) {
2006-12-18 12:32:42 +08:00
static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
2000-07-09 10:46:08 +08:00
2006-12-18 12:32:42 +08:00
/*
* If the character falls into any of these special cases, do
* not force the result to a blank:
*
* a) it is printable (this works around a bug in wcwidth()).
* b) use_legacy_coding() has been called to modify the treatment
* of codes 128-255.
* c) the acs_map[] has been initialized to allow codes 0-31
* to be rendered. This supports Linux console's "PC"
* characters. Codes 128-255 are allowed though this is
* not checked.
*/
2005-10-10 02:41:57 +08:00
if (is8bits(CharOf(CHDEREF(ch)))
&& (isprint(CharOf(CHDEREF(ch)))
|| (SP_PARM->_legacy_coding > 0 && CharOf(CHDEREF(ch)) >= 160)
|| (SP_PARM->_legacy_coding > 1 && CharOf(CHDEREF(ch)) >= 128)
2006-12-18 12:32:42 +08:00
|| (AttrOf(attr) & A_ALTCHARSET
&& ((CharOfD(ch) < ACS_LEN
&& SP_PARM->_acs_map != 0
&& SP_PARM->_acs_map[CharOfD(ch)] != 0)
2006-12-18 12:32:42 +08:00
|| (CharOfD(ch) >= 128))))) {
2004-02-09 10:15:26 +08:00
;
} else {
ch = CHREF(blank);
TR(TRACE_CHARPUT, ("forced to blank"));
}
chlen = 1;
}
#endif
2005-10-10 02:41:57 +08:00
if ((AttrOf(attr) & A_ALTCHARSET)
&& SP_PARM->_acs_map != 0
2004-02-09 10:15:26 +08:00
&& CharOfD(ch) < ACS_LEN) {
my_ch = CHDEREF(ch); /* work around const param */
#if USE_WIDEC_SUPPORT
/*
* This is crude & ugly, but works most of the time. It checks if the
* acs_chars string specified that we have a mapping for this
* character, and uses the wide-character mapping when we expect the
* normal one to be broken (by mis-design ;-).
*/
if (SP_PARM->_screen_acs_fix
&& SP_PARM->_screen_acs_map[CharOf(my_ch)]) {
2005-10-10 02:41:57 +08:00
RemAttr(attr, A_ALTCHARSET);
2004-02-09 10:15:26 +08:00
my_ch = _nc_wacs[CharOf(my_ch)];
}
#endif
2005-10-10 02:41:57 +08:00
/*
* If we (still) have alternate character set, it is the normal 8bit
* flavor. The _screen_acs_map[] array tells if the character was
* really in acs_chars, needed because of the way wide/normal line
* drawing flavors are integrated.
*/
if (AttrOf(attr) & A_ALTCHARSET) {
int j = CharOfD(ch);
chtype temp = UChar(SP_PARM->_acs_map[j]);
2005-10-10 02:41:57 +08:00
if (!(SP_PARM->_screen_acs_map[j])) {
2005-10-10 02:41:57 +08:00
RemAttr(attr, A_ALTCHARSET);
2006-12-18 12:32:42 +08:00
if (temp == 0)
temp = ' ';
}
2004-02-09 10:15:26 +08:00
if (temp != 0)
2005-10-10 02:41:57 +08:00
SetChar(my_ch, temp, AttrOf(attr));
2004-02-09 10:15:26 +08:00
}
ch = CHREF(my_ch);
}
2002-10-13 11:35:53 +08:00
if (tilde_glitch && (CharOfD(ch) == L('~'))) {
2005-10-10 02:41:57 +08:00
SetChar(tilde, L('`'), AttrOf(attr));
2002-10-13 11:35:53 +08:00
ch = CHREF(tilde);
}
2000-07-09 10:46:08 +08:00
UpdateAttrs(SP_PARM, attr);
2002-10-13 11:35:53 +08:00
#if !USE_WIDEC_SUPPORT
/* FIXME - we do this special case for signal handling, should see how to
* make it work for wide characters.
*/
if (SP_PARM->_outch != 0) {
SP_PARM->_outch(NCURSES_SP_ARGx UChar(ch));
2002-10-13 11:35:53 +08:00
} else
#endif
{
PUTC(CHDEREF(ch), SP_PARM->_ofp); /* macro's fastest... */
COUNT_OUTCHARS(1);
2000-07-09 10:46:08 +08:00
}
SP_PARM->_curscol += chlen;
2000-07-09 10:46:08 +08:00
if (char_padding) {
TPUTS_TRACE("char_padding");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx char_padding);
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
static bool
check_pending(NCURSES_SP_DCL0)
1997-05-15 12:00:00 +08:00
/* check for pending input */
{
2000-07-09 10:46:08 +08:00
bool have_pending = FALSE;
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
/*
* Only carry out this check when the flag is zero, otherwise we'll
* have the refreshing slow down drastically (or stop) if there's an
* unread character available.
*/
if (SP_PARM->_fifohold != 0)
2000-07-09 10:46:08 +08:00
return FALSE;
1998-03-01 12:21:12 +08:00
if (SP_PARM->_checkfd >= 0) {
1997-05-15 12:00:00 +08:00
#if USE_FUNC_POLL
2000-07-09 10:46:08 +08:00
struct pollfd fds[1];
fds[0].fd = SP_PARM->_checkfd;
2000-07-09 10:46:08 +08:00
fds[0].events = POLLIN;
if (poll(fds, 1, 0) > 0) {
have_pending = TRUE;
}
1999-10-24 12:32:42 +08:00
#elif defined(__BEOS__)
2000-07-09 10:46:08 +08:00
/*
* BeOS's select() is declared in socket.h, so the configure script does
* not see it. That's just as well, since that function works only for
* sockets. This (using snooze and ioctl) was distilled from Be's patch
* for ncurses which uses a separate thread to simulate select().
*
* FIXME: the return values from the ioctl aren't very clear if we get
* interrupted.
*/
int n = 0;
int howmany = ioctl(0, 'ichr', &n);
if (howmany >= 0 && n > 0) {
have_pending = TRUE;
}
1997-05-15 12:00:00 +08:00
#elif HAVE_SELECT
2000-07-09 10:46:08 +08:00
fd_set fdset;
struct timeval ktimeout;
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
ktimeout.tv_sec =
ktimeout.tv_usec = 0;
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
FD_ZERO(&fdset);
FD_SET(SP_PARM->_checkfd, &fdset);
if (select(SP_PARM->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) {
2000-07-09 10:46:08 +08:00
have_pending = TRUE;
1998-03-01 12:21:12 +08:00
}
2000-07-09 10:46:08 +08:00
#endif
}
if (have_pending) {
SP_PARM->_fifohold = 5;
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
2000-07-09 10:46:08 +08:00
}
return FALSE;
1997-05-15 12:00:00 +08:00
}
1998-03-01 12:21:12 +08:00
/* put char at lower right corner */
2000-07-09 10:46:08 +08:00
static void
PutCharLR(NCURSES_SP_DCLx const ARG_CH_T ch)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
if (!auto_right_margin) {
1998-03-01 12:21:12 +08:00
/* we can put the char directly */
PutAttrChar(NCURSES_SP_ARGx ch);
2000-07-09 10:46:08 +08:00
} else if (enter_am_mode && exit_am_mode) {
1998-03-01 12:21:12 +08:00
/* we can suppress automargin */
TPUTS_TRACE("exit_am_mode");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx exit_am_mode);
1997-05-15 12:00:00 +08:00
PutAttrChar(NCURSES_SP_ARGx ch);
SP_PARM->_curscol--;
position_check(SP_PARM,
SP_PARM->_cursrow,
SP_PARM->_curscol,
"exit_am_mode");
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("enter_am_mode");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx enter_am_mode);
2000-07-09 10:46:08 +08:00
} else if ((enter_insert_mode && exit_insert_mode)
2000-10-21 12:42:11 +08:00
|| insert_character || parm_ich) {
GoTo(NCURSES_SP_ARGx
screen_lines(SP_PARM) - 1,
screen_columns(SP_PARM) - 2);
PutAttrChar(NCURSES_SP_ARGx ch);
GoTo(NCURSES_SP_ARGx
screen_lines(SP_PARM) - 1,
screen_columns(SP_PARM) - 2);
InsStr(NCURSES_SP_ARGx
NewScreen(SP_PARM)->_line[screen_lines(SP_PARM) - 1].text +
screen_columns(SP_PARM) - 2, 1);
1997-05-15 12:00:00 +08:00
}
1998-03-01 12:21:12 +08:00
}
1997-05-15 12:00:00 +08:00
2006-12-18 12:32:42 +08:00
/*
* Wrap the cursor position, i.e., advance to the beginning of the next line.
*/
2000-07-09 10:46:08 +08:00
static void
wrap_cursor(NCURSES_SP_DCL0)
1998-03-01 12:21:12 +08:00
{
2000-07-09 10:46:08 +08:00
if (eat_newline_glitch) {
1998-03-01 12:21:12 +08:00
/*
2006-12-18 12:32:42 +08:00
* xenl can manifest two different ways. The vt100 way is that, when
* you'd expect the cursor to wrap, it stays hung at the right margin
* (on top of the character just emitted) and doesn't wrap until the
* *next* graphic char is emitted. The c100 way is to ignore LF
* received just after an am wrap.
1998-03-01 12:21:12 +08:00
*
2006-12-18 12:32:42 +08:00
* An aggressive way to handle this would be to emit CR/LF after the
* char and then assume the wrap is done, you're on the first position
* of the next line, and the terminal out of its weird state. Here
* it's safe to just tell the code that the cursor is in hyperspace and
* let the next mvcur() call straighten things out.
1998-03-01 12:21:12 +08:00
*/
SP_PARM->_curscol = -1;
SP_PARM->_cursrow = -1;
2000-07-09 10:46:08 +08:00
} else if (auto_right_margin) {
SP_PARM->_curscol = 0;
SP_PARM->_cursrow++;
2006-12-18 12:32:42 +08:00
/*
* We've actually moved - but may have to work around problems with
* video attributes not working.
*/
if (!move_standout_mode && AttrOf(SCREEN_ATTRS(SP_PARM))) {
2006-12-18 12:32:42 +08:00
TR(TRACE_CHARPUT, ("turning off (%#lx) %s before wrapping",
(unsigned long) AttrOf(SCREEN_ATTRS(SP_PARM)),
_traceattr(AttrOf(SCREEN_ATTRS(SP_PARM)))));
2009-05-03 08:59:25 +08:00
(void) VIDATTR(SP_PARM, A_NORMAL, 0);
2006-12-18 12:32:42 +08:00
}
2000-07-09 10:46:08 +08:00
} else {
SP_PARM->_curscol--;
1998-03-01 12:21:12 +08:00
}
position_check(SP_PARM,
SP_PARM->_cursrow,
SP_PARM->_curscol,
"wrap_cursor");
1998-03-01 12:21:12 +08:00
}
2006-12-18 12:32:42 +08:00
static NCURSES_INLINE void
PutChar(NCURSES_SP_DCLx const ARG_CH_T ch)
1998-03-01 12:21:12 +08:00
/* insert character, handling automargin stuff */
{
if (SP_PARM->_cursrow == screen_lines(SP_PARM) - 1 &&
SP_PARM->_curscol == screen_columns(SP_PARM) - 1) {
PutCharLR(NCURSES_SP_ARGx ch);
} else {
PutAttrChar(NCURSES_SP_ARGx ch);
}
1998-03-01 12:21:12 +08:00
if (SP_PARM->_curscol >= screen_columns(SP_PARM))
wrap_cursor(NCURSES_SP_ARG);
1998-03-01 12:21:12 +08:00
position_check(SP_PARM, SP_PARM->_cursrow, SP_PARM->_curscol, "PutChar");
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
/*
* Check whether the given character can be output by clearing commands. This
* includes test for being a space and not including any 'bad' attributes, such
* as A_REVERSE. All attribute flags which don't affect appearance of a space
* or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
*/
2006-12-18 12:32:42 +08:00
static NCURSES_INLINE bool
can_clear_with(NCURSES_SP_DCLx ARG_CH_T ch)
2000-07-09 10:46:08 +08:00
{
if (!back_color_erase && SP_PARM->_coloron) {
2000-10-21 12:42:11 +08:00
#if NCURSES_EXT_FUNCS
2005-10-10 02:41:57 +08:00
int pair;
if (!SP_PARM->_default_color)
2000-07-09 10:46:08 +08:00
return FALSE;
if (SP_PARM->_default_fg != C_MASK || SP_PARM->_default_bg != C_MASK)
2000-07-09 10:46:08 +08:00
return FALSE;
2005-10-10 02:41:57 +08:00
if ((pair = GetPair(CHDEREF(ch))) != 0) {
2002-10-13 11:35:53 +08:00
short fg, bg;
NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx pair, &fg, &bg);
2002-10-13 11:35:53 +08:00
if (fg != C_MASK || bg != C_MASK)
return FALSE;
}
#else
if (AttrOfD(ch) & A_COLOR)
return FALSE;
2000-07-09 10:46:08 +08:00
#endif
}
2002-10-13 11:35:53 +08:00
return (ISBLANK(CHDEREF(ch)) &&
(AttrOfD(ch) & ~(NONBLANK_ATTR | A_COLOR)) == BLANK_ATTR);
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
/*
* Issue a given span of characters from an array.
* Must be functionally equivalent to:
* for (i = 0; i < num; i++)
* PutChar(ntext[i]);
* but can leave the cursor positioned at the middle of the interval.
*
* Returns: 0 - cursor is at the end of interval
* 1 - cursor is somewhere in the middle
*
* This code is optimized using ech and rep.
*/
2000-07-09 10:46:08 +08:00
static int
EmitRange(NCURSES_SP_DCLx const NCURSES_CH_T * ntext, int num)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int i;
1997-05-15 12:00:00 +08:00
2006-12-18 12:32:42 +08:00
TR(TRACE_CHARPUT, ("EmitRange %d:%s", num, _nc_viscbuf(ntext, num)));
2000-07-09 10:46:08 +08:00
if (erase_chars || repeat_char) {
while (num > 0) {
int runcount;
2002-10-13 11:35:53 +08:00
NCURSES_CH_T ntext0;
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
while (num > 1 && !CharEq(ntext[0], ntext[1])) {
PutChar(NCURSES_SP_ARGx CHREF(ntext[0]));
1997-05-15 12:00:00 +08:00
ntext++;
num--;
}
ntext0 = ntext[0];
2000-07-09 10:46:08 +08:00
if (num == 1) {
PutChar(NCURSES_SP_ARGx CHREF(ntext0));
1997-05-15 12:00:00 +08:00
return 0;
}
runcount = 2;
2002-10-13 11:35:53 +08:00
while (runcount < num && CharEq(ntext[runcount], ntext0))
1997-05-15 12:00:00 +08:00
runcount++;
/*
* The cost expression in the middle isn't exactly right.
2000-07-09 10:46:08 +08:00
* _cup_ch_cost is an upper bound on the cost for moving to the
1997-05-15 12:00:00 +08:00
* end of the erased area, but not the cost itself (which we
* can't compute without emitting the move). This may result
* in erase_chars not getting used in some situations for
* which it would be marginally advantageous.
*/
if (erase_chars
&& runcount > SP_PARM->_ech_cost + SP_PARM->_cup_ch_cost
&& can_clear_with(NCURSES_SP_ARGx CHREF(ntext0))) {
UpdateAttrs(SP_PARM, ntext0);
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx
TPARM_1(erase_chars, runcount));
1997-05-15 12:00:00 +08:00
/*
* If this is the last part of the given interval,
* don't bother moving cursor, since it can be the
* last update on the line.
*/
2000-10-21 12:42:11 +08:00
if (runcount < num) {
GoTo(NCURSES_SP_ARGx
SP_PARM->_cursrow,
SP_PARM->_curscol + runcount);
2000-10-21 12:42:11 +08:00
} else {
1997-05-15 12:00:00 +08:00
return 1; /* cursor stays in the middle */
2000-10-21 12:42:11 +08:00
}
} else if (repeat_char && runcount > SP_PARM->_rep_cost) {
bool wrap_possible = (SP_PARM->_curscol + runcount >=
screen_columns(SP_PARM));
1997-05-15 12:00:00 +08:00
int rep_count = runcount;
if (wrap_possible)
rep_count--;
UpdateAttrs(SP_PARM, ntext0);
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_2(repeat_char,
CharOf(ntext0),
rep_count),
rep_count,
NCURSES_SP_NAME(_nc_outch));
SP_PARM->_curscol += rep_count;
1997-05-15 12:00:00 +08:00
if (wrap_possible)
PutChar(NCURSES_SP_ARGx CHREF(ntext0));
2000-07-09 10:46:08 +08:00
} else {
1997-05-15 12:00:00 +08:00
for (i = 0; i < runcount; i++)
PutChar(NCURSES_SP_ARGx CHREF(ntext[i]));
1997-05-15 12:00:00 +08:00
}
ntext += runcount;
num -= runcount;
}
return 0;
}
for (i = 0; i < num; i++)
PutChar(NCURSES_SP_ARGx CHREF(ntext[i]));
1997-05-15 12:00:00 +08:00
return 0;
}
/*
* Output the line in the given range [first .. last]
*
* If there's a run of identical characters that's long enough to justify
* cursor movement, use that also.
*
* Returns: same as EmitRange
*/
2000-07-09 10:46:08 +08:00
static int
PutRange(NCURSES_SP_DCLx
const NCURSES_CH_T * otext,
2002-10-13 11:35:53 +08:00
const NCURSES_CH_T * ntext,
int row,
int first, int last)
1997-05-15 12:00:00 +08:00
{
2004-02-09 10:15:26 +08:00
int i, j, same;
2000-07-09 10:46:08 +08:00
TR(TRACE_CHARPUT, ("PutRange(%p, %p, %p, %d, %d, %d)",
SP_PARM, otext, ntext, row, first, last));
2000-07-09 10:46:08 +08:00
if (otext != ntext
&& (last - first + 1) > SP_PARM->_inline_cost) {
2004-02-09 10:15:26 +08:00
for (j = first, same = 0; j <= last; j++) {
2005-10-10 02:41:57 +08:00
if (!same && isWidecExt(otext[j]))
2002-10-13 11:35:53 +08:00
continue;
if (CharEq(otext[j], ntext[j])) {
2004-02-09 10:15:26 +08:00
same++;
2000-07-09 10:46:08 +08:00
} else {
if (same > SP_PARM->_inline_cost) {
EmitRange(NCURSES_SP_ARGx ntext + first, j - same - first);
GoTo(NCURSES_SP_ARGx row, first = j);
1997-05-15 12:00:00 +08:00
}
2004-02-09 10:15:26 +08:00
same = 0;
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
i = EmitRange(NCURSES_SP_ARGx ntext + first, j - same - first);
2004-02-09 10:15:26 +08:00
/*
* Always return 1 for the next GoTo() after a PutRange() if we found
* identical characters at end of interval
*/
return (same == 0 ? i : 1);
2000-07-09 10:46:08 +08:00
}
return EmitRange(NCURSES_SP_ARGx ntext + first, last - first + 1);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
/* leave unbracketed here so 'indent' works */
1997-05-15 12:00:00 +08:00
#define MARK_NOCHANGE(win,row) \
win->_line[row].firstchar = _NOCHANGE; \
win->_line[row].lastchar = _NOCHANGE; \
2000-07-09 10:46:08 +08:00
if_USE_SCROLL_HINTS(win->_line[row].oldindex = row)
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int i;
int nonempty;
1997-05-15 12:00:00 +08:00
#if USE_TRACE_TIMES
2000-07-09 10:46:08 +08:00
struct tms before, after;
1997-05-15 12:00:00 +08:00
#endif /* USE_TRACE_TIMES */
T((T_CALLED("_nc_tinfo:doupdate(%p)"), SP_PARM));
1997-05-15 12:00:00 +08:00
#if !USE_REENTRANT
/*
* It is "legal" but unlikely that an application could assign a new
* value to one of the standard windows. Check for that possibility
* and try to recover.
*
* We do not allow applications to assign new values in the reentrant
* model.
*/
#define SyncScreens(internal,exported) \
if (internal == 0) internal = exported; \
if (internal != exported) exported = internal
SyncScreens(CurScreen(SP_PARM), curscr);
SyncScreens(NewScreen(SP_PARM), newscr);
SyncScreens(StdScreen(SP_PARM), stdscr);
#endif
if (CurScreen(SP_PARM) == 0
|| NewScreen(SP_PARM) == 0
|| StdScreen(SP_PARM) == 0)
returnCode(ERR);
1997-05-15 12:00:00 +08:00
#ifdef TRACE
if (USE_TRACEF(TRACE_UPDATE)) {
if (CurScreen(SP_PARM)->_clear)
2000-07-09 10:46:08 +08:00
_tracef("curscr is clear");
else
_tracedump("curscr", CurScreen(SP_PARM));
_tracedump("newscr", NewScreen(SP_PARM));
_nc_unlock_global(tracef);
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
#endif /* TRACE */
2000-07-09 10:46:08 +08:00
_nc_signal_handler(FALSE);
1997-05-15 12:00:00 +08:00
if (SP_PARM->_fifohold)
SP_PARM->_fifohold--;
1997-05-15 12:00:00 +08:00
1998-03-01 12:21:12 +08:00
#if USE_SIZECHANGE
if (SP_PARM->_endwin || _nc_handle_sigwinch(SP_PARM)) {
2000-07-09 10:46:08 +08:00
/*
* This is a transparent extension: XSI does not address it,
* and applications need not know that ncurses can do it.
*
* Check if the terminal size has changed while curses was off
* (this can happen in an xterm, for example), and resize the
* ncurses data structures accordingly.
*/
_nc_update_screensize(SP_PARM);
2000-07-09 10:46:08 +08:00
}
1998-03-01 12:21:12 +08:00
#endif
if (SP_PARM->_endwin) {
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
T(("coming back from shell mode"));
NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
1997-05-15 12:00:00 +08:00
NCURSES_SP_NAME(_nc_mvcur_resume) (NCURSES_SP_ARG);
NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
SP_PARM->_mouse_resume(SP_PARM);
1997-05-15 12:00:00 +08:00
SP_PARM->_endwin = FALSE;
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
#if USE_TRACE_TIMES
2000-07-09 10:46:08 +08:00
/* zero the metering machinery */
RESET_OUTCHARS();
2000-07-09 10:46:08 +08:00
(void) times(&before);
1997-05-15 12:00:00 +08:00
#endif /* USE_TRACE_TIMES */
2000-07-09 10:46:08 +08:00
/*
2006-12-18 12:32:42 +08:00
* This is the support for magic-cookie terminals. The theory: we scan
* the virtual screen looking for attribute turnons. Where we find one,
* check to make sure it's realizable by seeing if the required number of
* un-attributed blanks are present before and after the attributed range;
* try to shift the range boundaries over blanks (not changing the screen
* display) so this becomes true. If it is, shift the beginning attribute
* change appropriately (the end one, if we've gotten this far, is
* guaranteed room for its cookie). If not, nuke the added attributes out
* of the span.
2000-07-09 10:46:08 +08:00
*/
1998-03-01 12:21:12 +08:00
#if USE_XMC_SUPPORT
2000-07-09 10:46:08 +08:00
if (magic_cookie_glitch > 0) {
int j, k;
attr_t rattr = A_NORMAL;
1997-05-15 12:00:00 +08:00
for (i = 0; i < screen_lines(SP_PARM); i++) {
for (j = 0; j < screen_columns(SP_PARM); j++) {
2000-07-09 10:46:08 +08:00
bool failed = FALSE;
NCURSES_CH_T *thisline = NewScreen(SP_PARM)->_line[i].text;
attr_t thisattr = AttrOf(thisline[j]) & SP_PARM->_xmc_triggers;
2006-12-18 12:32:42 +08:00
attr_t turnon = thisattr & ~rattr;
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
/* is an attribute turned on here? */
if (turnon == 0) {
2006-12-18 12:32:42 +08:00
rattr = thisattr;
2000-07-09 10:46:08 +08:00
continue;
}
1997-05-15 12:00:00 +08:00
2000-10-21 12:42:11 +08:00
TR(TRACE_ATTRS, ("At (%d, %d): from %s...", i, j, _traceattr(rattr)));
TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon)));
2000-07-09 10:46:08 +08:00
/*
2006-12-18 12:32:42 +08:00
* If the attribute change location is a blank with a "safe"
* attribute, undo the attribute turnon. This may ensure
* there's enough room to set the attribute before the first
* non-blank in the run.
2000-07-09 10:46:08 +08:00
*/
#define SAFE(scr,a) (!((a) & (scr)->_xmc_triggers))
if (ISBLANK(thisline[j]) && SAFE(SP_PARM, turnon)) {
2006-12-18 12:32:42 +08:00
RemAttr(thisline[j], turnon);
2000-07-09 10:46:08 +08:00
continue;
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
/* check that there's enough room at start of span */
for (k = 1; k <= magic_cookie_glitch; k++) {
if (j - k < 0
2006-12-18 12:32:42 +08:00
|| !ISBLANK(thisline[j - k])
|| !SAFE(SP_PARM, AttrOf(thisline[j - k]))) {
2000-07-09 10:46:08 +08:00
failed = TRUE;
2006-12-18 12:32:42 +08:00
TR(TRACE_ATTRS, ("No room at start in %d,%d%s%s",
i, j - k,
(ISBLANK(thisline[j - k])
? ""
: ":nonblank"),
(SAFE(SP_PARM, AttrOf(thisline[j - k]))
2006-12-18 12:32:42 +08:00
? ""
: ":unsafe")));
break;
}
2000-07-09 10:46:08 +08:00
}
if (!failed) {
bool end_onscreen = FALSE;
int m, n = j;
/* find end of span, if it's onscreen */
for (m = i; m < screen_lines(SP_PARM); m++) {
for (; n < screen_columns(SP_PARM); n++) {
attr_t testattr =
AttrOf(NewScreen(SP_PARM)->_line[m].text[n]);
if ((testattr & SP_PARM->_xmc_triggers) == rattr) {
2000-07-09 10:46:08 +08:00
end_onscreen = TRUE;
2000-10-21 12:42:11 +08:00
TR(TRACE_ATTRS,
("Range attributed with %s ends at (%d, %d)",
_traceattr(turnon), m, n));
2000-07-09 10:46:08 +08:00
goto foundit;
1998-03-01 12:21:12 +08:00
}
}
2000-07-09 10:46:08 +08:00
n = 0;
1997-05-15 12:00:00 +08:00
}
2000-10-21 12:42:11 +08:00
TR(TRACE_ATTRS,
("Range attributed with %s ends offscreen",
_traceattr(turnon)));
2000-07-09 10:46:08 +08:00
foundit:;
if (end_onscreen) {
NCURSES_CH_T *lastline =
NewScreen(SP_PARM)->_line[m].text;
1997-05-15 12:00:00 +08:00
/*
2006-12-18 12:32:42 +08:00
* If there are safely-attributed blanks at the end of
* the range, shorten the range. This will help ensure
* that there is enough room at end of span.
1997-05-15 12:00:00 +08:00
*/
2000-07-09 10:46:08 +08:00
while (n >= 0
2002-10-13 11:35:53 +08:00
&& ISBLANK(lastline[n])
&& SAFE(SP_PARM, AttrOf(lastline[n]))) {
2002-10-13 11:35:53 +08:00
RemAttr(lastline[n--], turnon);
2006-12-18 12:32:42 +08:00
}
2000-07-09 10:46:08 +08:00
/* check that there's enough room at end of span */
2006-12-18 12:32:42 +08:00
for (k = 1; k <= magic_cookie_glitch; k++) {
if (n + k >= screen_columns(SP_PARM)
2002-10-13 11:35:53 +08:00
|| !ISBLANK(lastline[n + k])
|| !SAFE(SP_PARM, AttrOf(lastline[n + k]))) {
2000-07-09 10:46:08 +08:00
failed = TRUE;
2006-12-18 12:32:42 +08:00
TR(TRACE_ATTRS,
("No room at end in %d,%d%s%s",
i, j - k,
(ISBLANK(lastline[n + k])
? ""
: ":nonblank"),
(SAFE(SP_PARM, AttrOf(lastline[n + k]))
2006-12-18 12:32:42 +08:00
? ""
: ":unsafe")));
break;
}
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (failed) {
int p, q = j;
2000-10-21 12:42:11 +08:00
TR(TRACE_ATTRS,
("Clearing %s beginning at (%d, %d)",
_traceattr(turnon), i, j));
2000-07-09 10:46:08 +08:00
/* turn off new attributes over span */
for (p = i; p < screen_lines(SP_PARM); p++) {
for (; q < screen_columns(SP_PARM); q++) {
attr_t testattr = AttrOf(newscr->_line[p].text[q]);
if ((testattr & SP_PARM->_xmc_triggers) == rattr)
2000-07-09 10:46:08 +08:00
goto foundend;
RemAttr(NewScreen(SP_PARM)->_line[p].text[q], turnon);
2000-07-09 10:46:08 +08:00
}
q = 0;
}
foundend:;
} else {
2000-10-21 12:42:11 +08:00
TR(TRACE_ATTRS,
("Cookie space for %s found before (%d, %d)",
_traceattr(turnon), i, j));
2000-07-09 10:46:08 +08:00
/*
2006-12-18 12:32:42 +08:00
* Back up the start of range so there's room for cookies
* before the first nonblank character.
2000-07-09 10:46:08 +08:00
*/
for (k = 1; k <= magic_cookie_glitch; k++)
2006-12-18 12:32:42 +08:00
AddAttr(thisline[j - k], turnon);
1997-05-15 12:00:00 +08:00
}
2006-12-18 12:32:42 +08:00
rattr = thisattr;
1997-05-15 12:00:00 +08:00
}
}
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
#ifdef TRACE
/* show altered highlights after magic-cookie check */
if (USE_TRACEF(TRACE_UPDATE)) {
2000-07-09 10:46:08 +08:00
_tracef("After magic-cookie check...");
_tracedump("newscr", NewScreen(SP_PARM));
_nc_unlock_global(tracef);
2000-07-09 10:46:08 +08:00
}
#endif /* TRACE */
}
#endif /* USE_XMC_SUPPORT */
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
nonempty = 0;
if (CurScreen(SP_PARM)->_clear || NewScreen(SP_PARM)->_clear) { /* force refresh ? */
ClrUpdate(NCURSES_SP_ARG);
CurScreen(SP_PARM)->_clear = FALSE; /* reset flag */
NewScreen(SP_PARM)->_clear = FALSE; /* reset flag */
2000-07-09 10:46:08 +08:00
} else {
int changedlines = CHECK_INTERVAL;
1998-03-01 12:21:12 +08:00
if (check_pending(NCURSES_SP_ARG))
2000-07-09 10:46:08 +08:00
goto cleanup;
1997-05-15 12:00:00 +08:00
nonempty = min(screen_lines(SP_PARM), NewScreen(SP_PARM)->_maxy + 1);
1997-05-15 12:00:00 +08:00
if (SP_PARM->_scrolling) {
NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_ARG);
2000-07-09 10:46:08 +08:00
}
1998-03-01 12:21:12 +08:00
nonempty = ClrBottom(NCURSES_SP_ARGx nonempty);
1997-05-15 12:00:00 +08:00
2000-10-21 12:42:11 +08:00
TR(TRACE_UPDATE, ("Transforming lines, nonempty %d", nonempty));
2000-07-09 10:46:08 +08:00
for (i = 0; i < nonempty; i++) {
/*
* Here is our line-breakout optimization.
*/
if (changedlines == CHECK_INTERVAL) {
if (check_pending(NCURSES_SP_ARG))
2000-07-09 10:46:08 +08:00
goto cleanup;
changedlines = 0;
}
/*
* newscr->line[i].firstchar is normally set
* by wnoutrefresh. curscr->line[i].firstchar
2000-07-09 10:46:08 +08:00
* is normally set by _nc_scroll_window in the
* vertical-movement optimization code,
*/
if (NewScreen(SP_PARM)->_line[i].firstchar != _NOCHANGE
|| CurScreen(SP_PARM)->_line[i].firstchar != _NOCHANGE) {
TransformLine(NCURSES_SP_ARGx i);
2000-07-09 10:46:08 +08:00
changedlines++;
}
/* mark line changed successfully */
if (i <= NewScreen(SP_PARM)->_maxy) {
MARK_NOCHANGE(NewScreen(SP_PARM), i);
2000-07-09 10:46:08 +08:00
}
if (i <= CurScreen(SP_PARM)->_maxy) {
MARK_NOCHANGE(CurScreen(SP_PARM), i);
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
/* put everything back in sync */
for (i = nonempty; i <= NewScreen(SP_PARM)->_maxy; i++) {
MARK_NOCHANGE(NewScreen(SP_PARM), i);
2000-07-09 10:46:08 +08:00
}
for (i = nonempty; i <= CurScreen(SP_PARM)->_maxy; i++) {
MARK_NOCHANGE(CurScreen(SP_PARM), i);
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
if (!NewScreen(SP_PARM)->_leaveok) {
CurScreen(SP_PARM)->_curx = NewScreen(SP_PARM)->_curx;
CurScreen(SP_PARM)->_cury = NewScreen(SP_PARM)->_cury;
1997-05-15 12:00:00 +08:00
GoTo(NCURSES_SP_ARGx CurScreen(SP_PARM)->_cury, CurScreen(SP_PARM)->_curx);
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
cleanup:
/*
2006-12-18 12:32:42 +08:00
* We would like to keep the physical screen in normal mode in case we get
* other processes writing to the screen. This goal cannot be met for
* magic cookies since it interferes with attributes that may propagate
* past the current position.
2000-07-09 10:46:08 +08:00
*/
2006-12-18 12:32:42 +08:00
#if USE_XMC_SUPPORT
if (magic_cookie_glitch != 0)
#endif
UpdateAttrs(SP_PARM, normal);
1997-05-15 12:00:00 +08:00
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
WINDOW_ATTRS(CurScreen(SP_PARM)) = WINDOW_ATTRS(NewScreen(SP_PARM));
1997-05-15 12:00:00 +08:00
#if USE_TRACE_TIMES
2000-07-09 10:46:08 +08:00
(void) times(&after);
TR(TRACE_TIMES,
2000-10-21 12:42:11 +08:00
("Update cost: %ld chars, %ld clocks system time, %ld clocks user time",
_nc_outchars,
2002-10-13 11:35:53 +08:00
(long) (after.tms_stime - before.tms_stime),
(long) (after.tms_utime - before.tms_utime)));
1997-05-15 12:00:00 +08:00
#endif /* USE_TRACE_TIMES */
2000-07-09 10:46:08 +08:00
_nc_signal_handler(TRUE);
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
returnCode(OK);
1997-05-15 12:00:00 +08:00
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
doupdate(void)
{
return NCURSES_SP_NAME(doupdate) (CURRENT_SCREEN);
}
#endif
1997-05-15 12:00:00 +08:00
/*
* ClrBlank(win)
*
* Returns the attributed character that corresponds to the "cleared"
* screen. If the terminal has the back-color-erase feature, this will be
1998-03-01 12:21:12 +08:00
* colored according to the wbkgd() call.
1997-05-15 12:00:00 +08:00
*
* We treat 'curscr' specially because it isn't supposed to be set directly
* in the wbkgd() call. Assume 'stdscr' for this case.
*/
#define BCE_ATTRS (A_NORMAL|A_COLOR)
#define BCE_BKGD(sp,win) (((win) == CurScreen(sp) ? StdScreen(sp) : (win))->_nc_bkgd)
1997-05-15 12:00:00 +08:00
2006-12-18 12:32:42 +08:00
static NCURSES_INLINE NCURSES_CH_T
ClrBlank(NCURSES_SP_DCLx WINDOW *win)
1997-05-15 12:00:00 +08:00
{
2006-12-18 12:32:42 +08:00
NCURSES_CH_T blank = blankchar;
2000-07-09 10:46:08 +08:00
if (back_color_erase)
AddAttr(blank, (AttrOf(BCE_BKGD(SP_PARM, win)) & BCE_ATTRS));
2000-07-09 10:46:08 +08:00
return blank;
1997-05-15 12:00:00 +08:00
}
/*
1999-10-24 12:32:42 +08:00
** ClrUpdate()
1997-05-15 12:00:00 +08:00
**
** Update by clearing and redrawing the entire screen.
**
*/
2000-07-09 10:46:08 +08:00
static void
ClrUpdate(NCURSES_SP_DCL0)
1997-05-15 12:00:00 +08:00
{
TR(TRACE_UPDATE, (T_CALLED("ClrUpdate")));
if (0 != SP_PARM) {
int i;
NCURSES_CH_T blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
int nonempty = min(screen_lines(SP_PARM),
NewScreen(SP_PARM)->_maxy + 1);
1998-03-01 12:21:12 +08:00
ClearScreen(NCURSES_SP_ARGx blank);
1997-05-15 12:00:00 +08:00
TR(TRACE_UPDATE, ("updating screen from scratch"));
1997-05-15 12:00:00 +08:00
nonempty = ClrBottom(NCURSES_SP_ARGx nonempty);
for (i = 0; i < nonempty; i++)
TransformLine(NCURSES_SP_ARGx i);
}
TR(TRACE_UPDATE, (T_RETURN("")));
1997-05-15 12:00:00 +08:00
}
/*
** ClrToEOL(blank)
**
** Clear to end of current line, starting at the cursor position
*/
2000-07-09 10:46:08 +08:00
static void
ClrToEOL(NCURSES_SP_DCLx NCURSES_CH_T blank, bool needclear)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int j;
1997-05-15 12:00:00 +08:00
if (SP_PARM != 0 && CurScreen(SP_PARM) != 0
&& SP_PARM->_cursrow >= 0) {
for (j = SP_PARM->_curscol; j < screen_columns(SP_PARM); j++) {
2000-10-21 12:42:11 +08:00
if (j >= 0) {
NCURSES_CH_T *cp =
&(CurScreen(SP_PARM)->_line[SP_PARM->_cursrow].text[j]);
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (!CharEq(*cp, blank)) {
2000-10-21 12:42:11 +08:00
*cp = blank;
needclear = TRUE;
}
1997-05-15 12:00:00 +08:00
}
}
2000-07-09 10:46:08 +08:00
} else {
needclear = TRUE;
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (needclear) {
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
TPUTS_TRACE("clr_eol");
if (clr_eol && SP_PARM->_el_cost <= (screen_columns(SP_PARM) - SP_PARM->_curscol)) {
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx clr_eol);
2004-02-09 10:15:26 +08:00
} else {
int count = (screen_columns(SP_PARM) - SP_PARM->_curscol);
2000-07-09 10:46:08 +08:00
while (count-- > 0)
PutChar(NCURSES_SP_ARGx CHREF(blank));
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
1998-03-01 12:21:12 +08:00
/*
** ClrToEOS(blank)
**
** Clear to end of screen, starting at the cursor position
*/
2000-07-09 10:46:08 +08:00
static void
ClrToEOS(NCURSES_SP_DCLx NCURSES_CH_T blank)
1998-03-01 12:21:12 +08:00
{
2000-07-09 10:46:08 +08:00
int row, col;
if (0 == SP_PARM)
return;
row = SP_PARM->_cursrow;
col = SP_PARM->_curscol;
1998-03-01 12:21:12 +08:00
UpdateAttrs(SP_PARM, blank);
2000-10-21 12:42:11 +08:00
TPUTS_TRACE("clr_eos");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
clr_eos,
screen_lines(SP_PARM) - row,
NCURSES_SP_NAME(_nc_outch));
1998-03-01 12:21:12 +08:00
while (col < screen_columns(SP_PARM))
CurScreen(SP_PARM)->_line[row].text[col++] = blank;
1998-03-01 12:21:12 +08:00
for (row++; row < screen_lines(SP_PARM); row++) {
for (col = 0; col < screen_columns(SP_PARM); col++)
CurScreen(SP_PARM)->_line[row].text[col] = blank;
2000-07-09 10:46:08 +08:00
}
1998-03-01 12:21:12 +08:00
}
1997-05-15 12:00:00 +08:00
/*
* ClrBottom(total)
*
* Test if clearing the end of the screen would satisfy part of the
* screen-update. Do this by scanning backwards through the lines in the
* screen, checking if each is blank, and one or more are changed.
*/
2000-07-09 10:46:08 +08:00
static int
ClrBottom(NCURSES_SP_DCLx int total)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int row;
int col;
int top = total;
int last = min(screen_columns(SP_PARM), NewScreen(SP_PARM)->_maxx + 1);
NCURSES_CH_T blank = NewScreen(SP_PARM)->_line[total - 1].text[last - 1];
2000-07-09 10:46:08 +08:00
bool ok;
if (clr_eos && can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
2000-07-09 10:46:08 +08:00
for (row = total - 1; row >= 0; row--) {
for (col = 0, ok = TRUE; ok && col < last; col++) {
ok = (CharEq(NewScreen(SP_PARM)->_line[row].text[col], blank));
2000-07-09 10:46:08 +08:00
}
2000-10-21 12:42:11 +08:00
if (!ok)
break;
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
for (col = 0; ok && col < last; col++) {
ok = (CharEq(CurScreen(SP_PARM)->_line[row].text[col], blank));
2000-07-09 10:46:08 +08:00
}
2000-10-21 12:42:11 +08:00
if (!ok)
top = row;
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
/* don't use clr_eos for just one line if clr_eol available */
2004-02-09 10:15:26 +08:00
if (top < total) {
GoTo(NCURSES_SP_ARGx top, 0);
ClrToEOS(NCURSES_SP_ARGx blank);
if (SP_PARM->oldhash && SP_PARM->newhash) {
for (row = top; row < screen_lines(SP_PARM); row++)
SP_PARM->oldhash[row] = SP_PARM->newhash[row];
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
2004-02-09 10:15:26 +08:00
return top;
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
#if USE_XMC_SUPPORT
#if USE_WIDEC_SUPPORT
#define check_xmc_transition(sp, a, b) \
((((a)->attr ^ (b)->attr) & ~((a)->attr) & (sp)->_xmc_triggers) != 0)
#define xmc_turn_on(sp,a,b) check_xmc_transition(sp,&(a), &(b))
2002-10-13 11:35:53 +08:00
#else
#define xmc_turn_on(sp,a,b) ((((a)^(b)) & ~(a) & (sp)->_xmc_triggers) != 0)
2002-10-13 11:35:53 +08:00
#endif
#define xmc_new(sp,r,c) NewScreen(sp)->_line[r].text[c]
#define xmc_turn_off(sp,a,b) xmc_turn_on(sp,b,a)
2002-10-13 11:35:53 +08:00
#endif /* USE_XMC_SUPPORT */
1997-05-15 12:00:00 +08:00
/*
** TransformLine(lineno)
**
** Transform the given line in curscr to the one in newscr, using
** Insert/Delete Character if _nc_idcok && has_ic().
**
** firstChar = position of first different character in line
** oLastChar = position of last different character in old line
** nLastChar = position of last different character in new line
**
** move to firstChar
** overwrite chars up to min(oLastChar, nLastChar)
** if oLastChar < nLastChar
** insert newLine[oLastChar+1..nLastChar]
** else
** delete oLastChar - nLastChar spaces
*/
2000-07-09 10:46:08 +08:00
static void
TransformLine(NCURSES_SP_DCLx int const lineno)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int firstChar, oLastChar, nLastChar;
NCURSES_CH_T *newLine = NewScreen(SP_PARM)->_line[lineno].text;
NCURSES_CH_T *oldLine = CurScreen(SP_PARM)->_line[lineno].text;
2000-07-09 10:46:08 +08:00
int n;
bool attrchanged = FALSE;
TR(TRACE_UPDATE, (T_CALLED("TransformLine(%p, %d)"), SP_PARM, lineno));
2000-07-09 10:46:08 +08:00
/* copy new hash value to old one */
if (SP_PARM->oldhash && SP_PARM->newhash)
SP_PARM->oldhash[lineno] = SP_PARM->newhash[lineno];
2000-07-09 10:46:08 +08:00
/*
* If we have colors, there is the possibility of having two color pairs
* that display as the same colors. For instance, Lynx does this. Check
* for this case, and update the old line with the new line's colors when
* they are equivalent.
*/
if (SP_PARM->_coloron) {
2000-07-09 10:46:08 +08:00
int oldPair;
int newPair;
for (n = 0; n < screen_columns(SP_PARM); n++) {
2002-10-13 11:35:53 +08:00
if (!CharEq(newLine[n], oldLine[n])) {
2005-10-10 02:41:57 +08:00
oldPair = GetPair(oldLine[n]);
newPair = GetPair(newLine[n]);
if (oldPair != newPair
2000-07-09 10:46:08 +08:00
&& unColor(oldLine[n]) == unColor(newLine[n])) {
if (oldPair < SP_PARM->_pair_limit
&& newPair < SP_PARM->_pair_limit
&& (SP_PARM->_color_pairs[oldPair] ==
SP_PARM->_color_pairs[newPair])) {
2005-10-10 02:41:57 +08:00
SetPair(oldLine[n], GetPair(newLine[n]));
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (ceol_standout_glitch && clr_eol) {
1997-05-15 12:00:00 +08:00
firstChar = 0;
while (firstChar < screen_columns(SP_PARM)) {
2005-10-10 02:41:57 +08:00
if (!SameAttrOf(newLine[firstChar], oldLine[firstChar])) {
2000-07-09 10:46:08 +08:00
attrchanged = TRUE;
2004-02-09 10:15:26 +08:00
break;
}
2000-07-09 10:46:08 +08:00
firstChar++;
}
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
firstChar = 0;
if (attrchanged) { /* we may have to disregard the whole line */
GoTo(NCURSES_SP_ARGx lineno, firstChar);
ClrToEOL(NCURSES_SP_ARGx
ClrBlank(NCURSES_SP_ARGx
CurScreen(SP_PARM)), FALSE);
PutRange(NCURSES_SP_ARGx
oldLine, newLine, lineno, 0,
screen_columns(SP_PARM) - 1);
1998-03-01 12:21:12 +08:00
#if USE_XMC_SUPPORT
/*
* This is a very simple loop to paint characters which may have the
* magic cookie glitch embedded. It doesn't know much about video
* attributes which are continued from one line to the next. It
* assumes that we have filtered out requests for attribute changes
* that do not get mapped to blank positions.
*
* FIXME: we are not keeping track of where we put the cookies, so this
* will work properly only once, since we may overwrite a cookie in a
* following operation.
*/
2000-07-09 10:46:08 +08:00
} else if (magic_cookie_glitch > 0) {
GoTo(NCURSES_SP_ARGx lineno, firstChar);
for (n = 0; n < screen_columns(SP_PARM); n++) {
2000-07-09 10:46:08 +08:00
int m = n + magic_cookie_glitch;
/* check for turn-on:
* If we are writing an attributed blank, where the
* previous cell is not attributed.
*/
2002-10-13 11:35:53 +08:00
if (ISBLANK(newLine[n])
2000-07-09 10:46:08 +08:00
&& ((n > 0
&& xmc_turn_on(SP_PARM, newLine[n - 1], newLine[n]))
2000-07-09 10:46:08 +08:00
|| (n == 0
&& lineno > 0
&& xmc_turn_on(SP_PARM,
xmc_new(SP_PARM, lineno - 1,
screen_columns(SP_PARM) - 1),
2000-10-21 12:42:11 +08:00
newLine[n])))) {
2000-07-09 10:46:08 +08:00
n = m;
}
1998-03-01 12:21:12 +08:00
PutChar(NCURSES_SP_ARGx CHREF(newLine[n]));
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
/* check for turn-off:
* If we are writing an attributed non-blank, where the
* next cell is blank, and not attributed.
*/
2002-10-13 11:35:53 +08:00
if (!ISBLANK(newLine[n])
&& ((n + 1 < screen_columns(SP_PARM)
&& xmc_turn_off(SP_PARM, newLine[n], newLine[n + 1]))
|| (n + 1 >= screen_columns(SP_PARM)
&& lineno + 1 < screen_lines(SP_PARM)
&& xmc_turn_off(SP_PARM,
newLine[n],
xmc_new(SP_PARM, lineno + 1, 0))))) {
2000-07-09 10:46:08 +08:00
n = m;
}
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
}
1998-03-01 12:21:12 +08:00
#endif
2000-07-09 10:46:08 +08:00
} else {
2002-10-13 11:35:53 +08:00
NCURSES_CH_T blank;
2000-07-09 10:46:08 +08:00
/* it may be cheap to clear leading whitespace with clr_bol */
2004-02-09 10:15:26 +08:00
blank = newLine[0];
if (clr_bol && can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
2000-07-09 10:46:08 +08:00
int oFirstChar, nFirstChar;
for (oFirstChar = 0;
oFirstChar < screen_columns(SP_PARM);
oFirstChar++)
2002-10-13 11:35:53 +08:00
if (!CharEq(oldLine[oFirstChar], blank))
2000-07-09 10:46:08 +08:00
break;
for (nFirstChar = 0;
nFirstChar < screen_columns(SP_PARM);
nFirstChar++)
2002-10-13 11:35:53 +08:00
if (!CharEq(newLine[nFirstChar], blank))
2000-07-09 10:46:08 +08:00
break;
2004-02-09 10:15:26 +08:00
if (nFirstChar == oFirstChar) {
firstChar = nFirstChar;
/* find the first differing character */
while (firstChar < screen_columns(SP_PARM)
2004-02-09 10:15:26 +08:00
&& CharEq(newLine[firstChar], oldLine[firstChar]))
firstChar++;
} else if (oFirstChar > nFirstChar) {
firstChar = nFirstChar;
} else { /* oFirstChar < nFirstChar */
firstChar = oFirstChar;
if (SP_PARM->_el1_cost < nFirstChar - oFirstChar) {
if (nFirstChar >= screen_columns(SP_PARM)
&& SP_PARM->_el_cost <= SP_PARM->_el1_cost) {
GoTo(NCURSES_SP_ARGx lineno, 0);
UpdateAttrs(SP_PARM, blank);
2004-02-09 10:15:26 +08:00
TPUTS_TRACE("clr_eol");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx clr_eol);
2004-02-09 10:15:26 +08:00
} else {
GoTo(NCURSES_SP_ARGx lineno, nFirstChar - 1);
UpdateAttrs(SP_PARM, blank);
2004-02-09 10:15:26 +08:00
TPUTS_TRACE("clr_bol");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx clr_bol);
2004-02-09 10:15:26 +08:00
}
1997-05-15 12:00:00 +08:00
2004-02-09 10:15:26 +08:00
while (firstChar < nFirstChar)
oldLine[firstChar++] = blank;
}
2000-07-09 10:46:08 +08:00
}
2004-02-09 10:15:26 +08:00
} else {
/* find the first differing character */
while (firstChar < screen_columns(SP_PARM)
2004-02-09 10:15:26 +08:00
&& CharEq(newLine[firstChar], oldLine[firstChar]))
firstChar++;
2000-07-09 10:46:08 +08:00
}
2004-02-09 10:15:26 +08:00
/* if there wasn't one, we're done */
if (firstChar >= screen_columns(SP_PARM)) {
2005-10-10 02:41:57 +08:00
TR(TRACE_UPDATE, (T_RETURN("")));
2004-02-09 10:15:26 +08:00
return;
2005-10-10 02:41:57 +08:00
}
1997-05-15 12:00:00 +08:00
blank = newLine[screen_columns(SP_PARM) - 1];
1997-05-15 12:00:00 +08:00
if (!can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
2000-07-09 10:46:08 +08:00
/* find the last differing character */
nLastChar = screen_columns(SP_PARM) - 1;
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
while (nLastChar > firstChar
2002-10-13 11:35:53 +08:00
&& CharEq(newLine[nLastChar], oldLine[nLastChar]))
2000-07-09 10:46:08 +08:00
nLastChar--;
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (nLastChar >= firstChar) {
GoTo(NCURSES_SP_ARGx lineno, firstChar);
PutRange(NCURSES_SP_ARGx
oldLine,
newLine,
lineno,
firstChar,
nLastChar);
2000-07-09 10:46:08 +08:00
memcpy(oldLine + firstChar,
2000-10-21 12:42:11 +08:00
newLine + firstChar,
2002-10-13 11:35:53 +08:00
(nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T));
2000-07-09 10:46:08 +08:00
}
2005-10-10 02:41:57 +08:00
TR(TRACE_UPDATE, (T_RETURN("")));
2000-07-09 10:46:08 +08:00
return;
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
/* find last non-blank character on old line */
oLastChar = screen_columns(SP_PARM) - 1;
2002-10-13 11:35:53 +08:00
while (oLastChar > firstChar && CharEq(oldLine[oLastChar], blank))
2000-07-09 10:46:08 +08:00
oLastChar--;
/* find last non-blank character on new line */
nLastChar = screen_columns(SP_PARM) - 1;
2002-10-13 11:35:53 +08:00
while (nLastChar > firstChar && CharEq(newLine[nLastChar], blank))
2000-07-09 10:46:08 +08:00
nLastChar--;
if ((nLastChar == firstChar)
&& (SP_PARM->_el_cost < (oLastChar - nLastChar))) {
GoTo(NCURSES_SP_ARGx lineno, firstChar);
2002-10-13 11:35:53 +08:00
if (!CharEq(newLine[firstChar], blank))
PutChar(NCURSES_SP_ARGx CHREF(newLine[firstChar]));
ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
2000-07-09 10:46:08 +08:00
} else if ((nLastChar != oLastChar)
2002-10-13 11:35:53 +08:00
&& (!CharEq(newLine[nLastChar], oldLine[oLastChar])
|| !(SP_PARM->_nc_sp_idcok
&& NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG)))) {
GoTo(NCURSES_SP_ARGx lineno, firstChar);
if ((oLastChar - nLastChar) > SP_PARM->_el_cost) {
if (PutRange(NCURSES_SP_ARGx
oldLine,
newLine,
lineno,
firstChar,
nLastChar)) {
GoTo(NCURSES_SP_ARGx lineno, nLastChar + 1);
}
ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
2000-07-09 10:46:08 +08:00
} else {
n = max(nLastChar, oLastChar);
PutRange(NCURSES_SP_ARGx
oldLine,
newLine,
lineno,
firstChar,
n);
2000-07-09 10:46:08 +08:00
}
} else {
int nLastNonblank = nLastChar;
int oLastNonblank = oLastChar;
/* find the last characters that really differ */
2002-10-13 11:35:53 +08:00
/* can be -1 if no characters differ */
while (CharEq(newLine[nLastChar], oldLine[oLastChar])) {
/* don't split a wide char */
2005-10-10 02:41:57 +08:00
if (isWidecExt(newLine[nLastChar]) &&
2002-10-13 11:35:53 +08:00
!CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1]))
break;
nLastChar--;
oLastChar--;
if (nLastChar == -1 || oLastChar == -1)
2000-07-09 10:46:08 +08:00
break;
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
n = min(oLastChar, nLastChar);
if (n >= firstChar) {
GoTo(NCURSES_SP_ARGx lineno, firstChar);
PutRange(NCURSES_SP_ARGx
oldLine,
newLine,
lineno,
firstChar,
n);
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (oLastChar < nLastChar) {
int m = max(nLastNonblank, oLastNonblank);
2005-10-10 02:41:57 +08:00
#if USE_WIDEC_SUPPORT
while (isWidecExt(newLine[n + 1]) && n) {
--n;
--oLastChar;
}
#endif
GoTo(NCURSES_SP_ARGx lineno, n + 1);
2005-10-10 02:41:57 +08:00
if ((nLastChar < nLastNonblank)
|| InsCharCost(SP_PARM, nLastChar - oLastChar) > (m - n)) {
PutRange(NCURSES_SP_ARGx
oldLine,
newLine,
lineno,
n + 1,
m);
2000-07-09 10:46:08 +08:00
} else {
InsStr(NCURSES_SP_ARGx &newLine[n + 1], nLastChar - oLastChar);
2000-07-09 10:46:08 +08:00
}
} else if (oLastChar > nLastChar) {
GoTo(NCURSES_SP_ARGx lineno, n + 1);
if (DelCharCost(SP_PARM, oLastChar - nLastChar)
> SP_PARM->_el_cost + nLastNonblank - (n + 1)) {
if (PutRange(NCURSES_SP_ARGx oldLine, newLine, lineno,
2000-10-21 12:42:11 +08:00
n + 1, nLastNonblank))
GoTo(NCURSES_SP_ARGx lineno, nLastNonblank + 1);
ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
2000-07-09 10:46:08 +08:00
} else {
/*
* The delete-char sequence will
* effectively shift in blanks from the
* right margin of the screen. Ensure
* that they are the right color by
* setting the video attributes from
* the last character on the row.
*/
UpdateAttrs(SP_PARM, blank);
DelChar(NCURSES_SP_ARGx oLastChar - nLastChar);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
/* update the code's internal representation */
if (screen_columns(SP_PARM) > firstChar)
2000-07-09 10:46:08 +08:00
memcpy(oldLine + firstChar,
2000-10-21 12:42:11 +08:00
newLine + firstChar,
(screen_columns(SP_PARM) - firstChar) * sizeof(NCURSES_CH_T));
2005-10-10 02:41:57 +08:00
TR(TRACE_UPDATE, (T_RETURN("")));
return;
1997-05-15 12:00:00 +08:00
}
/*
1998-03-01 12:21:12 +08:00
** ClearScreen(blank)
1997-05-15 12:00:00 +08:00
**
** Clear the physical screen and put cursor at home
**
*/
2000-07-09 10:46:08 +08:00
static void
ClearScreen(NCURSES_SP_DCLx NCURSES_CH_T blank)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int i, j;
bool fast_clear = (clear_screen || clr_eos || clr_eol);
2000-10-21 12:42:11 +08:00
TR(TRACE_UPDATE, ("ClearScreen() called"));
1997-05-15 12:00:00 +08:00
2000-10-21 12:42:11 +08:00
#if NCURSES_EXT_FUNCS
if (SP_PARM->_coloron
&& !SP_PARM->_default_color) {
NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx
GET_SCREEN_PAIR(SP_PARM),
0,
FALSE,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
if (!back_color_erase) {
fast_clear = FALSE;
}
}
#endif
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (fast_clear) {
1997-05-15 12:00:00 +08:00
if (clear_screen) {
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
TPUTS_TRACE("clear_screen");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx clear_screen);
SP_PARM->_cursrow = SP_PARM->_curscol = 0;
position_check(SP_PARM,
SP_PARM->_cursrow,
SP_PARM->_curscol,
"ClearScreen");
1997-05-15 12:00:00 +08:00
} else if (clr_eos) {
SP_PARM->_cursrow = SP_PARM->_curscol = -1;
GoTo(NCURSES_SP_ARGx 0, 0);
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
TPUTS_TRACE("clr_eos");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
clr_eos,
screen_lines(SP_PARM),
NCURSES_SP_NAME(_nc_outch));
1997-05-15 12:00:00 +08:00
} else if (clr_eol) {
SP_PARM->_cursrow = SP_PARM->_curscol = -1;
UpdateAttrs(SP_PARM, blank);
for (i = 0; i < screen_lines(SP_PARM); i++) {
GoTo(NCURSES_SP_ARGx i, 0);
2000-07-09 10:46:08 +08:00
TPUTS_TRACE("clr_eol");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx clr_eol);
2000-07-09 10:46:08 +08:00
}
GoTo(NCURSES_SP_ARGx 0, 0);
1998-03-01 12:21:12 +08:00
}
2000-07-09 10:46:08 +08:00
} else {
UpdateAttrs(SP_PARM, blank);
for (i = 0; i < screen_lines(SP_PARM); i++) {
GoTo(NCURSES_SP_ARGx i, 0);
for (j = 0; j < screen_columns(SP_PARM); j++)
PutChar(NCURSES_SP_ARGx CHREF(blank));
1997-05-15 12:00:00 +08:00
}
GoTo(NCURSES_SP_ARGx 0, 0);
2000-07-09 10:46:08 +08:00
}
1998-03-01 12:21:12 +08:00
for (i = 0; i < screen_lines(SP_PARM); i++) {
for (j = 0; j < screen_columns(SP_PARM); j++)
CurScreen(SP_PARM)->_line[i].text[j] = blank;
2000-07-09 10:46:08 +08:00
}
2000-10-21 12:42:11 +08:00
TR(TRACE_UPDATE, ("screen cleared"));
1997-05-15 12:00:00 +08:00
}
/*
** InsStr(line, count)
**
** Insert the count characters pointed to by line.
**
*/
2000-07-09 10:46:08 +08:00
static void
InsStr(NCURSES_SP_DCLx NCURSES_CH_T * line, int count)
1997-05-15 12:00:00 +08:00
{
TR(TRACE_UPDATE, ("InsStr(%p, %p,%d) called", SP_PARM, line, count));
2000-07-09 10:46:08 +08:00
/* Prefer parm_ich as it has the smallest cost - no need to shift
* the whole line on each character. */
/* The order must match that of InsCharCost. */
if (parm_ich) {
TPUTS_TRACE("parm_ich");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_1(parm_ich, count),
count,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
while (count) {
PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
2000-07-09 10:46:08 +08:00
line++;
count--;
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
} else if (enter_insert_mode && exit_insert_mode) {
TPUTS_TRACE("enter_insert_mode");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx enter_insert_mode);
2000-07-09 10:46:08 +08:00
while (count) {
PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
2000-07-09 10:46:08 +08:00
if (insert_padding) {
TPUTS_TRACE("insert_padding");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx insert_padding);
2000-07-09 10:46:08 +08:00
}
line++;
count--;
}
TPUTS_TRACE("exit_insert_mode");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx exit_insert_mode);
2000-07-09 10:46:08 +08:00
} else {
while (count) {
TPUTS_TRACE("insert_character");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx insert_character);
PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
2000-07-09 10:46:08 +08:00
if (insert_padding) {
TPUTS_TRACE("insert_padding");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx insert_padding);
2000-07-09 10:46:08 +08:00
}
line++;
count--;
}
}
position_check(SP_PARM, SP_PARM->_cursrow, SP_PARM->_curscol, "InsStr");
1997-05-15 12:00:00 +08:00
}
/*
** DelChar(count)
**
** Delete count characters at current position
**
*/
2000-07-09 10:46:08 +08:00
static void
DelChar(NCURSES_SP_DCLx int count)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int n;
1997-05-15 12:00:00 +08:00
TR(TRACE_UPDATE, ("DelChar(%p, %d) called, position = (%ld,%ld)",
SP_PARM, count,
(long) NewScreen(SP_PARM)->_cury,
(long) NewScreen(SP_PARM)->_curx));
2000-07-09 10:46:08 +08:00
if (parm_dch) {
TPUTS_TRACE("parm_dch");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_1(parm_dch, count),
count,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
} else {
for (n = 0; n < count; n++) {
TPUTS_TRACE("delete_character");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx delete_character);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
}
1997-05-15 12:00:00 +08:00
}
1998-03-01 12:21:12 +08:00
/*
* Physical-scrolling support
*
* This code was adapted from Keith Bostic's hardware scrolling
* support for 4.4BSD curses. I (esr) translated it to use terminfo
* capabilities, narrowed the call interface slightly, and cleaned
* up some convoluted tests. I also added support for the memory_above
* memory_below, and non_dest_scroll_region capabilities.
*
* For this code to work, we must have either
* change_scroll_region and scroll forward/reverse commands, or
* insert and delete line capabilities.
* When the scrolling region has been set, the cursor has to
* be at the last line of the region to make the scroll up
* happen, or on the first line of region to scroll down.
*
* This code makes one aesthetic decision in the opposite way from
* BSD curses. BSD curses preferred pairs of il/dl operations
* over scrolls, allegedly because il/dl looked faster. We, on
* the other hand, prefer scrolls because (a) they're just as fast
* on many terminals and (b) using them avoids bouncing an
* unchanged bottom section of the screen up and down, which is
* visually nasty.
*
* (lav): added more cases, used dl/il when bot==maxy and in csr case.
*
* I used assumption that capabilities il/il1/dl/dl1 work inside
* changed scroll region not shifting screen contents outside of it.
* If there are any terminals behaving different way, it would be
* necessary to add some conditions to scroll_csr_forward/backward.
*/
/* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */
2000-07-09 10:46:08 +08:00
static int
scroll_csr_forward(NCURSES_SP_DCLx
int n,
int top,
int bot,
int miny,
int maxy,
NCURSES_CH_T blank)
1998-03-01 12:21:12 +08:00
{
2002-10-13 11:35:53 +08:00
int i;
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
if (n == 1 && scroll_forward && top == miny && bot == maxy) {
GoTo(NCURSES_SP_ARGx bot, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("scroll_forward");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx scroll_forward);
2000-07-09 10:46:08 +08:00
} else if (n == 1 && delete_line && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("delete_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx delete_line);
2000-07-09 10:46:08 +08:00
} else if (parm_index && top == miny && bot == maxy) {
GoTo(NCURSES_SP_ARGx bot, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("parm_index");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_2(parm_index, n, 0),
n,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
} else if (parm_delete_line && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("parm_delete_line");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_2(parm_delete_line, n, 0),
n,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
} else if (scroll_forward && top == miny && bot == maxy) {
GoTo(NCURSES_SP_ARGx bot, 0);
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
for (i = 0; i < n; i++) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("scroll_forward");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx scroll_forward);
1998-03-01 12:21:12 +08:00
}
2000-07-09 10:46:08 +08:00
} else if (delete_line && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
for (i = 0; i < n; i++) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("delete_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx delete_line);
1998-03-01 12:21:12 +08:00
}
2000-07-09 10:46:08 +08:00
} else
1998-03-01 12:21:12 +08:00
return ERR;
2000-10-21 12:42:11 +08:00
#if NCURSES_EXT_FUNCS
if (FILL_BCE(SP_PARM)) {
2002-10-13 11:35:53 +08:00
int j;
2000-07-09 10:46:08 +08:00
for (i = 0; i < n; i++) {
GoTo(NCURSES_SP_ARGx bot - i, 0);
for (j = 0; j < screen_columns(SP_PARM); j++)
PutChar(NCURSES_SP_ARGx CHREF(blank));
2000-07-09 10:46:08 +08:00
}
}
#endif
1998-03-01 12:21:12 +08:00
return OK;
}
/* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */
/* n > 0 */
2000-07-09 10:46:08 +08:00
static int
scroll_csr_backward(NCURSES_SP_DCLx
int n,
int top,
int bot,
int miny,
int maxy,
2002-10-13 11:35:53 +08:00
NCURSES_CH_T blank)
1998-03-01 12:21:12 +08:00
{
2002-10-13 11:35:53 +08:00
int i;
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
if (n == 1 && scroll_reverse && top == miny && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("scroll_reverse");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx scroll_reverse);
2000-07-09 10:46:08 +08:00
} else if (n == 1 && insert_line && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("insert_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx insert_line);
2000-07-09 10:46:08 +08:00
} else if (parm_rindex && top == miny && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("parm_rindex");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_2(parm_rindex, n, 0),
n,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
} else if (parm_insert_line && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("parm_insert_line");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_2(parm_insert_line, n, 0),
n,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
} else if (scroll_reverse && top == miny && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
for (i = 0; i < n; i++) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("scroll_reverse");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx scroll_reverse);
1998-03-01 12:21:12 +08:00
}
2000-07-09 10:46:08 +08:00
} else if (insert_line && bot == maxy) {
GoTo(NCURSES_SP_ARGx top, 0);
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
for (i = 0; i < n; i++) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("insert_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx insert_line);
1998-03-01 12:21:12 +08:00
}
2000-07-09 10:46:08 +08:00
} else
1998-03-01 12:21:12 +08:00
return ERR;
2000-10-21 12:42:11 +08:00
#if NCURSES_EXT_FUNCS
if (FILL_BCE(SP_PARM)) {
2002-10-13 11:35:53 +08:00
int j;
2000-07-09 10:46:08 +08:00
for (i = 0; i < n; i++) {
GoTo(NCURSES_SP_ARGx top + i, 0);
for (j = 0; j < screen_columns(SP_PARM); j++)
PutChar(NCURSES_SP_ARGx CHREF(blank));
2000-07-09 10:46:08 +08:00
}
}
#endif
1998-03-01 12:21:12 +08:00
return OK;
}
/* scroll by using delete_line at del and insert_line at ins */
/* n > 0 */
2000-07-09 10:46:08 +08:00
static int
scroll_idl(NCURSES_SP_DCLx int n, int del, int ins, NCURSES_CH_T blank)
1998-03-01 12:21:12 +08:00
{
int i;
2000-07-09 10:46:08 +08:00
if (!((parm_delete_line || delete_line) && (parm_insert_line || insert_line)))
1998-03-01 12:21:12 +08:00
return ERR;
GoTo(NCURSES_SP_ARGx del, 0);
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
if (n == 1 && delete_line) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("delete_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx delete_line);
2000-07-09 10:46:08 +08:00
} else if (parm_delete_line) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("parm_delete_line");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_2(parm_delete_line, n, 0),
n,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
} else { /* if (delete_line) */
for (i = 0; i < n; i++) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("delete_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx delete_line);
1998-03-01 12:21:12 +08:00
}
}
GoTo(NCURSES_SP_ARGx ins, 0);
UpdateAttrs(SP_PARM, blank);
2000-07-09 10:46:08 +08:00
if (n == 1 && insert_line) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("insert_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx insert_line);
2000-07-09 10:46:08 +08:00
} else if (parm_insert_line) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("parm_insert_line");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
TPARM_2(parm_insert_line, n, 0),
n,
NCURSES_SP_NAME(_nc_outch));
2000-07-09 10:46:08 +08:00
} else { /* if (insert_line) */
for (i = 0; i < n; i++) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("insert_line");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx insert_line);
1998-03-01 12:21:12 +08:00
}
}
return OK;
}
2004-02-09 10:15:26 +08:00
/*
* Note: some terminals require the cursor to be within the scrolling margins
* before setting them. Generally, the cursor must be at the appropriate end
* of the scrolling margins when issuing an indexing operation (it is not
* apparent whether it must also be at the left margin; we do this just to be
* safe). To make the related cursor movement a little faster, we use the
* save/restore cursor capabilities if the terminal has them.
*/
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_DCLx
int n,
int top,
int bot,
int maxy)
1998-03-01 12:21:12 +08:00
/* scroll region from top to bot by n lines */
{
NCURSES_CH_T blank;
1998-03-01 12:21:12 +08:00
int i;
2000-07-09 10:46:08 +08:00
bool cursor_saved = FALSE;
1998-03-01 12:21:12 +08:00
int res;
TR(TRACE_MOVE, ("_nc_scrolln(%p, %d, %d, %d, %d)", SP_PARM, n, top, bot, maxy));
if (!IsValidScreen(SP_PARM))
return (ERR);
blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
1998-03-01 12:21:12 +08:00
#if USE_XMC_SUPPORT
/*
* If we scroll, we might remove a cookie.
*/
if (magic_cookie_glitch > 0) {
return (ERR);
}
#endif
2000-07-09 10:46:08 +08:00
if (n > 0) { /* scroll up (forward) */
1998-03-01 12:21:12 +08:00
/*
* Explicitly clear if stuff pushed off top of region might
* be saved by the terminal.
*/
res = scroll_csr_forward(NCURSES_SP_ARGx n, top, bot, 0, maxy, blank);
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
if (res == ERR && change_scroll_region) {
if ((((n == 1 && scroll_forward) || parm_index)
&& (SP_PARM->_cursrow == bot || SP_PARM->_cursrow == bot - 1))
2000-07-09 10:46:08 +08:00
&& save_cursor && restore_cursor) {
cursor_saved = TRUE;
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("save_cursor");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx save_cursor);
1998-03-01 12:21:12 +08:00
}
TPUTS_TRACE("change_scroll_region");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx
TPARM_2(change_scroll_region, top, bot));
2000-07-09 10:46:08 +08:00
if (cursor_saved) {
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("restore_cursor");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx restore_cursor);
2000-07-09 10:46:08 +08:00
} else {
SP_PARM->_cursrow = SP_PARM->_curscol = -1;
1998-03-01 12:21:12 +08:00
}
res = scroll_csr_forward(NCURSES_SP_ARGx n, top, bot, top, bot, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("change_scroll_region");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx
TPARM_2(change_scroll_region, 0, maxy));
SP_PARM->_cursrow = SP_PARM->_curscol = -1;
1998-03-01 12:21:12 +08:00
}
if (res == ERR && SP_PARM->_nc_sp_idlok)
res = scroll_idl(NCURSES_SP_ARGx n, top, bot - n + 1, blank);
2000-10-21 12:42:11 +08:00
1998-03-01 12:21:12 +08:00
/*
2000-10-21 12:42:11 +08:00
* Clear the newly shifted-in text.
1998-03-01 12:21:12 +08:00
*/
2000-10-21 12:42:11 +08:00
if (res != ERR
&& (non_dest_scroll_region || (memory_below && bot == maxy))) {
2006-12-18 12:32:42 +08:00
static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
2000-07-09 10:46:08 +08:00
if (bot == maxy && clr_eos) {
GoTo(NCURSES_SP_ARGx bot - n + 1, 0);
ClrToEOS(NCURSES_SP_ARGx blank2);
2000-10-21 12:42:11 +08:00
} else {
for (i = 0; i < n; i++) {
GoTo(NCURSES_SP_ARGx bot - i, 0);
ClrToEOL(NCURSES_SP_ARGx blank2, FALSE);
1998-03-01 12:21:12 +08:00
}
}
}
2000-10-21 12:42:11 +08:00
} else { /* (n < 0) - scroll down (backward) */
res = scroll_csr_backward(NCURSES_SP_ARGx -n, top, bot, 0, maxy, blank);
1998-03-01 12:21:12 +08:00
2000-07-09 10:46:08 +08:00
if (res == ERR && change_scroll_region) {
if (top != 0
&& (SP_PARM->_cursrow == top ||
SP_PARM->_cursrow == top - 1)
2000-07-09 10:46:08 +08:00
&& save_cursor && restore_cursor) {
cursor_saved = TRUE;
1999-10-24 12:32:42 +08:00
TPUTS_TRACE("save_cursor");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx save_cursor);
1998-03-01 12:21:12 +08:00
}
TPUTS_TRACE("change_scroll_region");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx
TPARM_2(change_scroll_region, top, bot));
2000-07-09 10:46:08 +08:00
if (cursor_saved) {
1999-10-24 12:32:42 +08:00
TPUTS_TRACE("restore_cursor");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx restore_cursor);
2000-07-09 10:46:08 +08:00
} else {
SP_PARM->_cursrow = SP_PARM->_curscol = -1;
1998-03-01 12:21:12 +08:00
}
res = scroll_csr_backward(NCURSES_SP_ARGx
-n, top, bot, top, bot, blank);
1998-03-01 12:21:12 +08:00
TPUTS_TRACE("change_scroll_region");
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx
TPARM_2(change_scroll_region, 0, maxy));
SP_PARM->_cursrow = SP_PARM->_curscol = -1;
1998-03-01 12:21:12 +08:00
}
if (res == ERR && SP_PARM->_nc_sp_idlok)
res = scroll_idl(NCURSES_SP_ARGx -n, bot + n + 1, top, blank);
2000-10-21 12:42:11 +08:00
/*
* Clear the newly shifted-in text.
*/
if (res != ERR
&& (non_dest_scroll_region || (memory_above && top == 0))) {
2006-12-18 12:32:42 +08:00
static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
2000-10-21 12:42:11 +08:00
for (i = 0; i < -n; i++) {
GoTo(NCURSES_SP_ARGx i + top, 0);
ClrToEOL(NCURSES_SP_ARGx blank2, FALSE);
2000-10-21 12:42:11 +08:00
}
}
1998-03-01 12:21:12 +08:00
}
if (res == ERR)
2000-07-09 10:46:08 +08:00
return (ERR);
1998-03-01 12:21:12 +08:00
_nc_scroll_window(CurScreen(SP_PARM), n, top, bot, blank);
1998-03-01 12:21:12 +08:00
1999-10-24 12:32:42 +08:00
/* shift hash values too - they can be reused */
NCURSES_SP_NAME(_nc_scroll_oldhash) (NCURSES_SP_ARGx n, top, bot);
1999-10-24 12:32:42 +08:00
2000-07-09 10:46:08 +08:00
return (OK);
1998-03-01 12:21:12 +08:00
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
_nc_scrolln(int n, int top, int bot, int maxy)
{
return NCURSES_SP_NAME(_nc_scrolln) (CURRENT_SCREEN, n, top, bot, maxy);
}
#endif
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_DCL0)
1998-03-01 12:21:12 +08:00
{
assert(SP_PARM);
1998-03-01 12:21:12 +08:00
/* make sure terminal is in a sane known state */
SetAttr(SCREEN_ATTRS(SP_PARM), A_NORMAL);
NewScreen(SP_PARM)->_clear = TRUE;
1998-03-01 12:21:12 +08:00
2002-10-13 11:35:53 +08:00
/* reset color pairs and definitions */
if (SP_PARM->_coloron || SP_PARM->_color_defs)
NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
2002-10-13 11:35:53 +08:00
/* restore user-defined colors, if any */
if (SP_PARM->_color_defs < 0) {
2002-10-13 11:35:53 +08:00
int n;
SP_PARM->_color_defs = -(SP_PARM->_color_defs);
for (n = 0; n < SP_PARM->_color_defs; ++n) {
if (SP_PARM->_color_table[n].init) {
NCURSES_SP_NAME(init_color) (NCURSES_SP_ARGx n,
SP_PARM->_color_table[n].r,
SP_PARM->_color_table[n].g,
SP_PARM->_color_table[n].b);
2002-10-13 11:35:53 +08:00
}
}
}
1998-03-01 12:21:12 +08:00
if (exit_attribute_mode)
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx exit_attribute_mode);
2000-07-09 10:46:08 +08:00
else {
1998-03-01 12:21:12 +08:00
/* turn off attributes */
if (exit_alt_charset_mode)
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx exit_alt_charset_mode);
1998-03-01 12:21:12 +08:00
if (exit_standout_mode)
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx exit_standout_mode);
1998-03-01 12:21:12 +08:00
if (exit_underline_mode)
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx exit_underline_mode);
1998-03-01 12:21:12 +08:00
}
if (exit_insert_mode)
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx exit_insert_mode);
1998-03-01 12:21:12 +08:00
if (enter_am_mode && exit_am_mode)
NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx
(auto_right_margin
? enter_am_mode
: exit_am_mode));
1998-03-01 12:21:12 +08:00
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_screen_resume(void)
{
NCURSES_SP_NAME(_nc_screen_resume) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_screen_init) (NCURSES_SP_DCL0)
{
NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
}
#if NCURSES_SP_FUNCS
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(void)
2000-07-09 10:46:08 +08:00
_nc_screen_init(void)
1998-03-01 12:21:12 +08:00
{
NCURSES_SP_NAME(_nc_screen_init) (CURRENT_SCREEN);
1998-03-01 12:21:12 +08:00
}
#endif
1998-03-01 12:21:12 +08:00
/* wrap up screen handling */
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_screen_wrap) (NCURSES_SP_DCL0)
1998-03-01 12:21:12 +08:00
{
if (SP_PARM == 0)
return;
UpdateAttrs(SP_PARM, normal);
2000-10-21 12:42:11 +08:00
#if NCURSES_EXT_FUNCS
if (SP_PARM->_coloron
&& !SP_PARM->_default_color) {
2006-12-18 12:32:42 +08:00
static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
SP_PARM->_default_color = TRUE;
NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx
-1,
0,
FALSE,
NCURSES_SP_NAME(_nc_outch));
SP_PARM->_default_color = FALSE;
2000-07-09 10:46:08 +08:00
NCURSES_SP_NAME(mvcur) (NCURSES_SP_ARGx
SP_PARM->_cursrow,
SP_PARM->_curscol,
screen_lines(SP_PARM) - 1,
0);
2000-07-09 10:46:08 +08:00
ClrToEOL(NCURSES_SP_ARGx blank, TRUE);
2000-07-09 10:46:08 +08:00
}
#endif
if (SP_PARM->_color_defs) {
NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
2002-10-13 11:35:53 +08:00
}
1998-03-01 12:21:12 +08:00
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_screen_wrap(void)
{
NCURSES_SP_NAME(_nc_screen_wrap) (CURRENT_SCREEN);
}
#endif
1998-03-01 12:21:12 +08:00
#if USE_XMC_SUPPORT
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_do_xmc_glitch) (NCURSES_SP_DCLx attr_t previous)
1998-03-01 12:21:12 +08:00
{
if (SP_PARM != 0) {
attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP_PARM)));
while (chg != 0) {
if (chg & 1) {
SP_PARM->_curscol += magic_cookie_glitch;
if (SP_PARM->_curscol >= SP_PARM->_columns)
wrap_cursor(NCURSES_SP_ARG);
TR(TRACE_UPDATE, ("bumped to %d,%d after cookie",
SP_PARM->_cursrow, SP_PARM->_curscol));
}
chg >>= 1;
1998-03-01 12:21:12 +08:00
}
2000-07-09 10:46:08 +08:00
}
1998-03-01 12:21:12 +08:00
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_do_xmc_glitch(attr_t previous)
{
NCURSES_SP_NAME(_nc_do_xmc_glitch) (CURRENT_SCREEN, previous);
}
#endif
1998-03-01 12:21:12 +08:00
#endif /* USE_XMC_SUPPORT */