diff options
| author | Pedro F. Giffuni <pfg@FreeBSD.org> | 2017-09-13 15:57:58 +0000 |
|---|---|---|
| committer | Pedro F. Giffuni <pfg@FreeBSD.org> | 2017-09-13 15:57:58 +0000 |
| commit | 8c36b0434ca4a5ba6df2724542048eb219af7a34 (patch) | |
| tree | b6315213d0c73ac7d01023a1a82d568559b68b19 /refresh.c | |
| parent | 70f1d4d70d0c78aa69c52d977130f4046851c4a3 (diff) | |
Diffstat (limited to 'refresh.c')
| -rw-r--r-- | refresh.c | 176 |
1 files changed, 105 insertions, 71 deletions
diff --git a/refresh.c b/refresh.c index b210e8a47522..fe5187c5f066 100644 --- a/refresh.c +++ b/refresh.c @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.c,v 1.45 2016/03/02 19:24:20 christos Exp $ */ +/* $NetBSD: refresh.c,v 1.54 2017/06/30 20:26:52 kre 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.45 2016/03/02 19:24:20 christos Exp $"); +__RCSID("$NetBSD: refresh.c,v 1.54 2017/06/30 20:26:52 kre Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -50,18 +50,18 @@ __RCSID("$NetBSD: refresh.c,v 1.45 2016/03/02 19:24:20 christos Exp $"); #include "el.h" -private void re_nextline(EditLine *); -private void re_addc(EditLine *, wint_t); -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 *, wint_t); -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 \ if (/*CONSTCOND*/ a) { \ @@ -74,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)); @@ -91,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. */ @@ -104,7 +104,7 @@ re_nextline(EditLine *el) */ 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]; + wchar_t *firstline = el->el_vdisplay[0]; for(i = 1; i < lins; i++) el->el_vdisplay[i - 1] = el->el_vdisplay[i]; @@ -123,10 +123,10 @@ re_nextline(EditLine *el) /* re_addc(): * Draw c, expanding tabs, control chars etc. */ -private void +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); @@ -145,9 +145,9 @@ re_addc(EditLine *el, wint_t 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; @@ -155,35 +155,66 @@ re_addc(EditLine *el, wint_t c) } } +/* re_putliteral(): + * Place the literal string given + */ +libedit_private void +re_putliteral(EditLine *el, const wchar_t *begin, const wchar_t *end) +{ + coord_t *cur = &el->el_refresh.r_cursor; + wint_t c; + int sizeh = el->el_terminal.t_size.h; + int i, w; + + c = literal_add(el, begin, end, &w); + if (c == 0 || w <= 0) + return; + el->el_vdisplay[cur->v][cur->h] = c; + + i = w; + if (i > sizeh - cur->h) /* avoid overflow */ + i = sizeh - cur->h; + while (--i > 0) + el->el_vdisplay[cur->v][cur->h + i] = MB_FILL_CHAR; + + cur->h += w; + if (cur->h >= sizeh) { + /* assure end of line */ + el->el_vdisplay[cur->v][sizeh] = '\0'; + re_nextline(el); + } +} /* re_putc(): * Draw the character given */ -protected void +libedit_private void re_putc(EditLine *el, wint_t c, int shift) { - int i, w = Width(c); + coord_t *cur = &el->el_refresh.r_cursor; + int i, w = wcwidth(c); + int sizeh = el->el_terminal.t_size.h; + 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_terminal.t_size.h)) + while (shift && (cur->h + w > sizeh)) re_putc(el, ' ', 1); - el->el_vdisplay[el->el_refresh.r_cursor.v] - [el->el_refresh.r_cursor.h] = (Char)c; + el->el_vdisplay[cur->v][cur->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[cur->v][cur->h + i] = MB_FILL_CHAR; if (!shift) return; - el->el_refresh.r_cursor.h += w; /* advance to next place */ - if (el->el_refresh.r_cursor.h >= el->el_terminal.t_size.h) { + cur->h += w; /* advance to next place */ + if (cur->h >= sizeh) { /* assure end of line */ - el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_terminal.t_size.h] - = '\0'; + el->el_vdisplay[cur->v][sizeh] = '\0'; re_nextline(el); } } @@ -195,23 +226,26 @@ re_putc(EditLine *el, wint_t c, int shift) * 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 = :" FSTR ":\r\n", + ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%ls:\r\n", el->el_line.buffer)); + literal_clear(el); /* reset the Drawing cursor */ el->el_refresh.r_cursor.h = 0; el->el_refresh.r_cursor.v = 0; + terminal_move_to_char(el, 0); + /* temporarily draw rprompt to calculate its size */ prompt_print(el, EL_RPROMPT); @@ -251,7 +285,7 @@ re_refresh(EditLine *el) 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; @@ -319,10 +353,10 @@ re_refresh(EditLine *el) for (; i <= el->el_refresh.r_oldcv; 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])); + /* This wcslen should be safe even with MB_FILL_CHARs */ + terminal_clear_EOL(el, (int) wcslen(el->el_display[i])); #ifdef DEBUG_REFRESH - terminal_overwrite(el, STR("C\b"), 2); + terminal_overwrite(el, L"C\b", 2); #endif /* DEBUG_REFRESH */ el->el_display[i][0] = '\0'; } @@ -340,7 +374,7 @@ re_refresh(EditLine *el) /* re_goto_bottom(): * used to go to last used screen line */ -protected void +libedit_private void re_goto_bottom(EditLine *el) { @@ -355,12 +389,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; @@ -406,12 +440,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; @@ -440,8 +474,8 @@ re_delete(EditLine *el __attribute__((__unused__)), /* 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) @@ -455,7 +489,7 @@ re__strncopy(Char *a, Char *b, size_t n) * in the first or second diff, diff is the difference between the * number of characters between the new and old line. */ -private void +static void re_clear_eol(EditLine *el, int fx, int sx, int diff) { @@ -499,12 +533,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; @@ -561,7 +595,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; @@ -969,8 +1003,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; @@ -990,10 +1024,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) { @@ -1021,7 +1055,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++; @@ -1037,7 +1071,7 @@ 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++; @@ -1053,15 +1087,15 @@ re_refresh_cursor(EditLine *el) /* re_fastputc(): * Add a character fast. */ -private void +static void re_fastputc(EditLine *el, wint_t c) { - int w = Width((Char)c); + int w = wcwidth(c); while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h) re_fastputc(el, ' '); terminal__putc(el, c); - el->el_display[el->el_cursor.v][el->el_cursor.h++] = (Char)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; @@ -1078,12 +1112,12 @@ re_fastputc(EditLine *el, wint_t c) */ 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]; + 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(""), (size_t)0); + re__copy_and_pad(firstline, L"", (size_t)0); el->el_display[i - 1] = firstline; } else { el->el_cursor.v++; @@ -1106,10 +1140,10 @@ re_fastputc(EditLine *el, wint_t 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]; @@ -1133,9 +1167,9 @@ 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; @@ -1148,7 +1182,7 @@ re_fastaddc(EditLine *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; @@ -1164,7 +1198,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) { |
