diff --git a/cmd-attach-session.c b/cmd-attach-session.c index d29c4dd1..e9c23df3 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -98,6 +98,8 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, environ_update(s->options, c->environ, s->environ); c->session = s; + if (!item->repeat) + server_client_set_key_table(c, NULL); status_timer_start(c); notify_client("client-session-changed", c); session_update_activity(s, NULL); diff --git a/cmd-new-session.c b/cmd-new-session.c index 4e7b413b..deda88f2 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -277,6 +277,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) } else if (c->session != NULL) c->last_session = c->session; c->session = s; + if (!item->repeat) + server_client_set_key_table(c, NULL); status_timer_start(c); notify_client("client-session-changed", c); session_update_activity(s, NULL); diff --git a/cmd-switch-client.c b/cmd-switch-client.c index 5cf4756f..5bcdbb78 100644 --- a/cmd-switch-client.c +++ b/cmd-switch-client.c @@ -108,6 +108,8 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) if (c->session != NULL && c->session != s) c->last_session = c->session; c->session = s; + if (!item->repeat) + server_client_set_key_table(c, NULL); status_timer_start(c); session_update_activity(s, NULL); gettimeofday(&s->last_attached_time, NULL); diff --git a/input.c b/input.c index 17f81dd7..26eb1686 100644 --- a/input.c +++ b/input.c @@ -87,6 +87,7 @@ struct input_ctx { struct utf8_data utf8data; int ch; + int flags; #define INPUT_DISCARD 0x1 @@ -871,9 +872,10 @@ input_parse(struct window_pane *wp) buf = EVBUFFER_DATA(evb); len = EVBUFFER_LENGTH(evb); - notify_input(wp, evb); off = 0; + notify_input(wp, evb); + log_debug("%s: %%%u %s, %zu bytes: %.*s", __func__, wp->id, ictx->state->name, len, (int)len, buf); @@ -1218,11 +1220,13 @@ input_csi_dispatch(struct input_ctx *ictx) if (ictx->flags & INPUT_DISCARD) return (0); - if (input_split(ictx) != 0) - return (0); + log_debug("%s: '%c' \"%s\" \"%s\"", __func__, ictx->ch, ictx->interm_buf, ictx->param_buf); + if (input_split(ictx) != 0) + return (0); + entry = bsearch(ictx, input_csi_table, nitems(input_csi_table), sizeof input_csi_table[0], input_table_compare); if (entry == NULL) { @@ -1327,7 +1331,7 @@ input_csi_dispatch(struct input_ctx *ictx) screen_write_clearendofscreen(sctx, ictx->cell.cell.bg); break; case 1: - screen_write_clearstartofscreen(sctx); + screen_write_clearstartofscreen(sctx, ictx->cell.cell.bg); break; case 2: screen_write_clearscreen(sctx, ictx->cell.cell.bg); diff --git a/key-bindings.c b/key-bindings.c index 4cbb34ec..d96b51f6 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -400,8 +400,9 @@ void key_bindings_dispatch(struct key_binding *bd, struct client *c, struct mouse_event *m, struct cmd_find_state *fs) { - struct cmd *cmd; - int readonly; + struct cmd *cmd; + struct cmdq_item *item; + int readonly; readonly = 1; TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) { @@ -410,6 +411,9 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c, } if (!readonly && (c->flags & CLIENT_READONLY)) cmdq_append(c, cmdq_get_callback(key_bindings_read_only, NULL)); - else - cmdq_append(c, cmdq_get_command(bd->cmdlist, fs, m, 0)); + else { + item = cmdq_get_command(bd->cmdlist, fs, m, 0); + item->repeat = bd->can_repeat; + cmdq_append(c, item); + } } diff --git a/screen-write.c b/screen-write.c index 227316cb..fe8419e3 100644 --- a/screen-write.c +++ b/screen-write.c @@ -31,8 +31,8 @@ static void screen_write_flush(struct screen_write_ctx *); static int screen_write_overwrite(struct screen_write_ctx *, struct grid_cell *, u_int); -static int screen_write_combine(struct screen_write_ctx *, - const struct utf8_data *); +static const struct grid_cell *screen_write_combine(struct screen_write_ctx *, + const struct utf8_data *, u_int *); static const struct grid_cell screen_write_pad_cell = { GRID_FLAG_PADDING, 0, 8, 8, { { 0 }, 0, 0, 0 } @@ -971,24 +971,25 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg) /* Clear to start of screen. */ void -screen_write_clearstartofscreen(struct screen_write_ctx *ctx) +screen_write_clearstartofscreen(struct screen_write_ctx *ctx, u_int bg) { struct screen *s = ctx->s; struct tty_ctx ttyctx; u_int sx = screen_size_x(s); screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; if (s->cy > 0) { screen_dirty_clear(s, 0, 0, sx - 1, s->cy); - grid_view_clear(s->grid, 0, 0, sx, s->cy, 8); + grid_view_clear(s->grid, 0, 0, sx, s->cy, bg); } if (s->cx > sx - 1) { screen_dirty_clear(s, 0, s->cy, sx - 1, s->cy); - grid_view_clear(s->grid, 0, s->cy, sx, 1, 8); + grid_view_clear(s->grid, 0, s->cy, sx, 1, bg); } else { screen_dirty_clear(s, 0, s->cy, s->cx, s->cy); - grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1, 8); + grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1, bg); } tty_write(tty_cmd_clearstartofscreen, &ttyctx); @@ -1061,9 +1062,11 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) * there is space. */ if (width == 0) { - if (screen_write_combine(ctx, &gc->data) == 0) { + if ((gc = screen_write_combine(ctx, &gc->data, &xx)) != 0) { + screen_write_cursormove(ctx, xx, s->cy); screen_write_initctx(ctx, &ttyctx); - tty_write(tty_cmd_utf8character, &ttyctx); + ttyctx.cell = gc; + tty_write(tty_cmd_cell, &ttyctx); } return; } @@ -1203,36 +1206,48 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) } /* Combine a UTF-8 zero-width character onto the previous. */ -static int -screen_write_combine(struct screen_write_ctx *ctx, const struct utf8_data *ud) +static const struct grid_cell * +screen_write_combine(struct screen_write_ctx *ctx, const struct utf8_data *ud, + u_int *xx) { struct screen *s = ctx->s; struct grid *gd = s->grid; - struct grid_cell gc; + static struct grid_cell gc; + u_int n; /* Can't combine if at 0. */ if (s->cx == 0) - return (-1); + return (NULL); /* Empty data is out. */ if (ud->size == 0) fatalx("UTF-8 data empty"); /* Retrieve the previous cell. */ - grid_view_get_cell(gd, s->cx - 1, s->cy, &gc); + for (n = 1; n < s->cx; n++) { + grid_view_get_cell(gd, s->cx - n, s->cy, &gc); + if (~gc.flags & GRID_FLAG_PADDING) + break; + } + if (n == s->cx) + return (NULL); + *xx = s->cx - n; /* Check there is enough space. */ if (gc.data.size + ud->size > sizeof gc.data.data) - return (-1); + return (NULL); + + log_debug("%s: %.*s onto %.*s at %u,%u", __func__, (int)ud->size, + ud->data, (int)gc.data.size, gc.data.data, *xx, s->cy); /* Append the data. */ memcpy(gc.data.data + gc.data.size, ud->data, ud->size); gc.data.size += ud->size; /* Set the new cell. */ - grid_view_set_cell(gd, s->cx - 1, s->cy, &gc); + grid_view_set_cell(gd, *xx, s->cy, &gc); - return (0); + return (&gc); } /* diff --git a/tmux.h b/tmux.h index 9dee7a1a..b8972fd8 100644 --- a/tmux.h +++ b/tmux.h @@ -242,6 +242,7 @@ enum tty_code_code { TTYC_DL1, /* delete_line, dl */ TTYC_E3, TTYC_ECH, /* erase_chars, ec */ + TTYC_ED, /* csr_eos, cd */ TTYC_EL, /* clr_eol, ce */ TTYC_EL1, /* clr_bol, cb */ TTYC_ENACS, /* ena_acs, eA */ @@ -1056,6 +1057,9 @@ struct tty { struct grid_cell cell; + int last_wp; + struct grid_cell last_cell; + #define TTY_NOCURSOR 0x1 #define TTY_FREEZE 0x2 #define TTY_TIMER 0x4 @@ -1228,6 +1232,7 @@ struct cmdq_item { struct cmd_list *cmdlist; struct cmd *cmd; + int repeat; cmdq_cb cb; void *data; @@ -1669,7 +1674,6 @@ void tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *); void tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *); void tty_cmd_insertline(struct tty *, const struct tty_ctx *); void tty_cmd_linefeed(struct tty *, const struct tty_ctx *); -void tty_cmd_utf8character(struct tty *, const struct tty_ctx *); void tty_cmd_reverseindex(struct tty *, const struct tty_ctx *); void tty_cmd_setselection(struct tty *, const struct tty_ctx *); void tty_cmd_rawstring(struct tty *, const struct tty_ctx *); @@ -1994,7 +1998,7 @@ void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int); void screen_write_linefeed(struct screen_write_ctx *, int); void screen_write_carriagereturn(struct screen_write_ctx *); void screen_write_clearendofscreen(struct screen_write_ctx *, u_int); -void screen_write_clearstartofscreen(struct screen_write_ctx *); +void screen_write_clearstartofscreen(struct screen_write_ctx *, u_int); void screen_write_clearscreen(struct screen_write_ctx *, u_int); void screen_write_clearhistory(struct screen_write_ctx *); void screen_write_cell(struct screen_write_ctx *, const struct grid_cell *); diff --git a/tty-term.c b/tty-term.c index 0fcf5205..10475d04 100644 --- a/tty-term.c +++ b/tty-term.c @@ -87,6 +87,7 @@ static const struct tty_term_code_entry tty_term_codes[] = { [TTYC_DL1] = { TTYCODE_STRING, "dl1" }, [TTYC_E3] = { TTYCODE_STRING, "E3" }, [TTYC_ECH] = { TTYCODE_STRING, "ech" }, + [TTYC_ED] = { TTYCODE_STRING, "ed" }, [TTYC_EL] = { TTYCODE_STRING, "el" }, [TTYC_EL1] = { TTYCODE_STRING, "el1" }, [TTYC_ENACS] = { TTYCODE_STRING, "enacs" }, diff --git a/tty.c b/tty.c index f50fbdb2..b99305ce 100644 --- a/tty.c +++ b/tty.c @@ -64,6 +64,8 @@ static int tty_large_region(struct tty *, const struct tty_ctx *); static int tty_fake_bce(const struct tty *, const struct window_pane *, u_int); static void tty_redraw_region(struct tty *, const struct tty_ctx *); +static void tty_clear_area(struct tty *, const struct tty_ctx *ctx, u_int, + u_int, u_int, u_int); static void tty_emulate_repeat(struct tty *, enum tty_code_code, enum tty_code_code, u_int); static void tty_repeat_space(struct tty *, u_int); @@ -79,7 +81,7 @@ static void tty_default_attributes(struct tty *, const struct window_pane *, #define tty_use_margin(tty) \ ((tty)->term_type == TTY_VT420) -#define tty_pane_full_width(tty, ctx) \ +#define tty_pane_full_width(tty, ctx) \ ((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) void @@ -246,6 +248,9 @@ tty_start_tty(struct tty *tty) tty_putcode(tty, TTYC_SGR0); memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell); + memcpy(&tty->last_cell, &grid_default_cell, sizeof tty->last_cell); + tty->last_wp = -1; + tty_putcode(tty, TTYC_RMKX); if (tty_use_acs(tty)) tty_putcode(tty, TTYC_ENACS); @@ -682,6 +687,17 @@ tty_redraw_region(struct tty *tty, const struct tty_ctx *ctx) } } +static void +tty_clear_area(struct tty *tty, const struct tty_ctx *ctx, u_int sx, u_int sy, + u_int ex, u_int ey) +{ + char s[64]; + + snprintf (s, sizeof s, "\033[32;%u;%u;%u;%u$x", ctx->yoff + sy + 1, + ctx->xoff + sx + 1, ctx->yoff + ey + 1, ctx->xoff + ex + 1); + tty_puts(tty, s); +} + void tty_draw_pane(struct tty *tty, const struct window_pane *wp, u_int py, u_int ox, u_int oy) @@ -895,6 +911,7 @@ tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; + u_int sx = screen_size_x(s); tty_default_attributes(tty, wp, ctx->bg); @@ -904,8 +921,11 @@ tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx) !tty_fake_bce(tty, wp, ctx->bg) && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); + else if (tty->term_type == TTY_VT420 && + !tty_fake_bce(tty, wp, ctx->bg)) + tty_clear_area(tty, ctx, 0, ctx->ocy, sx - 1, ctx->ocy); else - tty_repeat_space(tty, screen_size_x(s)); + tty_repeat_space(tty, sx); } void @@ -913,6 +933,7 @@ tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; + u_int sx = screen_size_x(s); tty_default_attributes(tty, wp, ctx->bg); @@ -922,8 +943,11 @@ tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx) tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp, ctx->bg)) tty_putcode(tty, TTYC_EL); + else if (tty->term_type == TTY_VT420 && + !tty_fake_bce(tty, wp, ctx->bg)) + tty_clear_area(tty, ctx, ctx->ocx, ctx->ocy, sx - 1, ctx->ocy); else - tty_repeat_space(tty, screen_size_x(s) - ctx->ocx); + tty_repeat_space(tty, sx - ctx->ocx); } void @@ -938,7 +962,10 @@ tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) !tty_fake_bce(tty, ctx->wp, ctx->bg)) { tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putcode(tty, TTYC_EL1); - } else { + } else if (tty->term_type == TTY_VT420 && + !tty_fake_bce(tty, wp, ctx->bg)) + tty_clear_area(tty, ctx, 0, ctx->ocy, ctx->ocx, ctx->ocy); + else { tty_cursor_pane(tty, ctx, 0, ctx->ocy); tty_repeat_space(tty, ctx->ocx + 1); } @@ -1020,32 +1047,51 @@ tty_cmd_clearendofscreen(struct tty *tty, const struct tty_ctx *ctx) struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; u_int i, j; + u_int sx = screen_size_x(s), sy = screen_size_y(s); tty_default_attributes(tty, wp, ctx->bg); - tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); + tty_region_pane(tty, ctx, 0, sy - 1); tty_margin_off(tty); - tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); if (tty_pane_full_width(tty, ctx) && + status_at_line(tty->client) <= 0 && + tty_term_has(tty->term, TTYC_ED)) { + tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); + tty_putcode(tty, TTYC_ED); + } else if (tty->term_type == TTY_VT420 && + !tty_fake_bce(tty, wp, ctx->bg)) { + tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); + if (tty_pane_full_width(tty, ctx) && + tty_term_has(tty->term, TTYC_EL)) + tty_putcode(tty, TTYC_EL); + else + tty_repeat_space(tty, sx - ctx->ocx); + if (ctx->ocy != sy - 1) { + tty_clear_area(tty, ctx, 0, ctx->ocy + 1, sx - 1, + sy - 1); + } + } else if (tty_pane_full_width(tty, ctx) && tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp, ctx->bg)) { + tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putcode(tty, TTYC_EL); - if (ctx->ocy != screen_size_y(s) - 1) { + if (ctx->ocy != sy - 1) { tty_cursor_pane(tty, ctx, 0, ctx->ocy + 1); - for (i = ctx->ocy + 1; i < screen_size_y(s); i++) { + for (i = ctx->ocy + 1; i < sy; i++) { tty_putcode(tty, TTYC_EL); - if (i == screen_size_y(s) - 1) + if (i == sy - 1) continue; tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); tty->cy++; } } } else { - tty_repeat_space(tty, screen_size_x(s) - ctx->ocx); - for (j = ctx->ocy + 1; j < screen_size_y(s); j++) { + tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); + tty_repeat_space(tty, sx - ctx->ocx); + for (j = ctx->ocy + 1; j < sy; j++) { tty_cursor_pane(tty, ctx, 0, j); - tty_repeat_space(tty, screen_size_x(s)); + tty_repeat_space(tty, sx); } } } @@ -1056,27 +1102,33 @@ tty_cmd_clearstartofscreen(struct tty *tty, const struct tty_ctx *ctx) struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; u_int i, j; + u_int sx = screen_size_x(s), sy = screen_size_y(s); - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); - tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); + tty_region_pane(tty, ctx, 0, sy - 1); tty_margin_off(tty); - tty_cursor_pane(tty, ctx, 0, 0); - if (tty_pane_full_width(tty, ctx) && + if (tty->term_type == TTY_VT420 && + !tty_fake_bce(tty, wp, ctx->bg)) + tty_clear_area(tty, ctx, 0, 0, sx - 1, ctx->ocy - 1); + else if (tty_pane_full_width(tty, ctx) && tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp, ctx->bg)) { + tty_cursor_pane(tty, ctx, 0, 0); for (i = 0; i < ctx->ocy; i++) { tty_putcode(tty, TTYC_EL); tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); tty->cy++; } } else { + tty_cursor_pane(tty, ctx, 0, 0); for (j = 0; j < ctx->ocy; j++) { tty_cursor_pane(tty, ctx, 0, j); - tty_repeat_space(tty, screen_size_x(s)); + tty_repeat_space(tty, sx); } } + tty_cursor_pane(tty, ctx, 0, ctx->ocy); tty_repeat_space(tty, ctx->ocx + 1); } @@ -1086,27 +1138,37 @@ tty_cmd_clearscreen(struct tty *tty, const struct tty_ctx *ctx) struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; u_int i, j; + u_int sx = screen_size_x(s), sy = screen_size_y(s); tty_default_attributes(tty, wp, ctx->bg); - tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); + tty_region_pane(tty, ctx, 0, sy - 1); tty_margin_off(tty); - tty_cursor_pane(tty, ctx, 0, 0); if (tty_pane_full_width(tty, ctx) && + status_at_line(tty->client) <= 0 && + tty_term_has(tty->term, TTYC_ED)) { + tty_cursor_pane(tty, ctx, 0, 0); + tty_putcode(tty, TTYC_ED); + } else if (tty->term_type == TTY_VT420 && + !tty_fake_bce(tty, wp, ctx->bg)) + tty_clear_area(tty, ctx, 0, 0, sx - 1, sy - 1); + else if (tty_pane_full_width(tty, ctx) && tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp, ctx->bg)) { - for (i = 0; i < screen_size_y(s); i++) { + tty_cursor_pane(tty, ctx, 0, 0); + for (i = 0; i < sy; i++) { tty_putcode(tty, TTYC_EL); - if (i != screen_size_y(s) - 1) { + if (i != sy - 1) { tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); tty->cy++; } } } else { - for (j = 0; j < screen_size_y(s); j++) { + tty_cursor_pane(tty, ctx, 0, 0); + for (j = 0; j < sy; j++) { tty_cursor_pane(tty, ctx, 0, j); - tty_repeat_space(tty, screen_size_x(s)); + tty_repeat_space(tty, sx); } } } @@ -1173,18 +1235,6 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx) tty_cell(tty, ctx->cell, wp); } -void -tty_cmd_utf8character(struct tty *tty, const struct tty_ctx *ctx) -{ - struct window_pane *wp = ctx->wp; - - /* - * Cannot rely on not being a partial character, so just redraw the - * whole line. - */ - tty_draw_pane(tty, wp, ctx->ocy, ctx->xoff, ctx->yoff); -} - void tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx) { @@ -1262,13 +1312,15 @@ tty_reset(struct tty *tty) { struct grid_cell *gc = &tty->cell; - if (grid_cells_equal(gc, &grid_default_cell)) - return; + if (!grid_cells_equal(gc, &grid_default_cell)) { + if ((gc->attr & GRID_ATTR_CHARSET) && tty_use_acs(tty)) + tty_putcode(tty, TTYC_RMACS); + tty_putcode(tty, TTYC_SGR0); + memcpy(gc, &grid_default_cell, sizeof *gc); + } - if ((gc->attr & GRID_ATTR_CHARSET) && tty_use_acs(tty)) - tty_putcode(tty, TTYC_RMACS); - tty_putcode(tty, TTYC_SGR0); - memcpy(gc, &grid_default_cell, sizeof *gc); + memcpy(&tty->last_cell, &grid_default_cell, sizeof tty->last_cell); + tty->last_wp = -1; } /* Turn off margin. */ @@ -1490,6 +1542,18 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc, struct grid_cell *tc = &tty->cell, gc2; u_char changed; + /* Ignore cell if it is the same as the last one. */ + if (wp != NULL && + (int)wp->id == tty->last_wp && + ~(wp->window->flags & WINDOW_STYLECHANGED) && + gc->attr == tty->last_cell.attr && + gc->fg == tty->last_cell.fg && + gc->bg == tty->last_cell.bg) + return; + tty->last_wp = (wp != NULL ? (int)wp->id : -1); + memcpy(&tty->last_cell, gc, sizeof tty->last_cell); + + /* Copy cell and update default colours. */ memcpy(&gc2, gc, sizeof gc2); if (wp != NULL) tty_default_colours(&gc2, wp);