summaryrefslogtreecommitdiff
path: root/cmd-line-utils/libedit/refresh.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-line-utils/libedit/refresh.c')
-rw-r--r--cmd-line-utils/libedit/refresh.c76
1 files changed, 52 insertions, 24 deletions
diff --git a/cmd-line-utils/libedit/refresh.c b/cmd-line-utils/libedit/refresh.c
index 46aca15ef08..5edd1fe78fc 100644
--- a/cmd-line-utils/libedit/refresh.c
+++ b/cmd-line-utils/libedit/refresh.c
@@ -1,4 +1,4 @@
-/* $NetBSD: refresh.c,v 1.26 2003/08/07 16:44:33 agc Exp $ */
+/* $NetBSD: refresh.c,v 1.28 2008/09/10 15:45:37 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -32,7 +32,13 @@
* SUCH DAMAGE.
*/
-#include <config.h>
+#include "config.h"
+#if !defined(lint) && !defined(SCCSID)
+#if 0
+static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
+#else
+#endif
+#endif /* not lint && not SCCSID */
/*
* refresh.c: Lower level screen refreshing functions
@@ -49,6 +55,7 @@ private void re_update_line(EditLine *, char *, char *, int);
private void re_insert (EditLine *, char *, int, int, char *, int);
private void re_delete(EditLine *, char *, int, int, int);
private void re_fastputc(EditLine *, int);
+private void re_clear_eol(EditLine *, int, int, int);
private void re__strncopy(char *, char *, size_t);
private void re__copy_and_pad(char *, const char *, size_t);
@@ -315,9 +322,9 @@ re_goto_bottom(EditLine *el)
{
term_move_to_line(el, el->el_refresh.r_oldcv);
- term__putc('\n');
+ term__putc(el, '\n');
re_clear_display(el);
- term__flush();
+ term__flush(el);
}
@@ -340,7 +347,7 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1,
(__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, d));
- ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
+ ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
/* open up the space for num chars */
if (num > 0) {
@@ -353,7 +360,7 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1, (__F,
"re_insert() after insert: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, d));
- ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
+ ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
/* copy the characters */
for (a = d + dat; (a < d + dlen) && (num > 0); num--)
@@ -362,7 +369,7 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1,
(__F, "re_insert() after copy: %d at %d max %d, %s == \"%s\"\n",
num, dat, dlen, d, s));
- ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
+ ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
}
@@ -411,6 +418,32 @@ re__strncopy(char *a, char *b, size_t n)
*a++ = *b++;
}
+/* re_clear_eol():
+ * Find the number of characters we need to clear till the end of line
+ * in order to make sure that we have cleared the previous contents of
+ * the line. fx and sx is the number of characters inserted or deleted
+ * int the first or second diff, diff is the difference between the
+ * number of characters between the new and old line.
+ */
+private void
+re_clear_eol(EditLine *el, int fx, int sx, int diff)
+{
+
+ ELRE_DEBUG(1, (__F, "re_clear_eol sx %d, fx %d, diff %d\n",
+ sx, fx, diff));
+
+ if (fx < 0)
+ fx = -fx;
+ if (sx < 0)
+ sx = -sx;
+ if (fx > diff)
+ diff = fx;
+ if (sx > diff)
+ diff = sx;
+
+ ELRE_DEBUG(1, (__F, "re_clear_eol %d\n", diff));
+ term_clear_EOL(el, diff);
+}
/*****************************************************************
re_update_line() is based on finding the middle difference of each line
@@ -626,7 +659,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
fx = (nsb - nfd) - (osb - ofd);
sx = (nls - nse) - (ols - ose);
- ELRE_DEBUG(1, (__F, "\n"));
+ ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx));
ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n",
ofd - old, osb - old, ose - old, ols - old, oe - old));
ELRE_DEBUG(1, (__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n",
@@ -775,9 +808,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* write (nsb-nfd) chars of new starting at nfd
*/
term_overwrite(el, nfd, (nsb - nfd));
- ELRE_DEBUG(1, (__F,
- "cleareol %d\n", (oe - old) - (ne - new)));
- term_clear_EOL(el, (oe - old) - (ne - new));
+ re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
/*
* Done
*/
@@ -818,10 +849,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(1, (__F,
"but with nothing left to save\r\n"));
term_overwrite(el, nse, (nls - nse));
- ELRE_DEBUG(1, (__F,
- "cleareol %d\n", (oe - old) - (ne - new)));
- if ((oe - old) - (ne - new) != 0)
- term_clear_EOL(el, (oe - old) - (ne - new));
+ re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
}
}
/*
@@ -982,7 +1010,7 @@ re_refresh_cursor(EditLine *el)
/* now go there */
term_move_to_line(el, v);
term_move_to_char(el, h);
- term__flush();
+ term__flush(el);
}
@@ -993,7 +1021,7 @@ private void
re_fastputc(EditLine *el, int c)
{
- term__putc(c);
+ term__putc(el, c);
el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
if (el->el_cursor.h >= el->el_term.t_size.h) {
/* if we must overflow */
@@ -1020,12 +1048,12 @@ re_fastputc(EditLine *el, int c)
}
if (EL_HAS_AUTO_MARGINS) {
if (EL_HAS_MAGIC_MARGINS) {
- term__putc(' ');
- term__putc('\b');
+ term__putc(el, ' ');
+ term__putc(el, '\b');
}
} else {
- term__putc('\r');
- term__putc('\n');
+ term__putc(el, '\r');
+ term__putc(el, '\n');
}
}
}
@@ -1065,7 +1093,7 @@ re_fastaddc(EditLine *el)
re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0'));
re_fastputc(el, (c & 7) + '0');
}
- term__flush();
+ term__flush(el);
}
@@ -1104,7 +1132,7 @@ re_clear_lines(EditLine *el)
} else {
term_move_to_line(el, el->el_refresh.r_oldcv);
/* go to last line */
- term__putc('\r'); /* go to BOL */
- term__putc('\n'); /* go to new line */
+ term__putc(el, '\r'); /* go to BOL */
+ term__putc(el, '\n'); /* go to new line */
}
}