void tty_cmd_clearscreen( struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; u_int i, j; tty_reset(tty); tty_region(tty, 0, screen_size_y(s) - 1, wp->yoff); tty_cursor(tty, 0, 0, wp->xoff, wp->yoff); if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { for (i = 0; i < screen_size_y(s); i++) { tty_putcode(tty, TTYC_EL); if (i != screen_size_y(s) - 1) { tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); tty->cy++; } } } else { for (j = 0; j < screen_size_y(s); j++) { tty_cursor(tty, 0, j, wp->xoff, wp->yoff); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, ' '); } } }
/* Move cursor inside pane. */ void tty_cursor_pane(struct tty *tty, const struct tty_ctx *ctx, u_int cx, u_int cy) { struct window_pane *wp = ctx->wp; tty_cursor(tty, wp->xoff + cx, wp->yoff + cy); }
void tty_cmd_insertcharacter(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; u_int ua; if (wp->xoff != 0 || screen_size_x(s) < tty->sx) { tty_draw_line(tty, wp->screen, s->old_cy, wp->xoff, wp->yoff); return; } ua = va_arg(ap, u_int); tty_reset(tty); tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); if (tty_term_has(tty->term, TTYC_ICH) || tty_term_has(tty->term, TTYC_ICH1)) tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ua); else { tty_putcode(tty, TTYC_SMIR); while (ua-- > 0) tty_putc(tty, ' '); tty_putcode(tty, TTYC_RMIR); } }
void tty_cmd_clearstartofline( struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; u_int i; tty_reset(tty); if (wp->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) { tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_putcode(tty, TTYC_EL1); } else { tty_cursor(tty, 0, s->old_cy, wp->xoff, wp->yoff); for (i = 0; i < s->old_cx + 1; i++) tty_putc(tty, ' '); } }
void tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) { const struct grid_cell *gc; const struct grid_utf8 *gu; u_int i, sx; sx = screen_size_x(s); if (sx > s->grid->size[s->grid->hsize + py]) sx = s->grid->size[s->grid->hsize + py]; if (sx > tty->sx) sx = tty->sx; tty_cursor(tty, 0, py, ox, oy); for (i = 0; i < sx; i++) { gc = grid_view_peek_cell(s->grid, i, py); gu = NULL; if (gc->flags & GRID_FLAG_UTF8) gu = grid_view_peek_utf8(s->grid, i, py); if (screen_check_selection(s, i, py)) { s->sel.cell.data = gc->data; tty_cell(tty, &s->sel.cell, gu); } else tty_cell(tty, gc, gu); } if (sx >= tty->sx) return; tty_reset(tty); tty_cursor(tty, sx, py, ox, oy); if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { for (i = sx; i < screen_size_x(s); i++) tty_putc(tty, ' '); } }
/* Set region at absolute position. */ void tty_region(struct tty *tty, u_int rupper, u_int rlower) { if (tty->rlower == rlower && tty->rupper == rupper) return; if (!tty_term_has(tty->term, TTYC_CSR)) return; tty->rupper = rupper; tty->rlower = rlower; /* * Some terminals (such as PuTTY) do not correctly reset the cursor to * 0,0 if it is beyond the last column (they do not reset their wrap * flag so further output causes a line feed). As a workaround, do an * explicit move to 0 first. */ if (tty->cx >= tty->sx) tty_cursor(tty, 0, tty->cy); tty_putcode2(tty, TTYC_CSR, tty->rupper, tty->rlower); tty_cursor(tty, 0, 0); }
void tty_cmd_cell(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; struct grid_cell *gc; struct grid_utf8 *gu; gc = va_arg(ap, struct grid_cell *); gu = va_arg(ap, struct grid_utf8 *); tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_cell(tty, gc, gu); }
void tty_cmd_alignmenttest( struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; u_int i, j; tty_reset(tty); tty_region(tty, 0, screen_size_y(s) - 1, wp->yoff); for (j = 0; j < screen_size_y(s); j++) { tty_cursor(tty, 0, j, wp->xoff, wp->yoff); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, 'E'); } }
void tty_cmd_clearendofline( struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; u_int i; tty_reset(tty); tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { for (i = s->old_cx; i < screen_size_x(s); i++) tty_putc(tty, ' '); } }
void tty_cmd_deletecharacter(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; u_int ua; if (wp->xoff != 0 || screen_size_x(s) < tty->sx) { tty_draw_line(tty, wp->screen, s->old_cy, wp->xoff, wp->yoff); return; } ua = va_arg(ap, u_int); tty_reset(tty); tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ua); }
void tty_cmd_linefeed(struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; if (wp->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { tty_redraw_region(tty, wp); return; } tty_reset(tty); tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); if (s->old_cy == s->old_rlower) { tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_putc(tty, '\n'); } }
void tty_cmd_deleteline(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; u_int ua; if (wp->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { tty_redraw_region(tty, wp); return; } ua = va_arg(ap, u_int); tty_reset(tty); tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ua); }
int tty_resize(struct tty *tty) { struct winsize ws; u_int sx, sy; if (ioctl(tty->fd, TIOCGWINSZ, &ws) != -1) { sx = ws.ws_col; if (sx == 0) sx = 80; sy = ws.ws_row; if (sy == 0) sy = 24; } else { sx = 80; sy = 24; } if (sx == tty->sx && sy == tty->sy) return (0); tty->sx = sx; tty->sy = sy; tty->cx = UINT_MAX; tty->cy = UINT_MAX; tty->rupper = UINT_MAX; tty->rlower = UINT_MAX; /* * If the terminal has been started, reset the actual scroll region and * cursor position, as this may not have happened. */ if (tty->flags & TTY_STARTED) { tty_cursor(tty, 0, 0); tty_region(tty, 0, tty->sy - 1); } return (1); }
void tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) { const struct grid_cell *gc; struct grid_line *gl; struct grid_cell tmpgc; const struct grid_utf8 *gu; u_int i, sx; tty_update_mode(tty, tty->mode & ~MODE_CURSOR, s); sx = screen_size_x(s); if (sx > s->grid->linedata[s->grid->hsize + py].cellsize) sx = s->grid->linedata[s->grid->hsize + py].cellsize; if (sx > tty->sx) sx = tty->sx; /* * Don't move the cursor to the start permission if it will wrap there * itself. */ gl = NULL; if (py != 0) gl = &s->grid->linedata[s->grid->hsize + py - 1]; if (oy + py == 0 || gl == NULL || !(gl->flags & GRID_LINE_WRAPPED) || tty->cx < tty->sx || ox != 0 || (oy + py != tty->cy + 1 && tty->cy != s->rlower + oy)) tty_cursor(tty, ox, oy + py); for (i = 0; i < sx; i++) { gc = grid_view_peek_cell(s->grid, i, py); gu = NULL; if (gc->flags & GRID_FLAG_UTF8) gu = grid_view_peek_utf8(s->grid, i, py); if (screen_check_selection(s, i, py)) { memcpy(&tmpgc, &s->sel.cell, sizeof tmpgc); tmpgc.data = gc->data; tmpgc.flags = gc->flags & ~(GRID_FLAG_FG256|GRID_FLAG_BG256); tmpgc.flags |= s->sel.cell.flags & (GRID_FLAG_FG256|GRID_FLAG_BG256); tty_cell(tty, &tmpgc, gu); } else tty_cell(tty, gc, gu); } if (sx >= tty->sx) { tty_update_mode(tty, tty->mode, s); return; } tty_reset(tty); tty_cursor(tty, ox + sx, oy + py); if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { for (i = sx; i < screen_size_x(s); i++) tty_putc(tty, ' '); } tty_update_mode(tty, tty->mode, s); }
/* Move cursor inside pane. */ void tty_cursor_pane(struct tty *tty, const struct tty_ctx *ctx, u_int cx, u_int cy) { tty_cursor(tty, ctx->xoff + cx, ctx->yoff + cy); }