Updated libedit to NetBSD upstream
Note: This unconditionally assumes wchar_t support. May need revision if some platforms prove problematic.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: refresh.c,v 1.35 2009/12/30 22:37:40 christos Exp $ */
|
||||
/* $NetBSD: refresh.c,v 1.51 2016/05/09 21:46:56 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@@ -37,7 +37,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: refresh.c,v 1.35 2009/12/30 22:37:40 christos Exp $");
|
||||
__RCSID("$NetBSD: refresh.c,v 1.51 2016/05/09 21:46:56 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@@ -45,26 +45,25 @@ __RCSID("$NetBSD: refresh.c,v 1.35 2009/12/30 22:37:40 christos Exp $");
|
||||
* refresh.c: Lower level screen refreshing functions
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "el.h"
|
||||
|
||||
private void re_nextline(EditLine *);
|
||||
private void re_addc(EditLine *, Int);
|
||||
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);
|
||||
static void re_nextline(EditLine *);
|
||||
static void re_addc(EditLine *, wint_t);
|
||||
static void re_update_line(EditLine *, wchar_t *, wchar_t *, int);
|
||||
static void re_insert (EditLine *, wchar_t *, int, int, wchar_t *, int);
|
||||
static void re_delete(EditLine *, wchar_t *, int, int, int);
|
||||
static void re_fastputc(EditLine *, wint_t);
|
||||
static void re_clear_eol(EditLine *, int, int, int);
|
||||
static void re__strncopy(wchar_t *, wchar_t *, size_t);
|
||||
static void re__copy_and_pad(wchar_t *, const wchar_t *, size_t);
|
||||
|
||||
#ifdef DEBUG_REFRESH
|
||||
private void re_printstr(EditLine *, const char *, char *, char *);
|
||||
static void re_printstr(EditLine *, const char *, wchar_t *, wchar_t *);
|
||||
#define __F el->el_errfile
|
||||
#define ELRE_ASSERT(a, b, c) do \
|
||||
#define ELRE_ASSERT(a, b, c) do \
|
||||
if (/*CONSTCOND*/ a) { \
|
||||
(void) fprintf b; \
|
||||
c; \
|
||||
@@ -75,8 +74,8 @@ private void re_printstr(EditLine *, const char *, char *, char *);
|
||||
/* re_printstr():
|
||||
* Print a string on the debugging pty
|
||||
*/
|
||||
private void
|
||||
re_printstr(EditLine *el, const char *str, char *f, char *t)
|
||||
static void
|
||||
re_printstr(EditLine *el, const char *str, wchar_t *f, wchar_t *t)
|
||||
{
|
||||
|
||||
ELRE_DEBUG(1, (__F, "%s:\"", str));
|
||||
@@ -92,7 +91,7 @@ re_printstr(EditLine *el, const char *str, char *f, char *t)
|
||||
/* re_nextline():
|
||||
* Move to the next line or scroll
|
||||
*/
|
||||
private void
|
||||
static void
|
||||
re_nextline(EditLine *el)
|
||||
{
|
||||
el->el_refresh.r_cursor.h = 0; /* reset it. */
|
||||
@@ -103,9 +102,9 @@ re_nextline(EditLine *el)
|
||||
* We do this via pointer shuffling - it's safe in this case
|
||||
* and we avoid memcpy().
|
||||
*/
|
||||
if (el->el_refresh.r_cursor.v + 1 >= el->el_term.t_size.v) {
|
||||
int i, lins = el->el_term.t_size.v;
|
||||
Char *firstline = el->el_vdisplay[0];
|
||||
if (el->el_refresh.r_cursor.v + 1 >= el->el_terminal.t_size.v) {
|
||||
int i, lins = el->el_terminal.t_size.v;
|
||||
wchar_t *firstline = el->el_vdisplay[0];
|
||||
|
||||
for(i = 1; i < lins; i++)
|
||||
el->el_vdisplay[i - 1] = el->el_vdisplay[i];
|
||||
@@ -115,19 +114,19 @@ re_nextline(EditLine *el)
|
||||
} else
|
||||
el->el_refresh.r_cursor.v++;
|
||||
|
||||
ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
|
||||
ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_terminal.t_size.v,
|
||||
(__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
|
||||
el->el_refresh.r_cursor.v, el->el_term.t_size.v),
|
||||
el->el_refresh.r_cursor.v, el->el_terminal.t_size.v),
|
||||
abort());
|
||||
}
|
||||
|
||||
/* re_addc():
|
||||
* Draw c, expanding tabs, control chars etc.
|
||||
*/
|
||||
private void
|
||||
re_addc(EditLine *el, Int c)
|
||||
static void
|
||||
re_addc(EditLine *el, wint_t c)
|
||||
{
|
||||
switch (ct_chr_class((Char)c)) {
|
||||
switch (ct_chr_class(c)) {
|
||||
case CHTYPE_TAB: /* expand the tab */
|
||||
for (;;) {
|
||||
re_putc(el, ' ', 1);
|
||||
@@ -146,9 +145,9 @@ re_addc(EditLine *el, Int c)
|
||||
re_putc(el, c, 1);
|
||||
break;
|
||||
default: {
|
||||
Char visbuf[VISUAL_WIDTH_MAX];
|
||||
wchar_t visbuf[VISUAL_WIDTH_MAX];
|
||||
ssize_t i, n =
|
||||
ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c);
|
||||
ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c);
|
||||
for (i = 0; n-- > 0; ++i)
|
||||
re_putc(el, visbuf[i], 1);
|
||||
break;
|
||||
@@ -160,13 +159,15 @@ re_addc(EditLine *el, Int c)
|
||||
/* re_putc():
|
||||
* Draw the character given
|
||||
*/
|
||||
protected void
|
||||
re_putc(EditLine *el, Int c, int shift)
|
||||
libedit_private void
|
||||
re_putc(EditLine *el, wint_t c, int shift)
|
||||
{
|
||||
int i, w = Width(c);
|
||||
ELRE_DEBUG(1, (__F, "printing %5x '%c'\r\n", c, c));
|
||||
int i, w = wcwidth(c);
|
||||
ELRE_DEBUG(1, (__F, "printing %5x '%lc'\r\n", c, c));
|
||||
if (w == -1)
|
||||
w = 0;
|
||||
|
||||
while (shift && (el->el_refresh.r_cursor.h + w > el->el_term.t_size.h))
|
||||
while (shift && (el->el_refresh.r_cursor.h + w > el->el_terminal.t_size.h))
|
||||
re_putc(el, ' ', 1);
|
||||
|
||||
el->el_vdisplay[el->el_refresh.r_cursor.v]
|
||||
@@ -181,9 +182,9 @@ re_putc(EditLine *el, Int c, int shift)
|
||||
return;
|
||||
|
||||
el->el_refresh.r_cursor.h += w; /* advance to next place */
|
||||
if (el->el_refresh.r_cursor.h >= el->el_term.t_size.h) {
|
||||
if (el->el_refresh.r_cursor.h >= el->el_terminal.t_size.h) {
|
||||
/* assure end of line */
|
||||
el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h]
|
||||
el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_terminal.t_size.h]
|
||||
= '\0';
|
||||
re_nextline(el);
|
||||
}
|
||||
@@ -192,21 +193,21 @@ re_putc(EditLine *el, Int c, int shift)
|
||||
|
||||
/* re_refresh():
|
||||
* draws the new virtual screen image from the current input
|
||||
* line, then goes line-by-line changing the real image to the new
|
||||
* line, then goes line-by-line changing the real image to the new
|
||||
* virtual image. The routine to re-draw a line can be replaced
|
||||
* easily in hopes of a smarter one being placed there.
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
re_refresh(EditLine *el)
|
||||
{
|
||||
int i, rhdiff;
|
||||
Char *cp, *st;
|
||||
wchar_t *cp, *st;
|
||||
coord_t cur;
|
||||
#ifdef notyet
|
||||
size_t termsz;
|
||||
#endif
|
||||
|
||||
ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%s:\r\n",
|
||||
ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%ls:\r\n",
|
||||
el->el_line.buffer));
|
||||
|
||||
/* reset the Drawing cursor */
|
||||
@@ -235,7 +236,7 @@ re_refresh(EditLine *el)
|
||||
|
||||
/* draw the current input buffer */
|
||||
#if notyet
|
||||
termsz = el->el_term.t_size.h * el->el_term.t_size.v;
|
||||
termsz = el->el_terminal.t_size.h * el->el_terminal.t_size.v;
|
||||
if (el->el_line.lastchar - el->el_line.buffer > termsz) {
|
||||
/*
|
||||
* If line is longer than terminal, process only part
|
||||
@@ -244,21 +245,21 @@ re_refresh(EditLine *el)
|
||||
size_t rem = (el->el_line.lastchar-el->el_line.buffer)%termsz;
|
||||
|
||||
st = el->el_line.lastchar - rem
|
||||
- (termsz - (((rem / el->el_term.t_size.v) - 1)
|
||||
* el->el_term.t_size.v));
|
||||
- (termsz - (((rem / el->el_terminal.t_size.v) - 1)
|
||||
* el->el_terminal.t_size.v));
|
||||
} else
|
||||
#endif
|
||||
st = el->el_line.buffer;
|
||||
|
||||
for (cp = st; cp < el->el_line.lastchar; cp++) {
|
||||
if (cp == el->el_line.cursor) {
|
||||
int w = Width(*cp);
|
||||
int w = wcwidth(*cp);
|
||||
/* save for later */
|
||||
cur.h = el->el_refresh.r_cursor.h;
|
||||
cur.v = el->el_refresh.r_cursor.v;
|
||||
/* handle being at a linebroken doublewidth char */
|
||||
if (w > 1 && el->el_refresh.r_cursor.h + w >
|
||||
el->el_term.t_size.h) {
|
||||
el->el_terminal.t_size.h) {
|
||||
cur.h = 0;
|
||||
cur.v++;
|
||||
}
|
||||
@@ -270,7 +271,7 @@ re_refresh(EditLine *el)
|
||||
cur.h = el->el_refresh.r_cursor.h;
|
||||
cur.v = el->el_refresh.r_cursor.v;
|
||||
}
|
||||
rhdiff = el->el_term.t_size.h - el->el_refresh.r_cursor.h -
|
||||
rhdiff = el->el_terminal.t_size.h - el->el_refresh.r_cursor.h -
|
||||
el->el_rprompt.p_pos.h;
|
||||
if (el->el_rprompt.p_pos.h && !el->el_rprompt.p_pos.v &&
|
||||
!el->el_refresh.r_cursor.v && rhdiff > 1) {
|
||||
@@ -293,8 +294,9 @@ re_refresh(EditLine *el)
|
||||
|
||||
ELRE_DEBUG(1, (__F,
|
||||
"term.h=%d vcur.h=%d vcur.v=%d vdisplay[0]=\r\n:%80.80s:\r\n",
|
||||
el->el_term.t_size.h, el->el_refresh.r_cursor.h,
|
||||
el->el_refresh.r_cursor.v, ct_encode_string(el->el_vdisplay[0])));
|
||||
el->el_terminal.t_size.h, el->el_refresh.r_cursor.h,
|
||||
el->el_refresh.r_cursor.v, ct_encode_string(el->el_vdisplay[0],
|
||||
&el->el_scratch)));
|
||||
|
||||
ELRE_DEBUG(1, (__F, "updating %d lines.\r\n", el->el_refresh.r_newcv));
|
||||
for (i = 0; i <= el->el_refresh.r_newcv; i++) {
|
||||
@@ -309,7 +311,7 @@ re_refresh(EditLine *el)
|
||||
* leftover stuff.
|
||||
*/
|
||||
re__copy_and_pad(el->el_display[i], el->el_vdisplay[i],
|
||||
(size_t) el->el_term.t_size.h);
|
||||
(size_t) el->el_terminal.t_size.h);
|
||||
}
|
||||
ELRE_DEBUG(1, (__F,
|
||||
"\r\nel->el_refresh.r_cursor.v=%d,el->el_refresh.r_oldcv=%d i=%d\r\n",
|
||||
@@ -317,12 +319,12 @@ re_refresh(EditLine *el)
|
||||
|
||||
if (el->el_refresh.r_oldcv > el->el_refresh.r_newcv)
|
||||
for (; i <= el->el_refresh.r_oldcv; i++) {
|
||||
term_move_to_line(el, i);
|
||||
term_move_to_char(el, 0);
|
||||
/* This Strlen should be safe even with MB_FILL_CHARs */
|
||||
term_clear_EOL(el, (int) Strlen(el->el_display[i]));
|
||||
terminal_move_to_line(el, i);
|
||||
terminal_move_to_char(el, 0);
|
||||
/* This wcslen should be safe even with MB_FILL_CHARs */
|
||||
terminal_clear_EOL(el, (int) wcslen(el->el_display[i]));
|
||||
#ifdef DEBUG_REFRESH
|
||||
term_overwrite(el, "C\b", (size_t)2);
|
||||
terminal_overwrite(el, L"C\b", 2);
|
||||
#endif /* DEBUG_REFRESH */
|
||||
el->el_display[i][0] = '\0';
|
||||
}
|
||||
@@ -332,22 +334,22 @@ re_refresh(EditLine *el)
|
||||
"\r\ncursor.h = %d, cursor.v = %d, cur.h = %d, cur.v = %d\r\n",
|
||||
el->el_refresh.r_cursor.h, el->el_refresh.r_cursor.v,
|
||||
cur.h, cur.v));
|
||||
term_move_to_line(el, cur.v); /* go to where the cursor is */
|
||||
term_move_to_char(el, cur.h);
|
||||
terminal_move_to_line(el, cur.v); /* go to where the cursor is */
|
||||
terminal_move_to_char(el, cur.h);
|
||||
}
|
||||
|
||||
|
||||
/* re_goto_bottom():
|
||||
* used to go to last used screen line
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
re_goto_bottom(EditLine *el)
|
||||
{
|
||||
|
||||
term_move_to_line(el, el->el_refresh.r_oldcv);
|
||||
term__putc(el, '\n');
|
||||
terminal_move_to_line(el, el->el_refresh.r_oldcv);
|
||||
terminal__putc(el, '\n');
|
||||
re_clear_display(el);
|
||||
term__flush(el);
|
||||
terminal__flush(el);
|
||||
}
|
||||
|
||||
|
||||
@@ -355,12 +357,12 @@ re_goto_bottom(EditLine *el)
|
||||
* insert num characters of s into d (in front of the character)
|
||||
* at dat, maximum length of d is dlen
|
||||
*/
|
||||
private void
|
||||
static void
|
||||
/*ARGSUSED*/
|
||||
re_insert(EditLine *el __attribute__((__unused__)),
|
||||
Char *d, int dat, int dlen, Char *s, int num)
|
||||
wchar_t *d, int dat, int dlen, wchar_t *s, int num)
|
||||
{
|
||||
Char *a, *b;
|
||||
wchar_t *a, *b;
|
||||
|
||||
if (num <= 0)
|
||||
return;
|
||||
@@ -369,8 +371,9 @@ re_insert(EditLine *el __attribute__((__unused__)),
|
||||
|
||||
ELRE_DEBUG(1,
|
||||
(__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n",
|
||||
num, dat, dlen, ct_encode_string(d)));
|
||||
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
|
||||
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
|
||||
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s,
|
||||
&el->el_scratch)));
|
||||
|
||||
/* open up the space for num chars */
|
||||
if (num > 0) {
|
||||
@@ -383,8 +386,9 @@ 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, ct_encode_string(d)));
|
||||
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
|
||||
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
|
||||
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s,
|
||||
&el->el_scratch)));
|
||||
|
||||
/* copy the characters */
|
||||
for (a = d + dat; (a < d + dlen) && (num > 0); num--)
|
||||
@@ -404,12 +408,12 @@ re_insert(EditLine *el __attribute__((__unused__)),
|
||||
/* re_delete():
|
||||
* delete num characters d at dat, maximum length of d is dlen
|
||||
*/
|
||||
private void
|
||||
static void
|
||||
/*ARGSUSED*/
|
||||
re_delete(EditLine *el __attribute__((__unused__)),
|
||||
Char *d, int dat, int dlen, int num)
|
||||
wchar_t *d, int dat, int dlen, int num)
|
||||
{
|
||||
Char *a, *b;
|
||||
wchar_t *a, *b;
|
||||
|
||||
if (num <= 0)
|
||||
return;
|
||||
@@ -419,7 +423,7 @@ re_delete(EditLine *el __attribute__((__unused__)),
|
||||
}
|
||||
ELRE_DEBUG(1,
|
||||
(__F, "re_delete() starting: %d at %d max %d, d == \"%s\"\n",
|
||||
num, dat, dlen, ct_encode_string(d)));
|
||||
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
|
||||
|
||||
/* open up the space for num chars */
|
||||
if (num > 0) {
|
||||
@@ -431,15 +435,15 @@ re_delete(EditLine *el __attribute__((__unused__)),
|
||||
}
|
||||
ELRE_DEBUG(1,
|
||||
(__F, "re_delete() after delete: %d at %d max %d, d == \"%s\"\n",
|
||||
num, dat, dlen, ct_encode_string(d)));
|
||||
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
|
||||
}
|
||||
|
||||
|
||||
/* re__strncopy():
|
||||
* Like strncpy without padding.
|
||||
*/
|
||||
private void
|
||||
re__strncopy(Char *a, Char *b, size_t n)
|
||||
static void
|
||||
re__strncopy(wchar_t *a, wchar_t *b, size_t n)
|
||||
{
|
||||
|
||||
while (n-- && *b)
|
||||
@@ -451,9 +455,9 @@ re__strncopy(Char *a, Char *b, size_t n)
|
||||
* 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
|
||||
* in the first or second diff, diff is the difference between the
|
||||
* number of characters between the new and old line.
|
||||
* number of characters between the new and old line.
|
||||
*/
|
||||
private void
|
||||
static void
|
||||
re_clear_eol(EditLine *el, int fx, int sx, int diff)
|
||||
{
|
||||
|
||||
@@ -470,7 +474,7 @@ re_clear_eol(EditLine *el, int fx, int sx, int diff)
|
||||
diff = sx;
|
||||
|
||||
ELRE_DEBUG(1, (__F, "re_clear_eol %d\n", diff));
|
||||
term_clear_EOL(el, diff);
|
||||
terminal_clear_EOL(el, diff);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
@@ -497,12 +501,12 @@ new: eddie> Oh, my little buggy says to me, as lurgid as
|
||||
*/
|
||||
#define MIN_END_KEEP 4
|
||||
|
||||
private void
|
||||
re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
static void
|
||||
re_update_line(EditLine *el, wchar_t *old, wchar_t *new, int i)
|
||||
{
|
||||
Char *o, *n, *p, c;
|
||||
Char *ofd, *ols, *oe, *nfd, *nls, *ne;
|
||||
Char *osb, *ose, *nsb, *nse;
|
||||
wchar_t *o, *n, *p, c;
|
||||
wchar_t *ofd, *ols, *oe, *nfd, *nls, *ne;
|
||||
wchar_t *osb, *ose, *nsb, *nse;
|
||||
int fx, sx;
|
||||
size_t len;
|
||||
|
||||
@@ -559,7 +563,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
nls = ++n;
|
||||
|
||||
/*
|
||||
* find same begining and same end
|
||||
* find same beginning and same end
|
||||
*/
|
||||
osb = ols;
|
||||
nsb = nls;
|
||||
@@ -689,9 +693,9 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
sx = (int)((nls - nse) - (ols - ose));
|
||||
|
||||
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",
|
||||
ELRE_DEBUG(1, (__F, "ofd %td, osb %td, ose %td, ols %td, oe %td\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",
|
||||
ELRE_DEBUG(1, (__F, "nfd %td, nsb %td, nse %td, nls %td, ne %td\n",
|
||||
nfd - new, nsb - new, nse - new, nls - new, ne - new));
|
||||
ELRE_DEBUG(1, (__F,
|
||||
"xxx-xxx:\"00000000001111111111222222222233333333334\"\r\n"));
|
||||
@@ -717,7 +721,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
* don't have to change the line, we don't move to it. el_cursor.h to
|
||||
* first diff char
|
||||
*/
|
||||
term_move_to_line(el, i);
|
||||
terminal_move_to_line(el, i);
|
||||
|
||||
/*
|
||||
* at this point we have something like this:
|
||||
@@ -741,7 +745,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
* if we have a net insert on the first difference, AND inserting the
|
||||
* net amount ((nsb-nfd) - (osb-ofd)) won't push the last useful
|
||||
* character (which is ne if nls != ne, otherwise is nse) off the edge
|
||||
* of the screen (el->el_term.t_size.h) else we do the deletes first
|
||||
* of the screen (el->el_terminal.t_size.h) else we do the deletes first
|
||||
* so that we keep everything we need to.
|
||||
*/
|
||||
|
||||
@@ -763,13 +767,13 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
* No insert or delete
|
||||
*/
|
||||
if ((nsb != nfd) && fx > 0 &&
|
||||
((p - old) + fx <= el->el_term.t_size.h)) {
|
||||
((p - old) + fx <= el->el_terminal.t_size.h)) {
|
||||
ELRE_DEBUG(1,
|
||||
(__F, "first diff insert at %d...\r\n", nfd - new));
|
||||
(__F, "first diff insert at %td...\r\n", nfd - new));
|
||||
/*
|
||||
* Move to the first char to insert, where the first diff is.
|
||||
*/
|
||||
term_move_to_char(el, (int)(nfd - new));
|
||||
terminal_move_to_char(el, (int)(nfd - new));
|
||||
/*
|
||||
* Check if we have stuff to keep at end
|
||||
*/
|
||||
@@ -781,21 +785,21 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
if (fx > 0) {
|
||||
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
|
||||
"ERROR: cannot insert in early first diff\n"));
|
||||
term_insertwrite(el, nfd, fx);
|
||||
terminal_insertwrite(el, nfd, fx);
|
||||
re_insert(el, old, (int)(ofd - old),
|
||||
el->el_term.t_size.h, nfd, fx);
|
||||
el->el_terminal.t_size.h, nfd, fx);
|
||||
}
|
||||
/*
|
||||
* write (nsb-nfd) - fx chars of new starting at
|
||||
* (nfd + fx)
|
||||
*/
|
||||
len = (size_t) ((nsb - nfd) - fx);
|
||||
term_overwrite(el, (nfd + fx), len);
|
||||
terminal_overwrite(el, (nfd + fx), len);
|
||||
re__strncopy(ofd + fx, nfd + fx, len);
|
||||
} else {
|
||||
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
|
||||
len = (size_t)(nsb - nfd);
|
||||
term_overwrite(el, nfd, len);
|
||||
terminal_overwrite(el, nfd, len);
|
||||
re__strncopy(ofd, nfd, len);
|
||||
/*
|
||||
* Done
|
||||
@@ -804,11 +808,11 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
}
|
||||
} else if (fx < 0) {
|
||||
ELRE_DEBUG(1,
|
||||
(__F, "first diff delete at %d...\r\n", ofd - old));
|
||||
(__F, "first diff delete at %td...\r\n", ofd - old));
|
||||
/*
|
||||
* move to the first char to delete where the first diff is
|
||||
*/
|
||||
term_move_to_char(el, (int)(ofd - old));
|
||||
terminal_move_to_char(el, (int)(ofd - old));
|
||||
/*
|
||||
* Check if we have stuff to save
|
||||
*/
|
||||
@@ -821,15 +825,15 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
if (fx < 0) {
|
||||
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
|
||||
"ERROR: cannot delete in first diff\n"));
|
||||
term_deletechars(el, -fx);
|
||||
terminal_deletechars(el, -fx);
|
||||
re_delete(el, old, (int)(ofd - old),
|
||||
el->el_term.t_size.h, -fx);
|
||||
el->el_terminal.t_size.h, -fx);
|
||||
}
|
||||
/*
|
||||
* write (nsb-nfd) chars of new starting at nfd
|
||||
*/
|
||||
len = (size_t) (nsb - nfd);
|
||||
term_overwrite(el, nfd, len);
|
||||
terminal_overwrite(el, nfd, len);
|
||||
re__strncopy(ofd, nfd, len);
|
||||
|
||||
} else {
|
||||
@@ -838,7 +842,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, (size_t)(nsb - nfd));
|
||||
terminal_overwrite(el, nfd, (size_t)(nsb - nfd));
|
||||
re_clear_eol(el, fx, sx,
|
||||
(int)((oe - old) - (ne - new)));
|
||||
/*
|
||||
@@ -849,9 +853,9 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
} else
|
||||
fx = 0;
|
||||
|
||||
if (sx < 0 && (ose - old) + fx < el->el_term.t_size.h) {
|
||||
if (sx < 0 && (ose - old) + fx < el->el_terminal.t_size.h) {
|
||||
ELRE_DEBUG(1, (__F,
|
||||
"second diff delete at %d...\r\n", (ose - old) + fx));
|
||||
"second diff delete at %td...\r\n", (ose - old) + fx));
|
||||
/*
|
||||
* Check if we have stuff to delete
|
||||
*/
|
||||
@@ -859,7 +863,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
* fx is the number of characters inserted (+) or deleted (-)
|
||||
*/
|
||||
|
||||
term_move_to_char(el, (int)((ose - old) + fx));
|
||||
terminal_move_to_char(el, (int)((ose - old) + fx));
|
||||
/*
|
||||
* Check if we have stuff to save
|
||||
*/
|
||||
@@ -871,16 +875,16 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
if (sx < 0) {
|
||||
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
|
||||
"ERROR: cannot delete in second diff\n"));
|
||||
term_deletechars(el, -sx);
|
||||
terminal_deletechars(el, -sx);
|
||||
}
|
||||
/*
|
||||
* write (nls-nse) chars of new starting at nse
|
||||
*/
|
||||
term_overwrite(el, nse, (size_t)(nls - nse));
|
||||
terminal_overwrite(el, nse, (size_t)(nls - nse));
|
||||
} else {
|
||||
ELRE_DEBUG(1, (__F,
|
||||
"but with nothing left to save\r\n"));
|
||||
term_overwrite(el, nse, (size_t)(nls - nse));
|
||||
terminal_overwrite(el, nse, (size_t)(nls - nse));
|
||||
re_clear_eol(el, fx, sx,
|
||||
(int)((oe - old) - (ne - new)));
|
||||
}
|
||||
@@ -889,10 +893,10 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
* if we have a first insert AND WE HAVEN'T ALREADY DONE IT...
|
||||
*/
|
||||
if ((nsb != nfd) && (osb - ofd) <= (nsb - nfd) && (fx == 0)) {
|
||||
ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
|
||||
ELRE_DEBUG(1, (__F, "late first diff insert at %td...\r\n",
|
||||
nfd - new));
|
||||
|
||||
term_move_to_char(el, (int)(nfd - new));
|
||||
terminal_move_to_char(el, (int)(nfd - new));
|
||||
/*
|
||||
* Check if we have stuff to keep at the end
|
||||
*/
|
||||
@@ -910,21 +914,21 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
*/
|
||||
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
|
||||
"ERROR: cannot insert in late first diff\n"));
|
||||
term_insertwrite(el, nfd, fx);
|
||||
terminal_insertwrite(el, nfd, fx);
|
||||
re_insert(el, old, (int)(ofd - old),
|
||||
el->el_term.t_size.h, nfd, fx);
|
||||
el->el_terminal.t_size.h, nfd, fx);
|
||||
}
|
||||
/*
|
||||
* write (nsb-nfd) - fx chars of new starting at
|
||||
* (nfd + fx)
|
||||
*/
|
||||
len = (size_t) ((nsb - nfd) - fx);
|
||||
term_overwrite(el, (nfd + fx), len);
|
||||
terminal_overwrite(el, (nfd + fx), len);
|
||||
re__strncopy(ofd + fx, nfd + fx, len);
|
||||
} else {
|
||||
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
|
||||
len = (size_t) (nsb - nfd);
|
||||
term_overwrite(el, nfd, len);
|
||||
terminal_overwrite(el, nfd, len);
|
||||
re__strncopy(ofd, nfd, len);
|
||||
}
|
||||
}
|
||||
@@ -934,24 +938,24 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
if (sx >= 0) {
|
||||
ELRE_DEBUG(1, (__F,
|
||||
"second diff insert at %d...\r\n", (int)(nse - new)));
|
||||
term_move_to_char(el, (int)(nse - new));
|
||||
terminal_move_to_char(el, (int)(nse - new));
|
||||
if (ols != oe) {
|
||||
ELRE_DEBUG(1, (__F, "with stuff to keep at end\r\n"));
|
||||
if (sx > 0) {
|
||||
/* insert sx chars of new starting at nse */
|
||||
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
|
||||
"ERROR: cannot insert in second diff\n"));
|
||||
term_insertwrite(el, nse, sx);
|
||||
terminal_insertwrite(el, nse, sx);
|
||||
}
|
||||
/*
|
||||
* write (nls-nse) - sx chars of new starting at
|
||||
* (nse + sx)
|
||||
*/
|
||||
term_overwrite(el, (nse + sx),
|
||||
terminal_overwrite(el, (nse + sx),
|
||||
(size_t)((nls - nse) - sx));
|
||||
} else {
|
||||
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
|
||||
term_overwrite(el, nse, (size_t)(nls - nse));
|
||||
terminal_overwrite(el, nse, (size_t)(nls - nse));
|
||||
|
||||
/*
|
||||
* No need to do a clear-to-end here because we were
|
||||
@@ -967,8 +971,8 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
/* re__copy_and_pad():
|
||||
* Copy string and pad with spaces
|
||||
*/
|
||||
private void
|
||||
re__copy_and_pad(Char *dst, const Char *src, size_t width)
|
||||
static void
|
||||
re__copy_and_pad(wchar_t *dst, const wchar_t *src, size_t width)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -988,10 +992,10 @@ re__copy_and_pad(Char *dst, const Char *src, size_t width)
|
||||
/* re_refresh_cursor():
|
||||
* Move to the new cursor position
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
re_refresh_cursor(EditLine *el)
|
||||
{
|
||||
Char *cp;
|
||||
wchar_t *cp;
|
||||
int h, v, th, w;
|
||||
|
||||
if (el->el_line.cursor >= el->el_line.lastchar) {
|
||||
@@ -1005,7 +1009,7 @@ re_refresh_cursor(EditLine *el)
|
||||
/* first we must find where the cursor is... */
|
||||
h = el->el_prompt.p_pos.h;
|
||||
v = el->el_prompt.p_pos.v;
|
||||
th = el->el_term.t_size.h; /* optimize for speed */
|
||||
th = el->el_terminal.t_size.h; /* optimize for speed */
|
||||
|
||||
/* do input buffer to el->el_line.cursor */
|
||||
for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
|
||||
@@ -1019,7 +1023,7 @@ re_refresh_cursor(EditLine *el)
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
w = Width(*cp);
|
||||
w = wcwidth(*cp);
|
||||
if (w > 1 && h + w > th) { /* won't fit on line */
|
||||
h = 0;
|
||||
v++;
|
||||
@@ -1035,36 +1039,36 @@ re_refresh_cursor(EditLine *el)
|
||||
}
|
||||
/* if we have a next character, and it's a doublewidth one, we need to
|
||||
* check whether we need to linebreak for it to fit */
|
||||
if (cp < el->el_line.lastchar && (w = Width(*cp)) > 1)
|
||||
if (cp < el->el_line.lastchar && (w = wcwidth(*cp)) > 1)
|
||||
if (h + w > th) {
|
||||
h = 0;
|
||||
v++;
|
||||
}
|
||||
|
||||
/* now go there */
|
||||
term_move_to_line(el, v);
|
||||
term_move_to_char(el, h);
|
||||
term__flush(el);
|
||||
terminal_move_to_line(el, v);
|
||||
terminal_move_to_char(el, h);
|
||||
terminal__flush(el);
|
||||
}
|
||||
|
||||
|
||||
/* re_fastputc():
|
||||
* Add a character fast.
|
||||
*/
|
||||
private void
|
||||
re_fastputc(EditLine *el, Int c)
|
||||
static void
|
||||
re_fastputc(EditLine *el, wint_t c)
|
||||
{
|
||||
int w = Width((Char)c);
|
||||
while (w > 1 && el->el_cursor.h + w > el->el_term.t_size.h)
|
||||
int w = wcwidth(c);
|
||||
while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h)
|
||||
re_fastputc(el, ' ');
|
||||
|
||||
term__putc(el, c);
|
||||
terminal__putc(el, c);
|
||||
el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
|
||||
while (--w > 0)
|
||||
el->el_display[el->el_cursor.v][el->el_cursor.h++]
|
||||
= MB_FILL_CHAR;
|
||||
|
||||
if (el->el_cursor.h >= el->el_term.t_size.h) {
|
||||
if (el->el_cursor.h >= el->el_terminal.t_size.h) {
|
||||
/* if we must overflow */
|
||||
el->el_cursor.h = 0;
|
||||
|
||||
@@ -1074,14 +1078,14 @@ re_fastputc(EditLine *el, Int c)
|
||||
* We do this via pointer shuffling - it's safe in this case
|
||||
* and we avoid memcpy().
|
||||
*/
|
||||
if (el->el_cursor.v + 1 >= el->el_term.t_size.v) {
|
||||
int i, lins = el->el_term.t_size.v;
|
||||
Char *firstline = el->el_display[0];
|
||||
if (el->el_cursor.v + 1 >= el->el_terminal.t_size.v) {
|
||||
int i, lins = el->el_terminal.t_size.v;
|
||||
wchar_t *firstline = el->el_display[0];
|
||||
|
||||
for(i = 1; i < lins; i++)
|
||||
el->el_display[i - 1] = el->el_display[i];
|
||||
|
||||
re__copy_and_pad(firstline, STR(""), 0);
|
||||
re__copy_and_pad(firstline, L"", (size_t)0);
|
||||
el->el_display[i - 1] = firstline;
|
||||
} else {
|
||||
el->el_cursor.v++;
|
||||
@@ -1089,12 +1093,12 @@ re_fastputc(EditLine *el, Int c)
|
||||
}
|
||||
if (EL_HAS_AUTO_MARGINS) {
|
||||
if (EL_HAS_MAGIC_MARGINS) {
|
||||
term__putc(el, ' ');
|
||||
term__putc(el, '\b');
|
||||
terminal__putc(el, ' ');
|
||||
terminal__putc(el, '\b');
|
||||
}
|
||||
} else {
|
||||
term__putc(el, '\r');
|
||||
term__putc(el, '\n');
|
||||
terminal__putc(el, '\r');
|
||||
terminal__putc(el, '\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1104,10 +1108,10 @@ re_fastputc(EditLine *el, Int c)
|
||||
* we added just one char, handle it fast.
|
||||
* Assumes that screen cursor == real cursor
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
re_fastaddc(EditLine *el)
|
||||
{
|
||||
Char c;
|
||||
wchar_t c;
|
||||
int rhdiff;
|
||||
|
||||
c = el->el_line.cursor[-1];
|
||||
@@ -1116,7 +1120,7 @@ re_fastaddc(EditLine *el)
|
||||
re_refresh(el); /* too hard to handle */
|
||||
return;
|
||||
}
|
||||
rhdiff = el->el_term.t_size.h - el->el_cursor.h -
|
||||
rhdiff = el->el_terminal.t_size.h - el->el_cursor.h -
|
||||
el->el_rprompt.p_pos.h;
|
||||
if (el->el_rprompt.p_pos.h && rhdiff < 3) {
|
||||
re_refresh(el); /* clear out rprompt if less than 1 char gap */
|
||||
@@ -1131,29 +1135,29 @@ re_fastaddc(EditLine *el)
|
||||
break;
|
||||
case CHTYPE_ASCIICTL:
|
||||
case CHTYPE_NONPRINT: {
|
||||
Char visbuf[VISUAL_WIDTH_MAX];
|
||||
wchar_t visbuf[VISUAL_WIDTH_MAX];
|
||||
ssize_t i, n =
|
||||
ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c);
|
||||
ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c);
|
||||
for (i = 0; n-- > 0; ++i)
|
||||
re_fastputc(el, visbuf[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
term__flush(el);
|
||||
terminal__flush(el);
|
||||
}
|
||||
|
||||
|
||||
/* re_clear_display():
|
||||
* clear the screen buffers so that new new prompt starts fresh.
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
re_clear_display(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
|
||||
el->el_cursor.v = 0;
|
||||
el->el_cursor.h = 0;
|
||||
for (i = 0; i < el->el_term.t_size.v; i++)
|
||||
for (i = 0; i < el->el_terminal.t_size.v; i++)
|
||||
el->el_display[i][0] = '\0';
|
||||
el->el_refresh.r_oldcv = 0;
|
||||
}
|
||||
@@ -1162,7 +1166,7 @@ re_clear_display(EditLine *el)
|
||||
/* re_clear_lines():
|
||||
* Make sure all lines are *really* blank
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
re_clear_lines(EditLine *el)
|
||||
{
|
||||
|
||||
@@ -1170,14 +1174,14 @@ re_clear_lines(EditLine *el)
|
||||
int i;
|
||||
for (i = el->el_refresh.r_oldcv; i >= 0; i--) {
|
||||
/* for each line on the screen */
|
||||
term_move_to_line(el, i);
|
||||
term_move_to_char(el, 0);
|
||||
term_clear_EOL(el, el->el_term.t_size.h);
|
||||
terminal_move_to_line(el, i);
|
||||
terminal_move_to_char(el, 0);
|
||||
terminal_clear_EOL(el, el->el_terminal.t_size.h);
|
||||
}
|
||||
} else {
|
||||
term_move_to_line(el, el->el_refresh.r_oldcv);
|
||||
terminal_move_to_line(el, el->el_refresh.r_oldcv);
|
||||
/* go to last line */
|
||||
term__putc(el, '\r'); /* go to BOL */
|
||||
term__putc(el, '\n'); /* go to new line */
|
||||
terminal__putc(el, '\r'); /* go to BOL */
|
||||
terminal__putc(el, '\n'); /* go to new line */
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user