diff options
-rw-r--r-- | cmd-refresh-client.c | 4 | ||||
-rw-r--r-- | cmd-resize-pane.c | 56 | ||||
-rw-r--r-- | cmd-send-keys.c | 2 | ||||
-rw-r--r-- | cmd-set-option.c | 60 | ||||
-rw-r--r-- | cmd-show-options.c | 17 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | environ.c | 10 | ||||
-rw-r--r-- | format.c | 14 | ||||
-rw-r--r-- | grid-view.c | 16 | ||||
-rw-r--r-- | grid.c | 4 | ||||
-rw-r--r-- | input.c | 11 | ||||
-rw-r--r-- | key-bindings.c | 17 | ||||
-rw-r--r-- | resize.c | 3 | ||||
-rw-r--r-- | screen-write.c | 33 | ||||
-rw-r--r-- | server-client.c | 2 | ||||
-rw-r--r-- | server-fn.c | 2 | ||||
-rw-r--r-- | tmux.1 | 7 | ||||
-rw-r--r-- | tmux.h | 22 | ||||
-rw-r--r-- | tty.c | 290 | ||||
-rw-r--r-- | window-copy.c | 27 | ||||
-rw-r--r-- | window.c | 1 |
21 files changed, 353 insertions, 247 deletions
diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c index 5190df89..6af3362b 100644 --- a/cmd-refresh-client.c +++ b/cmd-refresh-client.c @@ -67,8 +67,10 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "not a control client"); return (CMD_RETURN_ERROR); } - if (tty_set_size(&c->tty, w, h)) + if (tty_set_size(&c->tty, w, h)) { + c->flags |= CLIENT_SIZECHANGED; recalculate_sizes(); + } } else if (args_has(args, 'S')) { c->flags |= CLIENT_STATUSFORCE; server_status_client(c); diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 2ad11c23..bbb78de7 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -129,9 +129,8 @@ static void cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m) { struct winlink *wl; - struct window_pane *wp; - int found; - u_int y, ly; + struct window_pane *loop, *wp_x, *wp_y; + u_int y, ly, x, lx, sx, sy, ex, ey; wl = cmd_mouse_window(m, NULL); if (wl == NULL) { @@ -139,37 +138,48 @@ cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m) return; } - y = m->y; + y = m->y; x = m->x; if (m->statusat == 0 && y > 0) y--; else if (m->statusat > 0 && y >= (u_int)m->statusat) y = m->statusat - 1; - ly = m->ly; + ly = m->ly; lx = m->lx; if (m->statusat == 0 && ly > 0) ly--; else if (m->statusat > 0 && ly >= (u_int)m->statusat) ly = m->statusat - 1; - found = 0; - TAILQ_FOREACH(wp, &wl->window->panes, entry) { - if (!window_pane_visible(wp)) + wp_x = wp_y = NULL; + TAILQ_FOREACH(loop, &wl->window->panes, entry) { + if (!window_pane_visible(loop)) continue; - if (wp->xoff + wp->sx == m->lx && - wp->yoff <= 1 + ly && - wp->yoff + wp->sy >= ly) { - layout_resize_pane(wp, LAYOUT_LEFTRIGHT, m->x - m->lx, 0); - found = 1; - } - if (wp->yoff + wp->sy == ly && - wp->xoff <= 1 + m->lx && - wp->xoff + wp->sx >= m->lx) { - layout_resize_pane(wp, LAYOUT_TOPBOTTOM, y - ly, 0); - found = 1; - } + sx = loop->xoff; + if (sx != 0) + sx--; + ex = loop->xoff + loop->sx; + + sy = loop->yoff; + if (sy != 0) + sy--; + ey = loop->yoff + loop->sy; + + if ((lx == sx || lx == ex) && + (ly >= sy && ly <= ey) && + (wp_x == NULL || loop->sy > wp_x->sy)) + wp_x = loop; + if ((ly == sy || ly == ey) && + (lx >= sx && lx <= ex) && + (wp_y == NULL || loop->sx > wp_y->sx)) + wp_y = loop; } - if (found) - server_redraw_window(wl->window); - else + if (wp_x == NULL && wp_y == NULL) { c->tty.mouse_drag_update = NULL; + return; + } + if (wp_x != NULL) + layout_resize_pane(wp_x, LAYOUT_LEFTRIGHT, x - lx, 0); + if (wp_y != NULL) + layout_resize_pane(wp_y, LAYOUT_TOPBOTTOM, y - ly, 0); + server_redraw_window(wl->window); } diff --git a/cmd-send-keys.c b/cmd-send-keys.c index e54574fe..5c6db347 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -73,7 +73,7 @@ cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key) bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find); if (bd != NULL) { table->references++; - key_bindings_dispatch(bd, c, NULL, &item->target); + key_bindings_dispatch(bd, item, c, NULL, &item->target); key_bindings_unref_table(table); } } diff --git a/cmd-set-option.c b/cmd-set-option.c index b35d60d8..ad058b8e 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -42,8 +42,8 @@ const struct cmd_entry cmd_set_option_entry = { .name = "set-option", .alias = "set", - .args = { "agoqst:uw", 1, 2 }, - .usage = "[-agosquw] [-t target-window] option [value]", + .args = { "aFgoqst:uw", 1, 2 }, + .usage = "[-aFgosquw] [-t target-window] option [value]", .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL }, @@ -55,8 +55,8 @@ const struct cmd_entry cmd_set_window_option_entry = { .name = "set-window-option", .alias = "setw", - .args = { "agoqt:u", 1, 2 }, - .usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]", + .args = { "aFgoqt:u", 1, 2 }, + .usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]", .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL }, @@ -70,33 +70,38 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) struct args *args = self->args; int append = args_has(args, 'a'); struct cmd_find_state *fs = &item->target; + struct client *c, *loop; struct session *s = fs->s; struct winlink *wl = fs->wl; struct window *w; - struct client *c; enum options_table_scope scope; struct options *oo; struct options_entry *parent, *o; - char *name; - const char *value, *target; + char *name, *argument, *value = NULL, *cause; + const char *target; int window, idx, already, error, ambiguous; - char *cause; + + /* Expand argument. */ + c = cmd_find_client(item, NULL, 1); + argument = format_single(item, args->argv[0], c, s, wl, NULL); /* Parse option name and index. */ - name = options_match(args->argv[0], &idx, &ambiguous); + name = options_match(argument, &idx, &ambiguous); if (name == NULL) { if (args_has(args, 'q')) - return (CMD_RETURN_NORMAL); + goto out; if (ambiguous) - cmdq_error(item, "ambiguous option: %s", args->argv[0]); + cmdq_error(item, "ambiguous option: %s", argument); else - cmdq_error(item, "invalid option: %s", args->argv[0]); - return (CMD_RETURN_ERROR); + cmdq_error(item, "invalid option: %s", argument); + goto fail; } if (args->argc < 2) value = NULL; + else if (args_has(args, 'F')) + value = format_single(item, args->argv[1], c, s, wl, NULL); else - value = args->argv[1]; + value = xstrdup(args->argv[1]); /* * Figure out the scope: for user options it comes from the arguments, @@ -114,12 +119,12 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) scope = OPTIONS_TABLE_WINDOW; else { scope = OPTIONS_TABLE_NONE; - xasprintf(&cause, "unknown option: %s", args->argv[0]); + xasprintf(&cause, "unknown option: %s", argument); } } if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) - return (CMD_RETURN_NORMAL); + goto out; cmdq_error(item, "%s", cause); free(cause); goto fail; @@ -159,7 +164,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) /* Check that array options and indexes match up. */ if (idx != -1) { if (*name == '@' || options_array_size(parent, NULL) == -1) { - cmdq_error(item, "not an array: %s", args->argv[0]); + cmdq_error(item, "not an array: %s", argument); goto fail; } } @@ -176,8 +181,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) } if (already) { if (args_has(args, 'q')) - return (CMD_RETURN_NORMAL); - cmdq_error(item, "already set: %s", args->argv[0]); + goto out; + cmdq_error(item, "already set: %s", argument); goto fail; } } @@ -217,7 +222,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) options_array_clear(o); options_array_assign(o, value); } else if (options_array_set(o, idx, value, append) != 0) { - cmdq_error(item, "invalid index: %s", args->argv[0]); + cmdq_error(item, "invalid index: %s", argument); goto fail; } } @@ -232,8 +237,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) } } if (strcmp(name, "key-table") == 0) { - TAILQ_FOREACH(c, &clients, entry) - server_client_set_key_table(c, NULL); + TAILQ_FOREACH(loop, &clients, entry) + server_client_set_key_table(loop, NULL); } if (strcmp(name, "status") == 0 || strcmp(name, "status-interval") == 0) @@ -257,15 +262,20 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) * anyway. */ recalculate_sizes(); - TAILQ_FOREACH(c, &clients, entry) { - if (c->session != NULL) - server_redraw_client(c); + TAILQ_FOREACH(loop, &clients, entry) { + if (loop->session != NULL) + server_redraw_client(loop); } +out: + free(argument); + free(value); free(name); return (CMD_RETURN_NORMAL); fail: + free(argument); + free(value); free(name); return (CMD_RETURN_ERROR); } diff --git a/cmd-show-options.c b/cmd-show-options.c index 382dd7fb..2dc3dee3 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -127,25 +127,36 @@ cmd_show_options_one(struct cmd *self, struct cmdq_item *item, struct options *oo) { struct args *args = self->args; + struct client *c = cmd_find_client(item, NULL, 1); + struct session *s = item->target.s; + struct winlink *wl = item->target.wl; struct options_entry *o; int idx, ambiguous; - const char *name = args->argv[0]; + char *name; + name = format_single(item, args->argv[0], c, s, wl, NULL); o = options_match_get(oo, name, &idx, 1, &ambiguous); if (o == NULL) { - if (args_has(args, 'q')) + if (args_has(args, 'q')) { + free(name); return (CMD_RETURN_NORMAL); + } if (ambiguous) { cmdq_error(item, "ambiguous option: %s", name); + free(name); return (CMD_RETURN_ERROR); } if (*name != '@' && - options_match_get(oo, name, &idx, 0, &ambiguous) != NULL) + options_match_get(oo, name, &idx, 0, &ambiguous) != NULL) { + free(name); return (CMD_RETURN_NORMAL); + } cmdq_error(item, "unknown option: %s", name); + free(name); return (CMD_RETURN_ERROR); } cmd_show_options_print(self, item, o, idx); + free(name); return (CMD_RETURN_NORMAL); } diff --git a/configure.ac b/configure.ac index ea16a483..14a286b8 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # configure.ac -AC_INIT(tmux, 2.5-rc2) +AC_INIT(tmux, master) AC_PREREQ([2.60]) AC_CONFIG_AUX_DIR(etc) @@ -208,9 +208,15 @@ environ_push(struct environ *env) /* Log the environment. */ void -environ_log(struct environ *env, const char *prefix) +environ_log(struct environ *env, const char *fmt, ...) { struct environ_entry *envent; + va_list ap; + char *prefix; + + va_start(ap, fmt); + vasprintf(&prefix, fmt, ap); + va_end(ap); RB_FOREACH(envent, environ, env) { if (envent->value != NULL && *envent->name != '\0') { @@ -218,6 +224,8 @@ environ_log(struct environ *env, const char *prefix) envent->value); } } + + free(prefix); } /* Create initial environment for new child. */ @@ -217,7 +217,6 @@ format_job_update(struct job *job) struct format_job *fj = job->data; char *line; time_t t; - struct client *c; if ((line = evbuffer_readline(job->event->input)) == NULL) return; @@ -226,12 +225,12 @@ format_job_update(struct job *job) free(fj->out); fj->out = line; - log_debug("%s: %s: %s", __func__, fj->cmd, fj->out); + log_debug("%s: %p %s: %s", __func__, fj, fj->cmd, fj->out); t = time (NULL); if (fj->status && fj->last != t) { - TAILQ_FOREACH(c, &clients, entry) - server_status_client(c); + if (fj->client != NULL) + server_status_client(fj->client); fj->last = t; } } @@ -256,10 +255,11 @@ format_job_complete(struct job *job) } else buf = line; + log_debug("%s: %p %s: %s", __func__, fj, fj->cmd, buf); + if (*buf != '\0' || !fj->updated) { free(fj->out); fj->out = buf; - log_debug("%s: %s: %s", __func__, fj->cmd, fj->out); } else free(buf); @@ -1416,8 +1416,8 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_synchronized", "%d", !!options_get_number(wp->window->options, "synchronize-panes")); - format_add(ft, "pane_search_string", "%s", - window_copy_search_string(wp)); + if (wp->searchstr != NULL) + format_add(ft, "pane_search_string", "%s", wp->searchstr); format_add(ft, "pane_tty", "%s", wp->tty); format_add(ft, "pane_pid", "%ld", (long) wp->pid); diff --git a/grid-view.c b/grid-view.c index fe096252..033ec033 100644 --- a/grid-view.c +++ b/grid-view.c @@ -96,32 +96,34 @@ grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, /* Scroll region up. */ void -grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower) +grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower, + u_int bg) { if (gd->flags & GRID_HISTORY) { - grid_collect_history(gd, 8); + grid_collect_history(gd, bg); if (rupper == 0 && rlower == gd->sy - 1) - grid_scroll_history(gd, 8); + grid_scroll_history(gd, bg); else { rupper = grid_view_y(gd, rupper); rlower = grid_view_y(gd, rlower); - grid_scroll_history_region(gd, rupper, rlower); + grid_scroll_history_region(gd, rupper, rlower, bg); } } else { rupper = grid_view_y(gd, rupper); rlower = grid_view_y(gd, rlower); - grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, 8); + grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, bg); } } /* Scroll region down. */ void -grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower) +grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower, + u_int bg) { rupper = grid_view_y(gd, rupper); rlower = grid_view_y(gd, rlower); - grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, 8); + grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, bg); } /* Insert lines. */ @@ -284,7 +284,7 @@ grid_clear_history(struct grid *gd) /* Scroll a region up, moving the top line into the history. */ void -grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower) +grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower, u_int bg) { struct grid_line *gl_history, *gl_upper, *gl_lower; u_int yy; @@ -309,7 +309,7 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower) /* Then move the region up and clear the bottom line. */ memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper); - memset(gl_lower, 0, sizeof *gl_lower); + grid_empty_line(gd, lower, bg); /* Move the history offset down over the line. */ gd->hscrolled++; @@ -1123,7 +1123,7 @@ input_c0_dispatch(struct input_ctx *ictx) case '\012': /* LF */ case '\013': /* VT */ case '\014': /* FF */ - screen_write_linefeed(sctx, 0); + screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); break; case '\015': /* CR */ screen_write_carriagereturn(sctx); @@ -1168,18 +1168,18 @@ input_esc_dispatch(struct input_ctx *ictx) screen_write_reset(sctx); break; case INPUT_ESC_IND: - screen_write_linefeed(sctx, 0); + screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); break; case INPUT_ESC_NEL: screen_write_carriagereturn(sctx); - screen_write_linefeed(sctx, 0); + screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); break; case INPUT_ESC_HTS: if (s->cx < screen_size_x(s)) bit_set(s->tabs, s->cx); break; case INPUT_ESC_RI: - screen_write_reverseindex(sctx); + screen_write_reverseindex(sctx, ictx->cell.cell.bg); break; case INPUT_ESC_DECKPAM: screen_write_mode_set(sctx, MODE_KKEYPAD); @@ -1417,7 +1417,8 @@ input_csi_dispatch(struct input_ctx *ictx) input_csi_dispatch_sm_private(ictx); break; case INPUT_CSI_SU: - screen_write_scrollup(sctx, input_get(ictx, 0, 1, 1)); + screen_write_scrollup(sctx, input_get(ictx, 0, 1, 1), + ictx->cell.cell.bg); break; case INPUT_CSI_TBC: switch (input_get(ictx, 0, 0, 0)) { diff --git a/key-bindings.c b/key-bindings.c index 9e327655..8f56cbee 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -400,11 +400,11 @@ key_bindings_read_only(struct cmdq_item *item, __unused void *data) } void -key_bindings_dispatch(struct key_binding *bd, struct client *c, - struct mouse_event *m, struct cmd_find_state *fs) +key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item, + struct client *c, struct mouse_event *m, struct cmd_find_state *fs) { struct cmd *cmd; - struct cmdq_item *item; + struct cmdq_item *new_item; int readonly; readonly = 1; @@ -413,11 +413,14 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c, readonly = 0; } if (!readonly && (c->flags & CLIENT_READONLY)) - cmdq_append(c, cmdq_get_callback(key_bindings_read_only, NULL)); + new_item = cmdq_get_callback(key_bindings_read_only, NULL); else { - item = cmdq_get_command(bd->cmdlist, fs, m, 0); + new_item = cmdq_get_command(bd->cmdlist, fs, m, 0); if (bd->flags & KEY_BINDING_REPEAT) - item->shared->flags |= CMDQ_SHARED_REPEAT; - cmdq_append(c, item); + new_item->shared->flags |= CMDQ_SHARED_REPEAT; } + if (item != NULL) + cmdq_insert_after(item, new_item); + else + cmdq_append(c, new_item); } @@ -60,6 +60,9 @@ recalculate_sizes(void) TAILQ_FOREACH(c, &clients, entry) { if (c->flags & CLIENT_SUSPENDED) continue; + if ((c->flags & (CLIENT_CONTROL|CLIENT_SIZECHANGED)) == + CLIENT_CONTROL) + continue; if (c->session == s) { if (c->tty.sx < ssx) ssx = c->tty.sx; diff --git a/screen-write.c b/screen-write.c index 0a63e1b6..1af623b1 100644 --- a/screen-write.c +++ b/screen-write.c @@ -75,6 +75,9 @@ screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp, TAILQ_INIT(&ctx->list[y].items); ctx->item = xcalloc(1, sizeof *ctx->item); + ctx->scrolled = 0; + ctx->bg = 8; + if (wp != NULL) snprintf(tmp, sizeof tmp, "pane %%%u", wp->id); log_debug("%s: size %ux%u, %s", __func__, screen_size_x(ctx->s), @@ -812,15 +815,16 @@ screen_write_cursormove(struct screen_write_ctx *ctx, u_int px, u_int py) /* Reverse index (up with scroll). */ void -screen_write_reverseindex(struct screen_write_ctx *ctx) +screen_write_reverseindex(struct screen_write_ctx *ctx, u_int bg) { struct screen *s = ctx->s; struct tty_ctx ttyctx; screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; if (s->cy == s->rupper) - grid_view_scroll_region_down(s->grid, s->rupper, s->rlower); + grid_view_scroll_region_down(s->grid, s->rupper, s->rlower, bg); else if (s->cy > 0) s->cy--; @@ -854,7 +858,7 @@ screen_write_scrollregion(struct screen_write_ctx *ctx, u_int rupper, /* Line feed. */ void -screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) +screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped, u_int bg) { struct screen *s = ctx->s; struct grid *gd = s->grid; @@ -869,8 +873,13 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) log_debug("%s: at %u,%u (region %u-%u)", __func__, s->cx, s->cy, s->rupper, s->rlower); + if (bg != ctx->bg) { + screen_write_collect_flush(ctx, 1); + ctx->bg = bg; + } + if (s->cy == s->rlower) { - grid_view_scroll_region_up(gd, s->rupper, s->rlower); + grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg); screen_write_collect_scroll(ctx); ctx->scrolled++; } else if (s->cy < screen_size_y(s) - 1) @@ -879,7 +888,7 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) /* Scroll up. */ void -screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines) +screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines, u_int bg) { struct screen *s = ctx->s; struct grid *gd = s->grid; @@ -890,8 +899,13 @@ screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines) else if (lines > s->rlower - s->rupper + 1) lines = s->rlower - s->rupper + 1; + if (bg != ctx->bg) { + screen_write_collect_flush(ctx, 1); + ctx->bg = bg; + } + for (i = 0; i < lines; i++) { - grid_view_scroll_region_up(gd, s->rupper, s->rlower); + grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg); screen_write_collect_scroll(ctx); } ctx->scrolled += lines; @@ -1046,9 +1060,12 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only) screen_write_initctx(ctx, &ttyctx); ttyctx.num = ctx->scrolled; + ttyctx.bg = ctx->bg; tty_write(tty_cmd_scrollup, &ttyctx); } ctx->scrolled = 0; + ctx->bg = 8; + if (scroll_only) return; @@ -1143,7 +1160,7 @@ screen_write_collect_add(struct screen_write_ctx *ctx, if (s->cx > sx - 1) { log_debug("%s: wrapped at %u,%u", __func__, s->cx, s->cy); ci->wrapped = 1; - screen_write_linefeed(ctx, 1); + screen_write_linefeed(ctx, 1, 8); s->cx = 0; } @@ -1204,7 +1221,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) /* Check this will fit on the current line and wrap if not. */ if ((s->mode & MODE_WRAP) && s->cx > sx - width) { - screen_write_linefeed(ctx, 1); + screen_write_linefeed(ctx, 1, 8); s->cx = 0; } diff --git a/server-client.c b/server-client.c index e8a9f757..e5c21dfb 100644 --- a/server-client.c +++ b/server-client.c @@ -945,7 +945,7 @@ retry: server_status_client(c); /* Execute the key binding. */ - key_bindings_dispatch(bd, c, m, &fs); + key_bindings_dispatch(bd, NULL, c, m, &fs); key_bindings_unref_table(table); return; } diff --git a/server-fn.c b/server-fn.c index 0be7f70d..5b1af13e 100644 --- a/server-fn.c +++ b/server-fn.c @@ -300,7 +300,7 @@ server_destroy_pane(struct window_pane *wp, int notify) screen_write_start(&ctx, wp, &wp->base); screen_write_scrollregion(&ctx, 0, screen_size_y(ctx.s) - 1); screen_write_cursormove(&ctx, 0, screen_size_y(ctx.s) - 1); - screen_write_linefeed(&ctx, 1); + screen_write_linefeed(&ctx, 1, 8); memcpy(&gc, &grid_default_cell, sizeof gc); gc.attr |= GRID_ATTR_BRIGHT; screen_write_puts(&ctx, &gc, "Pane is dead"); @@ -2335,7 +2335,7 @@ abc123 Commands which set options are as follows: .Bl -tag -width Ds .It Xo Ic set-option -.Op Fl agoqsuw +.Op Fl aFgoqsuw .Op Fl t Ar target-session | Ar target-window .Ar option Ar value .Xc @@ -2351,6 +2351,8 @@ otherwise a session option. If .Fl g is given, the global session or window option is set. +.Fl F +expands formats in the option value. The .Fl u flag unsets an option, so a session inherits the option from the global @@ -2901,7 +2903,7 @@ The default is .Ql \ -_@ . .El .It Xo Ic set-window-option -.Op Fl agoqu +.Op Fl aFgoqu .Op Fl t Ar target-window .Ar option Ar value .Xc @@ -2909,6 +2911,7 @@ The default is Set a window option. The .Fl a , +.Fl F , .Fl g , .Fl o , .Fl q @@ -676,6 +676,7 @@ struct screen_write_ctx { struct screen_write_collect_item *item; struct screen_write_collect_line *list; u_int scrolled; + u_int bg; u_int cells; u_int written; @@ -796,6 +797,7 @@ struct window_pane { struct event modetimer; time_t modelast; u_int modeprefix; + char *searchstr; TAILQ_ENTRY(window_pane) entry; RB_ENTRY(window_pane) tree_entry; @@ -1349,6 +1351,7 @@ struct client { #define CLIENT_STATUSFORCE 0x80000 #define CLIENT_DOUBLECLICK 0x100000 #define CLIENT_TRIPLECLICK 0x200000 +#define CLIENT_SIZECHANGED 0x400000 int flags; struct key_table *keytable; @@ -1624,7 +1627,7 @@ void environ_put(struct environ *, const char *); void environ_unset(struct environ *, const char *); void environ_update(struct options *, struct environ *, struct environ *); void environ_push(struct environ *); -void environ_log(struct environ *, const char *); +void printflike(2, 3) environ_log(struct environ *, const char *, ...); struct environ *environ_for_session(struct session *, int); /* tty.c */ @@ -1805,8 +1808,8 @@ void key_bindings_add(const char *, key_code, int, struct cmd_list *); void key_bindings_remove(const char *, key_code); void key_bindings_remove_table(const char *); void key_bindings_init(void); -void key_bindings_dispatch(struct key_binding *, struct client *, - struct mouse_event *, struct cmd_find_state *); +void key_bindings_dispatch(struct key_binding *, struct cmdq_item *, + struct client *, struct mouse_event *, struct cmd_find_state *); /* key-string.c */ key_code key_string_lookup_string(const char *); @@ -1933,7 +1936,7 @@ void grid_destroy(struct grid *); int grid_compare(struct grid *, struct grid *); void grid_collect_history(struct grid *, u_int); void grid_scroll_history(struct grid *, u_int); -void grid_scroll_history_region(struct grid *, u_int, u_int); +void grid_scroll_history_region(struct grid *, u_int, u_int, u_int); void grid_clear_history(struct grid *); const struct grid_line *grid_peek_line(struct grid *, u_int); void grid_get_cell(struct grid *, u_int, u_int, struct grid_cell *); @@ -1958,8 +1961,8 @@ void grid_view_set_cells(struct grid *, u_int, u_int, const struct grid_cell *, const char *, size_t); void grid_view_clear_history(struct grid *, u_int); void grid_view_clear(struct grid *, u_int, u_int, u_int, u_int, u_int); -void grid_view_scroll_region_up(struct grid *, u_int, u_int); -void grid_view_scroll_region_down(struct grid *, u_int, u_int); +void grid_view_scroll_region_up(struct grid *, u_int, u_int, u_int); +void grid_view_scroll_region_down(struct grid *, u_int, u_int, u_int); void grid_view_insert_lines(struct grid *, u_int, u_int, u_int); void grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int, u_int); @@ -2006,10 +2009,10 @@ void screen_write_clearline(struct screen_write_ctx *, u_int); void screen_write_clearendofline(struct screen_write_ctx *, u_int); void screen_write_clearstartofline(struct screen_write_ctx *, u_int); void screen_write_cursormove(struct screen_write_ctx *, u_int, u_int); -void screen_write_reverseindex(struct screen_write_ctx *); +void screen_write_reverseindex(struct screen_write_ctx *, u_int); void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int); -void screen_write_linefeed(struct screen_write_ctx *, int); -void screen_write_scrollup(struct screen_write_ctx *, u_int); +void screen_write_linefeed(struct screen_write_ctx *, int, u_int); +void screen_write_scrollup(struct screen_write_ctx *, u_int, u_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 *, u_int); @@ -2180,7 +2183,6 @@ void window_copy_vadd(struct window_pane *, const char *, va_list); void window_copy_pageup(struct window_pane *, int); void window_copy_start_drag(struct client *, struct mouse_event *); int window_copy_scroll_position(struct window_pane *); -const char *window_copy_search_string(struct window_pane *); /* window-choose.c */ extern const struct window_mode window_choose_mode; @@ -754,6 +754,115 @@ tty_redraw_region(struct tty *tty, const struct tty_ctx *ctx) } } +static void +tty_clear_line(struct tty *tty, const struct window_pane *wp, u_int py, + u_int px, u_int nx, u_int bg) +{ + log_debug("%s: %u at %u,%u", __func__, nx, px, py); + + /* Nothing to clear. */ + if (nx == 0) + return; + + /* If genuine BCE is available, can try escape sequences. */ + if (!tty_fake_bce(tty, wp, bg)) { + /* Off the end of the line, use EL if available. */ + if (px + nx >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { + tty_cursor(tty, px, py); + tty_putcode(tty, TTYC_EL); + return; + } + + /* At the start of the line. Use EL1. */ + if (px == 0 && tty_term_has(tty->term, TTYC_EL1)) { + tty_cursor(tty, px + nx - 1, py); + tty_putcode(tty, TTYC_EL1); + return; + } + + /* Section of line. Use ECH if possible. */ + if (tty_term_has(tty->term, TTYC_ECH)) { + tty_cursor(tty, px, py); + tty_putcode1(tty, TTYC_ECH, nx); + return; + } + } + + /* Couldn't use an escape sequence, use spaces. */ + tty_cursor(tty, px, py); + tty_repeat_space(tty, nx); +} + +static void +tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, + u_int ny, u_int px, u_int nx, u_int bg) +{ + u_int yy; + char tmp[64]; + + log_debug("%s: %u,%u at %u,%u", __func__, nx, ny, px, py); + + /* Nothing to clear. */ + if (nx == 0 || ny == 0) + return; + + /* If genuine BCE is available, can try escape sequences. */ + if (!tty_fake_bce(tty, wp, bg)) { + /* Use ED if clearing off the bottom of the terminal. */ + if (px == 0 && + px + nx >= tty->sx && + py + ny >= tty->sy && + tty_term_has(tty->term, TTYC_ED)) { + tty_cursor(tty, 0, py); + tty_putcode(tty, TTYC_ED); + return; + } + + /* + * On VT420 compatible terminals we can use DECFRA if the + * background colour isn't default (because it doesn't work + * after SGR 0). + */ + if (tty->term_type == TTY_VT420 && bg != 8) { + xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x", + py + 1, px + 1, py + ny, px + nx); + tty_puts(tty, tmp); + return; + } + + /* Full lines can be scrolled away to clear them. */ + if (px == 0 && + px + nx >= tty->sx && + ny > 2 && + tty_term_has(tty->term, TTYC_CSR) && + tty_term_has(tty->term, TTYC_INDN)) { + tty_region(tty, py, py + ny - 1); + tty_margin_off(tty); + tty_putcode1(tty, TTYC_INDN, ny); + return; + } + + /* + * If margins are supported, can just scroll the area off to + * clear it. + */ + if (nx > 2 && + ny > 2 && + tty_term_has(tty->term, TTYC_CSR) && + tty_use_margin(tty) && + tty_term_has(tty->term, TTYC_INDN)) { + tty_region(tty, py, py + ny - 1); + tty_margin(tty, px, px + nx - 1); + tty_putcode1(tty, TTYC_INDN, ny); + return; + } + } + + /* Couldn't use an escape sequence, loop over the lines. */ + for (yy = py; yy < py + ny; yy++) + tty_clear_line(tty, wp, yy, px, nx, bg); +} + void tty_draw_pane(struct tty *tty, const struct window_pane *wp, u_int py, u_int ox, u_int oy) @@ -766,7 +875,7 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp, struct screen *s, u_int py, u_int ox, u_int oy) { struct grid_cell gc, last; - u_int i, j, sx, width; + u_int i, j, sx, nx, width; int flags, cleared = 0; char buf[512]; size_t len; @@ -861,16 +970,10 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp, tty_putn(tty, buf, len, width); } - if (!cleared && sx < tty->sx) { + nx = screen_size_x(s) - sx; + if (!cleared && sx < tty->sx && nx != 0) { tty_default_attributes(tty, wp, 8); - tty_cursor(tty, ox + sx, oy + py); - if (sx != screen_size_x(s) && - ox + screen_size_x(s) >= tty->sx && - tty_term_has(tty->term, TTYC_EL) && - !tty_fake_bce(tty, wp, 8)) - tty_putcode(tty, TTYC_EL); - else - tty_repeat_space(tty, screen_size_x(s) - sx); + tty_clear_line(tty, wp, oy + py, ox + sx, nx, 8); } tty->flags = (tty->flags & ~TTY_NOCURSOR) | flags; @@ -1018,73 +1121,55 @@ void 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); + u_int nx, py = ctx->yoff + ctx->ocy; tty_default_attributes(tty, wp, ctx->bg); - tty_cursor_pane(tty, ctx, 0, ctx->ocy); - - if (tty_pane_full_width(tty, ctx) && - !tty_fake_bce(tty, wp, ctx->bg) && - tty_term_has(tty->term, TTYC_EL)) - tty_putcode(tty, TTYC_EL); - else - tty_repeat_space(tty, sx); + nx = screen_size_x(wp->screen); + tty_clear_line(tty, wp, py, ctx->xoff, nx, ctx->bg); } void 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); + u_int nx, py = ctx->yoff + ctx->ocy; tty_default_attributes(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_fake_bce(tty, wp, ctx->bg)) - tty_putcode(tty, TTYC_EL); - else - tty_repeat_space(tty, sx - ctx->ocx); + nx = screen_size_x(wp->screen) - ctx->ocx; + tty_clear_line(tty, wp, py, ctx->xoff + ctx->ocx, nx, ctx->bg); } void tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; + u_int nx, py = ctx->yoff + ctx->ocy; tty_default_attributes(tty, wp, ctx->bg); - if (ctx->xoff == 0 && - tty_term_has(tty->term, TTYC_EL1) && - !tty_fake_bce(tty, ctx->wp, ctx->bg)) { - tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); - tty_putcode(tty, TTYC_EL1); - } else { - tty_cursor_pane(tty, ctx, 0, ctx->ocy); - tty_repeat_space(tty, ctx->ocx + 1); - } + nx = screen_size_x(wp->screen) - ctx->ocx; + tty_clear_line(tty, wp, py, ctx->xoff, ctx->ocx + 1, ctx->bg); } void tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx) { + struct window_pane *wp = ctx->wp; + if (ctx->ocy != ctx->orupper) return; if (!tty_pane_full_width(tty, ctx) || - tty_fake_bce(tty, ctx->wp, 8) || + tty_fake_bce(tty, wp, 8) || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_RI)) { tty_redraw_region(tty, ctx); return; } - tty_attributes(tty, &grid_default_cell, ctx->wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_off(tty); @@ -1108,7 +1193,7 @@ tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx) return; } - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); @@ -1139,7 +1224,7 @@ tty_cmd_scrollup(struct tty *tty, const struct tty_ctx *ctx) return; } - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); @@ -1165,116 +1250,69 @@ void 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); + u_int px, py, nx, ny; tty_default_attributes(tty, wp, ctx->bg); - tty_region_pane(tty, ctx, 0, sy - 1); + tty_region_pane(tty, ctx, 0, screen_size_y(wp->screen) - 1); tty_margin_off(tty); - if (tty_pane_full_width(tty, ctx) && - ctx->yoff + wp->sy >= tty->sy - 1 && - 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_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 != sy - 1) { - tty_cursor_pane(tty, ctx, 0, ctx->ocy + 1); - for (i = ctx->ocy + 1; i < sy; i++) { - tty_putcode(tty, TTYC_EL); - if (i == sy - 1) - continue; - tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); - tty->cy++; - } - } - } else { - 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, sx); - } - } + px = ctx->xoff; + nx = screen_size_x(wp->screen); + py = ctx->yoff + ctx->ocy + 1; + ny = screen_size_y(wp->screen) - ctx->ocy - 1; + + tty_clear_area(tty, wp, py, ny, px, nx, ctx->bg); + + px = ctx->xoff + ctx->ocx; + nx = screen_size_x(wp->screen) - ctx->ocx; + py = ctx->yoff + ctx->ocy; + + tty_clear_line(tty, wp, py, px, nx, ctx->bg); } void 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); + u_int px, py, nx, ny; tty_default_attributes(tty, wp, ctx->bg); - tty_region_pane(tty, ctx, 0, sy - 1); + tty_region_pane(tty, ctx, 0, screen_size_y(wp->screen) - 1); tty_margin_off(tty); - 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, sx); - } - } - tty_cursor_pane(tty, ctx, 0, ctx->ocy); - tty_repeat_space(tty, ctx->ocx + 1); + px = ctx->xoff; + nx = screen_size_x(wp->screen); + py = ctx->yoff; + ny = ctx->ocy - 1; + + tty_clear_area(tty, wp, py, ny, px, nx, ctx->bg); + + px = ctx->xoff; + nx = ctx->ocx + 1; + py = ctx->yoff + ctx->ocy; + + tty_clear_line(tty, wp, py, px, nx, ctx->bg); } void 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); + u_int px, py, nx, ny; tty_default_attributes(tty, wp, ctx->bg); - tty_region_pane(tty, ctx, 0, sy - 1); + tty_region_pane(tty, ctx, 0, screen_size_y(wp->screen) - 1); tty_margin_off(tty); - if (tty_pane_full_width(tty, ctx) && - ctx->yoff + wp->sy >= tty->sy - 1 && - 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_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 < sy; i++) { - tty_putcode(tty, TTYC_EL); - if (i != sy - 1) { - tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); - tty->cy++; - } - } - } else { - tty_cursor_pane(tty, ctx, 0, 0); - for (j = 0; j < sy; j++) { - tty_cursor_pane(tty, ctx, 0, j); - tty_repeat_space(tty, sx); - } - } + px = ctx->xoff; + nx = screen_size_x(wp->screen); + py = ctx->yoff; + ny = screen_size_y(wp->screen); + + tty_clear_area(tty, wp, py, ny, px, nx, ctx->bg); } void diff --git a/window-copy.c b/window-copy.c index 8424bfa6..6d1a9f69 100644 --- a/window-copy.c +++ b/window-copy.c @@ -208,8 +208,13 @@ window_copy_init(struct window_pane *wp) data->rectflag = 0; data->scroll_exit = 0; - data->searchtype = WINDOW_COPY_OFF; - data->searchstr = NULL; + if (wp->searchstr != NULL) { + data->searchtype = WINDOW_COPY_SEARCHUP; + data->searchstr = xstrdup(wp->searchstr); + } else { + data->searchtype = WINDOW_COPY_OFF; + data->searchstr = NULL; + } data->searchmark = NULL; data->searchx = data->searchy = data->searcho = -1; @@ -316,7 +321,7 @@ window_copy_vadd(struct window_pane *wp, const char *fmt, va_list ap) * (so it's on a new line). */ screen_write_carriagereturn(&back_ctx); - screen_write_linefeed(&back_ctx, 0); + screen_write_linefeed(&back_ctx, 0, 8); } else data->backing_written = 1; old_cy = backing->cy; @@ -1134,6 +1139,9 @@ window_copy_search(struct window_pane *wp, int direction, int moveflag) u_int fx, fy, endline; int wrapflag, cis, found; + free(wp->searchstr); + wp->searchstr = xstrdup(data->searchstr); + fx = data->cx; fy = screen_hsize(data->backing) - data->oy + data->cy; @@ -2482,16 +2490,3 @@ window_copy_drag_update(__unused struct client *c, struct mouse_event *m) if (window_copy_update_selection(wp, 1)) window_copy_redraw_selection(wp, old_cy); } - -const char * -window_copy_search_string(struct window_pane *wp) -{ - struct window_copy_mode_data *data; - - if (wp->mode != &window_copy_mode) - return (""); - data = wp->modedata; - if (data->searchtype == WINDOW_COPY_OFF || data->searchstr == NULL) - return (""); - return (data->searchstr); -} @@ -828,6 +828,7 @@ static void window_pane_destroy(struct window_pane *wp) { window_pane_reset_mode(wp); + free(wp->searchstr); if (wp->fd != -1) { #ifdef HAVE_UTEMPTER |