summaryrefslogtreecommitdiffstats
path: root/contrib/less/screen.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/less/screen.c')
-rw-r--r--contrib/less/screen.c229
1 files changed, 103 insertions, 126 deletions
diff --git a/contrib/less/screen.c b/contrib/less/screen.c
index 8a8f6a3..48afdbf 100644
--- a/contrib/less/screen.c
+++ b/contrib/less/screen.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 Mark Nudelman
*
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
@@ -38,11 +38,12 @@ extern int fd0;
#else
-#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
-#include <termios.h>
-#if HAVE_SYS_IOCTL_H && !defined(TIOCGWINSZ)
+#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
+
+#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
+#include <termios.h>
#else
#if HAVE_TERMIO_H
#include <termio.h>
@@ -52,9 +53,6 @@ extern int fd0;
#else
#include <sgtty.h>
#endif
-#if HAVE_SYS_IOCTL_H && (defined(TIOCGWINSZ) || defined(TCGETA) || defined(TIOCGETP) || defined(WIOCGETD))
-#include <sys/ioctl.h>
-#endif
#endif
#endif
@@ -189,7 +187,9 @@ static int init_done = 0;
public int auto_wrap; /* Terminal does \r\n when write past margin */
public int ignaw; /* Terminal ignores \n immediately after wrap */
-public int erase_char, kill_char; /* The user's erase and line-kill chars */
+public int erase_char; /* The user's erase char */
+public int erase2_char; /* The user's other erase char */
+public int kill_char; /* The user's line-kill char */
public int werase_char; /* The user's word-erase char */
public int sc_width, sc_height; /* Height & width of screen */
public int bo_s_width, bo_e_width; /* Printing width of boldface seq */
@@ -202,6 +202,7 @@ public int clear_bg; /* Clear fills with background color */
public int missing_cap = 0; /* Some capability is missing */
static int attrmode = AT_NORMAL;
+extern int binattr;
#if !MSDOS_COMPILER
static char *cheaper();
@@ -230,6 +231,7 @@ extern int sigs;
extern int wscroll;
extern int screen_trashed;
extern int tty;
+extern int top_scroll;
#if HILITE_SEARCH
extern int hilite_search;
#endif
@@ -257,6 +259,7 @@ raw_mode(on)
if (on == curr_on)
return;
+ erase2_char = '\b'; /* in case OS doesn't know about erase2 */
#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
{
struct termios s;
@@ -339,6 +342,9 @@ raw_mode(on)
}
#endif
erase_char = s.c_cc[VERASE];
+#ifdef VERASE2
+ erase2_char = s.c_cc[VERASE2];
+#endif
kill_char = s.c_cc[VKILL];
#ifdef VWERASE
werase_char = s.c_cc[VWERASE];
@@ -1201,7 +1207,7 @@ get_term()
if (below_mem && (sc_eos_clear == NULL || *sc_eos_clear == '\0'))
{
missing_cap = 1;
- sc_eol_clear = "";
+ sc_eos_clear = "";
}
sc_clear = ltgetstr("cl", &sp);
@@ -1505,6 +1511,19 @@ init()
tputs(sc_init, sc_height, putchr);
if (!no_keypad)
tputs(sc_s_keypad, sc_height, putchr);
+ if (top_scroll)
+ {
+ int i;
+
+ /*
+ * This is nice to terminals with no alternate screen,
+ * but with saved scrolled-off-the-top lines. This way,
+ * no previous line is lost, but we start with a whole
+ * screen to ourself.
+ */
+ for (i = 1; i < sc_height; i++)
+ putchr('\n');
+ }
#else
#if MSDOS_COMPILER==WIN32C
if (!no_init)
@@ -1846,12 +1865,12 @@ create_flash()
videopages = w.numvideopages;
if (videopages < 2)
{
- so_enter();
- so_exit();
+ at_enter(AT_STANDOUT);
+ at_exit();
} else
{
_setactivepage(1);
- so_enter();
+ at_enter(AT_STANDOUT);
blanks = (char *) ecalloc(w.numtextcols, sizeof(char));
for (col = 0; col < w.numtextcols; col++)
blanks[col] = ' ';
@@ -1860,7 +1879,7 @@ create_flash()
_setactivepage(0);
_setvisualpage(0);
free(blanks);
- so_exit();
+ at_exit();
}
#else
#if MSDOS_COMPILER==BORLANDC
@@ -2090,153 +2109,111 @@ clear_bot()
* cleared area with the current attribute.
*/
lower_left();
- switch (attrmode)
- {
- case AT_STANDOUT:
- so_exit();
- clear_eol_bot();
- so_enter();
- break;
- case AT_UNDERLINE:
- ul_exit();
- clear_eol_bot();
- ul_enter();
- break;
- case AT_BOLD:
- bo_exit();
- clear_eol_bot();
- bo_enter();
- break;
- case AT_BLINK:
- bl_exit();
+ if (attrmode == AT_NORMAL)
clear_eol_bot();
- bl_enter();
- break;
- default:
+ else
+ {
+ int saved_attrmode = attrmode;
+
+ at_exit();
clear_eol_bot();
- break;
+ at_enter(saved_attrmode);
}
}
-/*
- * Begin "standout" (bold, underline, or whatever).
- */
public void
-so_enter()
+at_enter(attr)
+ int attr;
{
-#if !MSDOS_COMPILER
- tputs(sc_s_in, 1, putchr);
-#else
- flush();
- SETCOLORS(so_fg_color, so_bg_color);
-#endif
- attrmode = AT_STANDOUT;
-}
+ attr = apply_at_specials(attr);
-/*
- * End "standout".
- */
- public void
-so_exit()
-{
#if !MSDOS_COMPILER
- tputs(sc_s_out, 1, putchr);
+ /* The one with the most priority is last. */
+ if (attr & AT_UNDERLINE)
+ tputs(sc_u_in, 1, putchr);
+ if (attr & AT_BOLD)
+ tputs(sc_b_in, 1, putchr);
+ if (attr & AT_BLINK)
+ tputs(sc_bl_in, 1, putchr);
+ if (attr & AT_STANDOUT)
+ tputs(sc_s_in, 1, putchr);
#else
flush();
- SETCOLORS(nm_fg_color, nm_bg_color);
+ /* The one with the most priority is first. */
+ if (attr & AT_STANDOUT)
+ {
+ SETCOLORS(so_fg_color, so_bg_color);
+ } else if (attr & AT_BLINK)
+ {
+ SETCOLORS(bl_fg_color, bl_bg_color);
+ }
+ else if (attr & AT_BOLD)
+ {
+ SETCOLORS(bo_fg_color, bo_bg_color);
+ }
+ else if (attr & AT_UNDERLINE)
+ {
+ SETCOLORS(ul_fg_color, ul_bg_color);
+ }
#endif
- attrmode = AT_NORMAL;
-}
-/*
- * Begin "underline" (hopefully real underlining,
- * otherwise whatever the terminal provides).
- */
- public void
-ul_enter()
-{
-#if !MSDOS_COMPILER
- tputs(sc_u_in, 1, putchr);
-#else
- flush();
- SETCOLORS(ul_fg_color, ul_bg_color);
-#endif
- attrmode = AT_UNDERLINE;
+ attrmode = attr;
}
-/*
- * End "underline".
- */
public void
-ul_exit()
+at_exit()
{
#if !MSDOS_COMPILER
- tputs(sc_u_out, 1, putchr);
+ /* Undo things in the reverse order we did them. */
+ if (attrmode & AT_STANDOUT)
+ tputs(sc_s_out, 1, putchr);
+ if (attrmode & AT_BLINK)
+ tputs(sc_bl_out, 1, putchr);
+ if (attrmode & AT_BOLD)
+ tputs(sc_b_out, 1, putchr);
+ if (attrmode & AT_UNDERLINE)
+ tputs(sc_u_out, 1, putchr);
#else
flush();
SETCOLORS(nm_fg_color, nm_bg_color);
#endif
+
attrmode = AT_NORMAL;
}
-/*
- * Begin "bold"
- */
public void
-bo_enter()
+at_switch(attr)
+ int attr;
{
-#if !MSDOS_COMPILER
- tputs(sc_b_in, 1, putchr);
-#else
- flush();
- SETCOLORS(bo_fg_color, bo_bg_color);
-#endif
- attrmode = AT_BOLD;
+ if (apply_at_specials(attr) != attrmode)
+ {
+ at_exit();
+ at_enter(attr);
+ }
}
-/*
- * End "bold".
- */
- public void
-bo_exit()
+ public int
+is_at_equiv(attr1, attr2)
+ int attr1;
+ int attr2;
{
-#if !MSDOS_COMPILER
- tputs(sc_b_out, 1, putchr);
-#else
- flush();
- SETCOLORS(nm_fg_color, nm_bg_color);
-#endif
- attrmode = AT_NORMAL;
-}
+ attr1 = apply_at_specials(attr1);
+ attr2 = apply_at_specials(attr2);
-/*
- * Begin "blink"
- */
- public void
-bl_enter()
-{
-#if !MSDOS_COMPILER
- tputs(sc_bl_in, 1, putchr);
-#else
- flush();
- SETCOLORS(bl_fg_color, bl_bg_color);
-#endif
- attrmode = AT_BLINK;
+ return (attr1 == attr2);
}
-/*
- * End "blink".
- */
- public void
-bl_exit()
+ public int
+apply_at_specials(attr)
+ int attr;
{
-#if !MSDOS_COMPILER
- tputs(sc_bl_out, 1, putchr);
-#else
- flush();
- SETCOLORS(nm_fg_color, nm_bg_color);
-#endif
- attrmode = AT_NORMAL;
+ if (attr & AT_BINARY)
+ attr |= binattr;
+ if (attr & AT_HILITE)
+ attr |= AT_STANDOUT;
+ attr &= ~(AT_BINARY|AT_HILITE);
+
+ return attr;
}
#if 0 /* No longer used */
OpenPOWER on IntegriCloud