mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
WL#5945 : Improve libedit library
Updated libedit library.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: refresh.c,v 1.28 2008/09/10 15:45:37 christos Exp $ */
|
||||
/* $NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -40,6 +40,8 @@ static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
#include "chartype.c" /* XXXMYSQL */
|
||||
|
||||
/*
|
||||
* refresh.c: Lower level screen refreshing functions
|
||||
*/
|
||||
@ -50,14 +52,15 @@ static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
#include "el.h"
|
||||
|
||||
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_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);
|
||||
private void re__strncopy(Char *, Char *, size_t);
|
||||
private void re__copy_and_pad(Char *, const Char *, size_t);
|
||||
|
||||
#ifdef DEBUG_REFRESH
|
||||
private void re_printstr(EditLine *, const char *, char *, char *);
|
||||
@ -87,45 +90,70 @@ re_printstr(EditLine *el, const char *str, char *f, char *t)
|
||||
#define ELRE_DEBUG(a, b)
|
||||
#endif
|
||||
|
||||
/* re_nextline():
|
||||
* Move to the next line or scroll
|
||||
*/
|
||||
private void
|
||||
re_nextline(EditLine *el)
|
||||
{
|
||||
el->el_refresh.r_cursor.h = 0; /* reset it. */
|
||||
|
||||
/*
|
||||
* If we would overflow (input is longer than terminal size),
|
||||
* emulate scroll by dropping first line and shuffling the rest.
|
||||
* 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_terminal.t_size.v) {
|
||||
int i, lins = el->el_terminal.t_size.v;
|
||||
Char *firstline = el->el_vdisplay[0];
|
||||
|
||||
for(i = 1; i < lins; i++)
|
||||
el->el_vdisplay[i - 1] = el->el_vdisplay[i];
|
||||
|
||||
firstline[0] = '\0'; /* empty the string */
|
||||
el->el_vdisplay[i - 1] = firstline;
|
||||
} else
|
||||
el->el_refresh.r_cursor.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_terminal.t_size.v),
|
||||
abort());
|
||||
}
|
||||
|
||||
/* re_addc():
|
||||
* Draw c, expanding tabs, control chars etc.
|
||||
*/
|
||||
private void
|
||||
re_addc(EditLine *el, int c)
|
||||
re_addc(EditLine *el, Int c)
|
||||
{
|
||||
|
||||
if (el_isprint(c)) {
|
||||
re_putc(el, c, 1);
|
||||
return;
|
||||
}
|
||||
if (c == '\n') { /* expand the newline */
|
||||
int oldv = el->el_refresh.r_cursor.v;
|
||||
re_putc(el, '\0', 0); /* assure end of line */
|
||||
if (oldv == el->el_refresh.r_cursor.v) { /* XXX */
|
||||
el->el_refresh.r_cursor.h = 0; /* reset cursor pos */
|
||||
el->el_refresh.r_cursor.v++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (c == '\t') { /* expand the tab */
|
||||
switch (ct_chr_class((Char)c)) {
|
||||
case CHTYPE_TAB: /* expand the tab */
|
||||
for (;;) {
|
||||
re_putc(el, ' ', 1);
|
||||
if ((el->el_refresh.r_cursor.h & 07) == 0)
|
||||
break; /* go until tab stop */
|
||||
}
|
||||
} else if (iscntrl(c)) {
|
||||
re_putc(el, '^', 1);
|
||||
if (c == '\177')
|
||||
re_putc(el, '?', 1);
|
||||
else
|
||||
/* uncontrolify it; works only for iso8859-1 like sets */
|
||||
re_putc(el, (c | 0100), 1);
|
||||
} else {
|
||||
re_putc(el, '\\', 1);
|
||||
re_putc(el, (int) ((((unsigned int) c >> 6) & 07) + '0'), 1);
|
||||
re_putc(el, (int) ((((unsigned int) c >> 3) & 07) + '0'), 1);
|
||||
re_putc(el, (c & 07) + '0', 1);
|
||||
break;
|
||||
case CHTYPE_NL: {
|
||||
int oldv = el->el_refresh.r_cursor.v;
|
||||
re_putc(el, '\0', 0); /* assure end of line */
|
||||
if (oldv == el->el_refresh.r_cursor.v) /* XXX */
|
||||
re_nextline(el);
|
||||
break;
|
||||
}
|
||||
case CHTYPE_PRINT:
|
||||
re_putc(el, c, 1);
|
||||
break;
|
||||
default: {
|
||||
Char visbuf[VISUAL_WIDTH_MAX];
|
||||
ssize_t i, n =
|
||||
ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c);
|
||||
for (i = 0; n-- > 0; ++i)
|
||||
re_putc(el, visbuf[i], 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,43 +162,31 @@ re_addc(EditLine *el, int c)
|
||||
* Draw the character given
|
||||
*/
|
||||
protected void
|
||||
re_putc(EditLine *el, int c, int shift)
|
||||
re_putc(EditLine *el, Int c, int shift)
|
||||
{
|
||||
int i, w = Width(c);
|
||||
ELRE_DEBUG(1, (__F, "printing %5x '%c'\r\n", c, c));
|
||||
|
||||
ELRE_DEBUG(1, (__F, "printing %3.3o '%c'\r\n", c, c));
|
||||
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]
|
||||
[el->el_refresh.r_cursor.h] = c;
|
||||
/* assumes !shift is only used for single-column chars */
|
||||
i = w;
|
||||
while (--i > 0)
|
||||
el->el_vdisplay[el->el_refresh.r_cursor.v]
|
||||
[el->el_refresh.r_cursor.h + i] = MB_FILL_CHAR;
|
||||
|
||||
el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_refresh.r_cursor.h] = c;
|
||||
if (!shift)
|
||||
return;
|
||||
|
||||
el->el_refresh.r_cursor.h++; /* advance to next place */
|
||||
if (el->el_refresh.r_cursor.h >= el->el_term.t_size.h) {
|
||||
el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h] = '\0';
|
||||
el->el_refresh.r_cursor.h += w; /* advance to next place */
|
||||
if (el->el_refresh.r_cursor.h >= el->el_terminal.t_size.h) {
|
||||
/* assure end of line */
|
||||
el->el_refresh.r_cursor.h = 0; /* reset it. */
|
||||
|
||||
/*
|
||||
* If we would overflow (input is longer than terminal size),
|
||||
* emulate scroll by dropping first line and shuffling the rest.
|
||||
* 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];
|
||||
|
||||
for(i=1; i < lins; i++)
|
||||
el->el_vdisplay[i-1] = el->el_vdisplay[i];
|
||||
|
||||
firstline[0] = '\0'; /* empty the string */
|
||||
el->el_vdisplay[i-1] = firstline;
|
||||
} else
|
||||
el->el_refresh.r_cursor.v++;
|
||||
|
||||
ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.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),
|
||||
abort());
|
||||
el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_terminal.t_size.h]
|
||||
= '\0';
|
||||
re_nextline(el);
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,7 +201,7 @@ protected void
|
||||
re_refresh(EditLine *el)
|
||||
{
|
||||
int i, rhdiff;
|
||||
char *cp, *st;
|
||||
Char *cp, *st;
|
||||
coord_t cur;
|
||||
#ifdef notyet
|
||||
size_t termsz;
|
||||
@ -220,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
|
||||
@ -229,26 +245,33 @@ 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);
|
||||
/* 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_terminal.t_size.h) {
|
||||
cur.h = 0;
|
||||
cur.v++;
|
||||
}
|
||||
}
|
||||
re_addc(el, (unsigned char) *cp);
|
||||
re_addc(el, *cp);
|
||||
}
|
||||
|
||||
if (cur.h == -1) { /* if I haven't been set yet, I'm at the end */
|
||||
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) {
|
||||
@ -271,8 +294,8 @@ 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, 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])));
|
||||
|
||||
ELRE_DEBUG(1, (__F, "updating %d lines.\r\n", el->el_refresh.r_newcv));
|
||||
for (i = 0; i <= el->el_refresh.r_newcv; i++) {
|
||||
@ -287,7 +310,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",
|
||||
@ -295,11 +318,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);
|
||||
term_clear_EOL(el, (int) strlen(el->el_display[i]));
|
||||
terminal_move_to_line(el, i);
|
||||
terminal_move_to_char(el, 0);
|
||||
/* This Strlen should be safe even with MB_FILL_CHARs */
|
||||
terminal_clear_EOL(el, (int) Strlen(el->el_display[i]));
|
||||
#ifdef DEBUG_REFRESH
|
||||
term_overwrite(el, "C\b", 2);
|
||||
terminal_overwrite(el, "C\b", (size_t)2);
|
||||
#endif /* DEBUG_REFRESH */
|
||||
el->el_display[i][0] = '\0';
|
||||
}
|
||||
@ -309,8 +333,8 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@ -321,10 +345,10 @@ protected 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);
|
||||
}
|
||||
|
||||
|
||||
@ -335,9 +359,9 @@ re_goto_bottom(EditLine *el)
|
||||
private void
|
||||
/*ARGSUSED*/
|
||||
re_insert(EditLine *el __attribute__((__unused__)),
|
||||
char *d, int dat, int dlen, char *s, int num)
|
||||
Char *d, int dat, int dlen, Char *s, int num)
|
||||
{
|
||||
char *a, *b;
|
||||
Char *a, *b;
|
||||
|
||||
if (num <= 0)
|
||||
return;
|
||||
@ -346,8 +370,8 @@ 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));
|
||||
num, dat, dlen, ct_encode_string(d)));
|
||||
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
|
||||
|
||||
/* open up the space for num chars */
|
||||
if (num > 0) {
|
||||
@ -357,19 +381,24 @@ re_insert(EditLine *el __attribute__((__unused__)),
|
||||
*b-- = *a--;
|
||||
d[dlen] = '\0'; /* just in case */
|
||||
}
|
||||
|
||||
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));
|
||||
num, dat, dlen, ct_encode_string(d)));
|
||||
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
|
||||
|
||||
/* copy the characters */
|
||||
for (a = d + dat; (a < d + dlen) && (num > 0); num--)
|
||||
*a++ = *s++;
|
||||
|
||||
#ifdef notyet
|
||||
/* ct_encode_string() uses a static buffer, so we can't conveniently
|
||||
* encode both d & s here */
|
||||
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));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -379,9 +408,9 @@ re_insert(EditLine *el __attribute__((__unused__)),
|
||||
private void
|
||||
/*ARGSUSED*/
|
||||
re_delete(EditLine *el __attribute__((__unused__)),
|
||||
char *d, int dat, int dlen, int num)
|
||||
Char *d, int dat, int dlen, int num)
|
||||
{
|
||||
char *a, *b;
|
||||
Char *a, *b;
|
||||
|
||||
if (num <= 0)
|
||||
return;
|
||||
@ -391,7 +420,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, d));
|
||||
num, dat, dlen, ct_encode_string(d)));
|
||||
|
||||
/* open up the space for num chars */
|
||||
if (num > 0) {
|
||||
@ -403,7 +432,7 @@ 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, d));
|
||||
num, dat, dlen, ct_encode_string(d)));
|
||||
}
|
||||
|
||||
|
||||
@ -411,7 +440,7 @@ re_delete(EditLine *el __attribute__((__unused__)),
|
||||
* Like strncpy without padding.
|
||||
*/
|
||||
private void
|
||||
re__strncopy(char *a, char *b, size_t n)
|
||||
re__strncopy(Char *a, Char *b, size_t n)
|
||||
{
|
||||
|
||||
while (n-- && *b)
|
||||
@ -422,7 +451,7 @@ re__strncopy(char *a, char *b, size_t n)
|
||||
* 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
|
||||
* in the first or second diff, diff is the difference between the
|
||||
* number of characters between the new and old line.
|
||||
*/
|
||||
private void
|
||||
@ -442,7 +471,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);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
@ -470,12 +499,13 @@ 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)
|
||||
re_update_line(EditLine *el, Char *old, Char *new, int i)
|
||||
{
|
||||
char *o, *n, *p, c;
|
||||
char *ofd, *ols, *oe, *nfd, *nls, *ne;
|
||||
char *osb, *ose, *nsb, *nse;
|
||||
Char *o, *n, *p, c;
|
||||
Char *ofd, *ols, *oe, *nfd, *nls, *ne;
|
||||
Char *osb, *ose, *nsb, *nse;
|
||||
int fx, sx;
|
||||
size_t len;
|
||||
|
||||
/*
|
||||
* find first diff
|
||||
@ -602,12 +632,12 @@ re_update_line(EditLine *el, char *old, char *new, int i)
|
||||
* fx is the number of characters we need to insert/delete: in the
|
||||
* beginning to bring the two same begins together
|
||||
*/
|
||||
fx = (nsb - nfd) - (osb - ofd);
|
||||
fx = (int)((nsb - nfd) - (osb - ofd));
|
||||
/*
|
||||
* sx is the number of characters we need to insert/delete: in the
|
||||
* end to bring the two same last parts together
|
||||
*/
|
||||
sx = (nls - nse) - (ols - ose);
|
||||
sx = (int)((nls - nse) - (ols - ose));
|
||||
|
||||
if (!EL_CAN_INSERT) {
|
||||
if (fx > 0) {
|
||||
@ -656,8 +686,8 @@ re_update_line(EditLine *el, char *old, char *new, int i)
|
||||
/*
|
||||
* Now that we are done with pragmatics we recompute fx, sx
|
||||
*/
|
||||
fx = (nsb - nfd) - (osb - ofd);
|
||||
sx = (nls - nse) - (ols - ose);
|
||||
fx = (int)((nsb - nfd) - (osb - ofd));
|
||||
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",
|
||||
@ -688,7 +718,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:
|
||||
@ -712,7 +742,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.
|
||||
*/
|
||||
|
||||
@ -734,13 +764,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));
|
||||
/*
|
||||
* Move to the first char to insert, where the first diff is.
|
||||
*/
|
||||
term_move_to_char(el, nfd - new);
|
||||
terminal_move_to_char(el, (int)(nfd - new));
|
||||
/*
|
||||
* Check if we have stuff to keep at end
|
||||
*/
|
||||
@ -752,21 +782,22 @@ 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);
|
||||
re_insert(el, old, ofd - old,
|
||||
el->el_term.t_size.h, nfd, fx);
|
||||
terminal_insertwrite(el, nfd, fx);
|
||||
re_insert(el, old, (int)(ofd - old),
|
||||
el->el_terminal.t_size.h, nfd, fx);
|
||||
}
|
||||
/*
|
||||
* write (nsb-nfd) - fx chars of new starting at
|
||||
* (nfd + fx)
|
||||
*/
|
||||
term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
|
||||
re__strncopy(ofd + fx, nfd + fx,
|
||||
(size_t) ((nsb - nfd) - fx));
|
||||
len = (size_t) ((nsb - nfd) - fx);
|
||||
terminal_overwrite(el, (nfd + fx), len);
|
||||
re__strncopy(ofd + fx, nfd + fx, len);
|
||||
} else {
|
||||
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
|
||||
term_overwrite(el, nfd, (nsb - nfd));
|
||||
re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
|
||||
len = (size_t)(nsb - nfd);
|
||||
terminal_overwrite(el, nfd, len);
|
||||
re__strncopy(ofd, nfd, len);
|
||||
/*
|
||||
* Done
|
||||
*/
|
||||
@ -778,7 +809,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
|
||||
/*
|
||||
* move to the first char to delete where the first diff is
|
||||
*/
|
||||
term_move_to_char(el, ofd - old);
|
||||
terminal_move_to_char(el, (int)(ofd - old));
|
||||
/*
|
||||
* Check if we have stuff to save
|
||||
*/
|
||||
@ -791,15 +822,16 @@ 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);
|
||||
re_delete(el, old, ofd - old,
|
||||
el->el_term.t_size.h, -fx);
|
||||
terminal_deletechars(el, -fx);
|
||||
re_delete(el, old, (int)(ofd - old),
|
||||
el->el_terminal.t_size.h, -fx);
|
||||
}
|
||||
/*
|
||||
* write (nsb-nfd) chars of new starting at nfd
|
||||
*/
|
||||
term_overwrite(el, nfd, (nsb - nfd));
|
||||
re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
|
||||
len = (size_t) (nsb - nfd);
|
||||
terminal_overwrite(el, nfd, len);
|
||||
re__strncopy(ofd, nfd, len);
|
||||
|
||||
} else {
|
||||
ELRE_DEBUG(1, (__F,
|
||||
@ -807,8 +839,9 @@ 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));
|
||||
re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
|
||||
terminal_overwrite(el, nfd, (size_t)(nsb - nfd));
|
||||
re_clear_eol(el, fx, sx,
|
||||
(int)((oe - old) - (ne - new)));
|
||||
/*
|
||||
* Done
|
||||
*/
|
||||
@ -817,7 +850,7 @@ 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));
|
||||
/*
|
||||
@ -827,7 +860,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, (ose - old) + fx);
|
||||
terminal_move_to_char(el, (int)((ose - old) + fx));
|
||||
/*
|
||||
* Check if we have stuff to save
|
||||
*/
|
||||
@ -839,17 +872,18 @@ 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, (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, (nls - nse));
|
||||
re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
|
||||
terminal_overwrite(el, nse, (size_t)(nls - nse));
|
||||
re_clear_eol(el, fx, sx,
|
||||
(int)((oe - old) - (ne - new)));
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -859,7 +893,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
|
||||
ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
|
||||
nfd - new));
|
||||
|
||||
term_move_to_char(el, nfd - new);
|
||||
terminal_move_to_char(el, (int)(nfd - new));
|
||||
/*
|
||||
* Check if we have stuff to keep at the end
|
||||
*/
|
||||
@ -870,28 +904,29 @@ re_update_line(EditLine *el, char *old, char *new, int i)
|
||||
* to zero above as a flag saying that we hadn't done
|
||||
* an early first insert.
|
||||
*/
|
||||
fx = (nsb - nfd) - (osb - ofd);
|
||||
fx = (int)((nsb - nfd) - (osb - ofd));
|
||||
if (fx > 0) {
|
||||
/*
|
||||
* insert fx chars of new starting at nfd
|
||||
*/
|
||||
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
|
||||
"ERROR: cannot insert in late first diff\n"));
|
||||
term_insertwrite(el, nfd, fx);
|
||||
re_insert(el, old, ofd - old,
|
||||
el->el_term.t_size.h, nfd, fx);
|
||||
terminal_insertwrite(el, nfd, fx);
|
||||
re_insert(el, old, (int)(ofd - old),
|
||||
el->el_terminal.t_size.h, nfd, fx);
|
||||
}
|
||||
/*
|
||||
* write (nsb-nfd) - fx chars of new starting at
|
||||
* (nfd + fx)
|
||||
*/
|
||||
term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
|
||||
re__strncopy(ofd + fx, nfd + fx,
|
||||
(size_t) ((nsb - nfd) - fx));
|
||||
len = (size_t) ((nsb - nfd) - fx);
|
||||
terminal_overwrite(el, (nfd + fx), len);
|
||||
re__strncopy(ofd + fx, nfd + fx, len);
|
||||
} else {
|
||||
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
|
||||
term_overwrite(el, nfd, (nsb - nfd));
|
||||
re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
|
||||
len = (size_t) (nsb - nfd);
|
||||
terminal_overwrite(el, nfd, len);
|
||||
re__strncopy(ofd, nfd, len);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -899,24 +934,25 @@ 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", nse - new));
|
||||
term_move_to_char(el, nse - new);
|
||||
"second diff insert at %d...\r\n", (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, (nls - 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, (nls - nse));
|
||||
terminal_overwrite(el, nse, (size_t)(nls - nse));
|
||||
|
||||
/*
|
||||
* No need to do a clear-to-end here because we were
|
||||
@ -933,7 +969,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
|
||||
* Copy string and pad with spaces
|
||||
*/
|
||||
private void
|
||||
re__copy_and_pad(char *dst, const char *src, size_t width)
|
||||
re__copy_and_pad(Char *dst, const Char *src, size_t width)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -956,8 +992,8 @@ re__copy_and_pad(char *dst, const char *src, size_t width)
|
||||
protected void
|
||||
re_refresh_cursor(EditLine *el)
|
||||
{
|
||||
char *cp, c;
|
||||
int h, v, th;
|
||||
Char *cp;
|
||||
int h, v, th, w;
|
||||
|
||||
if (el->el_line.cursor >= el->el_line.lastchar) {
|
||||
if (el->el_map.current == el->el_map.alt
|
||||
@ -970,47 +1006,46 @@ 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++) {
|
||||
c = *cp;
|
||||
h++; /* all chars at least this long */
|
||||
|
||||
if (c == '\n') {/* handle newline in data part too */
|
||||
switch (ct_chr_class(*cp)) {
|
||||
case CHTYPE_NL: /* handle newline in data part too */
|
||||
h = 0;
|
||||
v++;
|
||||
} else {
|
||||
if (c == '\t') { /* if a tab, to next tab stop */
|
||||
while (h & 07) {
|
||||
h++;
|
||||
}
|
||||
} else if (iscntrl((unsigned char) c)) {
|
||||
/* if control char */
|
||||
h++;
|
||||
if (h > th) { /* if overflow, compensate */
|
||||
h = 1;
|
||||
v++;
|
||||
}
|
||||
} else if (!el_isprint((unsigned char) c)) {
|
||||
h += 3;
|
||||
if (h > th) { /* if overflow, compensate */
|
||||
h = h - th;
|
||||
v++;
|
||||
}
|
||||
break;
|
||||
case CHTYPE_TAB: /* if a tab, to next tab stop */
|
||||
while (++h & 07)
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
w = Width(*cp);
|
||||
if (w > 1 && h + w > th) { /* won't fit on line */
|
||||
h = 0;
|
||||
v++;
|
||||
}
|
||||
}
|
||||
h += ct_visual_width(*cp);
|
||||
break;
|
||||
}
|
||||
|
||||
if (h >= th) { /* check, extra long tabs picked up here also */
|
||||
h = 0;
|
||||
h -= th;
|
||||
v++;
|
||||
}
|
||||
}
|
||||
/* 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 (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);
|
||||
}
|
||||
|
||||
|
||||
@ -1018,12 +1053,19 @@ re_refresh_cursor(EditLine *el)
|
||||
* Add a character fast.
|
||||
*/
|
||||
private void
|
||||
re_fastputc(EditLine *el, int c)
|
||||
re_fastputc(EditLine *el, Int c)
|
||||
{
|
||||
int w = Width((Char)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;
|
||||
if (el->el_cursor.h >= el->el_term.t_size.h) {
|
||||
while (--w > 0)
|
||||
el->el_display[el->el_cursor.v][el->el_cursor.h++]
|
||||
= MB_FILL_CHAR;
|
||||
|
||||
if (el->el_cursor.h >= el->el_terminal.t_size.h) {
|
||||
/* if we must overflow */
|
||||
el->el_cursor.h = 0;
|
||||
|
||||
@ -1033,27 +1075,27 @@ 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;
|
||||
Char *firstline = el->el_display[0];
|
||||
|
||||
for(i=1; i < lins; i++)
|
||||
el->el_display[i-1] = el->el_display[i];
|
||||
for(i = 1; i < lins; i++)
|
||||
el->el_display[i - 1] = el->el_display[i];
|
||||
|
||||
re__copy_and_pad(firstline, "", 0);
|
||||
el->el_display[i-1] = firstline;
|
||||
re__copy_and_pad(firstline, STR(""), (size_t)0);
|
||||
el->el_display[i - 1] = firstline;
|
||||
} else {
|
||||
el->el_cursor.v++;
|
||||
el->el_refresh.r_oldcv++;
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1066,7 +1108,7 @@ re_fastputc(EditLine *el, int c)
|
||||
protected void
|
||||
re_fastaddc(EditLine *el)
|
||||
{
|
||||
char c;
|
||||
Char c;
|
||||
int rhdiff;
|
||||
|
||||
c = el->el_line.cursor[-1];
|
||||
@ -1075,25 +1117,30 @@ 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 */
|
||||
return;
|
||||
} /* else (only do at end of line, no TAB) */
|
||||
if (iscntrl((unsigned char) c)) { /* if control char, do caret */
|
||||
char mc = (c == '\177') ? '?' : (c | 0100);
|
||||
re_fastputc(el, '^');
|
||||
re_fastputc(el, mc);
|
||||
} else if (el_isprint((unsigned char) c)) { /* normal char */
|
||||
switch (ct_chr_class(c)) {
|
||||
case CHTYPE_TAB: /* already handled, should never happen here */
|
||||
break;
|
||||
case CHTYPE_NL:
|
||||
case CHTYPE_PRINT:
|
||||
re_fastputc(el, c);
|
||||
} else {
|
||||
re_fastputc(el, '\\');
|
||||
re_fastputc(el, (int)(((((unsigned int)c) >> 6) & 3) + '0'));
|
||||
re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0'));
|
||||
re_fastputc(el, (c & 7) + '0');
|
||||
break;
|
||||
case CHTYPE_ASCIICTL:
|
||||
case CHTYPE_NONPRINT: {
|
||||
Char visbuf[VISUAL_WIDTH_MAX];
|
||||
ssize_t i, n =
|
||||
ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c);
|
||||
for (i = 0; n-- > 0; ++i)
|
||||
re_fastputc(el, visbuf[i]);
|
||||
break;
|
||||
}
|
||||
term__flush(el);
|
||||
}
|
||||
terminal__flush(el);
|
||||
}
|
||||
|
||||
|
||||
@ -1107,7 +1154,7 @@ re_clear_display(EditLine *el)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -1122,17 +1169,16 @@ re_clear_lines(EditLine *el)
|
||||
|
||||
if (EL_CAN_CEOL) {
|
||||
int i;
|
||||
term_move_to_char(el, 0);
|
||||
for (i = 0; i <= el->el_refresh.r_oldcv; i++) {
|
||||
for (i = el->el_refresh.r_oldcv; i >= 0; i--) {
|
||||
/* for each line on the screen */
|
||||
term_move_to_line(el, i);
|
||||
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);
|
||||
}
|
||||
term_move_to_line(el, 0);
|
||||
} 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