/* re_putc(): * Draw the character given */ libedit_private void re_putc(EditLine *el, wint_t c, int shift) { 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 && (cur->h + w > sizeh)) re_putc(el, ' ', 1); 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[cur->v][cur->h + i] = MB_FILL_CHAR; if (!shift) return; cur->h += w; /* advance to next place */ if (cur->h >= sizeh) { /* assure end of line */ el->el_vdisplay[cur->v][sizeh] = '\0'; re_nextline(el); } }
/* re_addc(): * Draw c, expanding tabs, control chars etc. */ static void re_addc(EditLine *el, wint_t c) { switch (ct_chr_class(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 */ } 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: { wchar_t visbuf[VISUAL_WIDTH_MAX]; ssize_t i, n = ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c); for (i = 0; n-- > 0; ++i) re_putc(el, visbuf[i], 1); break; } } }
/* 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); } }