summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2020-04-10 07:44:26 +0000
committernicm <nicm@openbsd.org>2020-04-10 07:44:26 +0000
commitcdfe74ade09b697913dc61e107ba3b14abd8106e (patch)
tree43a1bc8ae99155ba554f58e9ee873404f296c91d
parentPlace the 64bit key on the stack instead of malloc(9)in' it in pppx_if_find(). (diff)
downloadwireguard-openbsd-cdfe74ade09b697913dc61e107ba3b14abd8106e.tar.xz
wireguard-openbsd-cdfe74ade09b697913dc61e107ba3b14abd8106e.zip
Now that copy mode copies the pane content rather than keeping a
reference to it, it isn't necessary that the pane in copy mode is the same as the one copying from. Add a -s flag to copy-mode to specify a different pane for the source content. This means it is possible to view two places in a pane's history at the same time in different panes, or copy from a pane's history into an editor or shell in the same pane. From Anindya Mukherjee.
-rw-r--r--usr.bin/tmux/cfg.c4
-rw-r--r--usr.bin/tmux/cmd-choose-tree.c4
-rw-r--r--usr.bin/tmux/cmd-copy-mode.c17
-rw-r--r--usr.bin/tmux/cmd-find-window.c5
-rw-r--r--usr.bin/tmux/cmd-queue.c8
-rw-r--r--usr.bin/tmux/cmd-run-shell.c4
-rw-r--r--usr.bin/tmux/tmux.110
-rw-r--r--usr.bin/tmux/tmux.h7
-rw-r--r--usr.bin/tmux/window-copy.c51
-rw-r--r--usr.bin/tmux/window.c8
10 files changed, 70 insertions, 48 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c
index 9a105b49ed8..39fc128fd94 100644
--- a/usr.bin/tmux/cfg.c
+++ b/usr.bin/tmux/cfg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cfg.c,v 1.78 2019/12/19 09:22:33 nicm Exp $ */
+/* $OpenBSD: cfg.c,v 1.79 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -284,7 +284,7 @@ cfg_show_causes(struct session *s)
wme = TAILQ_FIRST(&wp->modes);
if (wme == NULL || wme->mode != &window_view_mode)
- window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
+ window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
for (i = 0; i < cfg_ncauses; i++) {
window_copy_add(wp, "%s", cfg_causes[i]);
free(cfg_causes[i]);
diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c
index 8b31ba5c528..ab41867cce8 100644
--- a/usr.bin/tmux/cmd-choose-tree.c
+++ b/usr.bin/tmux/cmd-choose-tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-choose-tree.c,v 1.43 2019/08/16 11:49:12 nicm Exp $ */
+/* $OpenBSD: cmd-choose-tree.c,v 1.44 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
@@ -86,6 +86,6 @@ cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
} else
mode = &window_tree_mode;
- window_pane_set_mode(wp, mode, &item->target, args);
+ window_pane_set_mode(wp, NULL, mode, &item->target, args);
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-copy-mode.c b/usr.bin/tmux/cmd-copy-mode.c
index 8ff428c0cba..ce902d9d12f 100644
--- a/usr.bin/tmux/cmd-copy-mode.c
+++ b/usr.bin/tmux/cmd-copy-mode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-copy-mode.c,v 1.40 2020/03/20 17:59:39 nicm Exp $ */
+/* $OpenBSD: cmd-copy-mode.c,v 1.41 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -30,9 +30,10 @@ const struct cmd_entry cmd_copy_mode_entry = {
.name = "copy-mode",
.alias = NULL,
- .args = { "eHMt:uq", 0, 0 },
- .usage = "[-eHMuq] " CMD_TARGET_PANE_USAGE,
+ .args = { "eHMs:t:uq", 0, 0 },
+ .usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
+ .source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
@@ -59,7 +60,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
struct cmdq_shared *shared = item->shared;
struct client *c = item->client;
struct session *s;
- struct window_pane *wp = item->target.wp;
+ struct window_pane *wp = item->target.wp, *swp;
if (args_has(args, 'q')) {
window_pane_reset_mode_all(wp);
@@ -74,11 +75,15 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
}
if (self->entry == &cmd_clock_mode_entry) {
- window_pane_set_mode(wp, &window_clock_mode, NULL, NULL);
+ window_pane_set_mode(wp, NULL, &window_clock_mode, NULL, NULL);
return (CMD_RETURN_NORMAL);
}
- if (!window_pane_set_mode(wp, &window_copy_mode, NULL, args)) {
+ if (args_has(args, 's'))
+ swp = item->source.wp;
+ else
+ swp = wp;
+ if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) {
if (args_has(args, 'M'))
window_copy_start_drag(c, &shared->mouse);
}
diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c
index 68e0db91132..ae89436f2fc 100644
--- a/usr.bin/tmux/cmd-find-window.c
+++ b/usr.bin/tmux/cmd-find-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-find-window.c,v 1.46 2019/06/20 20:31:04 nicm Exp $ */
+/* $OpenBSD: cmd-find-window.c,v 1.47 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -116,7 +116,8 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
args_set(new_args, 'Z', NULL);
args_set(new_args, 'f', filter);
- window_pane_set_mode(wp, &window_tree_mode, &item->target, new_args);
+ window_pane_set_mode(wp, NULL, &window_tree_mode, &item->target,
+ new_args);
args_free(new_args);
free(filter);
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 5495890d951..cbc9aeefb16 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.80 2020/04/03 12:59:22 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.81 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -511,8 +511,10 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...)
} else {
wp = c->session->curw->window->active;
wme = TAILQ_FIRST(&wp->modes);
- if (wme == NULL || wme->mode != &window_view_mode)
- window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
+ if (wme == NULL || wme->mode != &window_view_mode) {
+ window_pane_set_mode(wp, NULL, &window_view_mode, NULL,
+ NULL);
+ }
window_copy_add(wp, "%s", msg);
}
diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c
index f9eea21b9cd..016729f23d2 100644
--- a/usr.bin/tmux/cmd-run-shell.c
+++ b/usr.bin/tmux/cmd-run-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-run-shell.c,v 1.63 2020/03/21 13:15:38 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.64 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -82,7 +82,7 @@ cmd_run_shell_print(struct job *job, const char *msg)
wme = TAILQ_FIRST(&wp->modes);
if (wme == NULL || wme->mode != &window_view_mode)
- window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
+ window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
window_copy_add(wp, "%s", msg);
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 60e2134ea79..f2e9232946d 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.734 2020/04/09 06:28:55 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.735 2020/04/10 07:44:26 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 9 2020 $
+.Dd $Mdocdate: April 10 2020 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1608,6 +1608,7 @@ command is:
.Bl -tag -width Ds
.It Xo Ic copy-mode
.Op Fl eHMqu
+.Op Fl s Ar src-pane
.Op Fl t Ar target-pane
.Xc
Enter copy mode.
@@ -1621,6 +1622,11 @@ begins a mouse drag (only valid if bound to a mouse key binding, see
hides the position indicator in the top right.
.Fl q
cancels copy mode and any other modes.
+.Fl s
+copies from
+.Ar src-pane
+instead of
+.Ar target-pane.
.Pp
.Fl e
specifies that scrolling to the bottom of the history (to the visible screen)
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 1b4a5f3b39e..8259cc4b45a 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.978 2020/04/09 14:23:34 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.979 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -848,6 +848,7 @@ struct window_mode {
/* Active window mode. */
struct window_mode_entry {
struct window_pane *wp;
+ struct window_pane *swp;
const struct window_mode *mode;
void *data;
@@ -2537,8 +2538,8 @@ void window_pane_unset_palette(struct window_pane *, u_int);
void window_pane_reset_palette(struct window_pane *);
int window_pane_get_palette(struct window_pane *, int);
int window_pane_set_mode(struct window_pane *,
- const struct window_mode *, struct cmd_find_state *,
- struct args *);
+ struct window_pane *, const struct window_mode *,
+ struct cmd_find_state *, struct args *);
void window_pane_reset_mode(struct window_pane *);
void window_pane_reset_mode_all(struct window_pane *);
int window_pane_key(struct window_pane *, struct client *,
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index cc8e9c7cfbd..caa4f9987ac 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.269 2020/04/09 14:30:28 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.270 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -130,7 +130,7 @@ static void window_copy_rectangle_toggle(struct window_mode_entry *);
static void window_copy_move_mouse(struct mouse_event *);
static void window_copy_drag_update(struct client *, struct mouse_event *);
static void window_copy_drag_release(struct client *, struct mouse_event *);
-static struct screen* window_copy_clone_screen(struct screen *src);
+static struct screen* window_copy_clone_screen(struct screen *, struct screen*);
const struct window_mode window_copy_mode = {
.name = "copy-mode",
@@ -299,21 +299,29 @@ window_copy_scroll_timer(__unused int fd, __unused short events, void *arg)
}
static struct screen *
-window_copy_clone_screen(struct screen *src)
+window_copy_clone_screen(struct screen *src, struct screen *hint)
{
struct screen *dst;
struct screen_write_ctx ctx;
+ u_int dy, sy;
dst = xcalloc(1, sizeof *dst);
- screen_init(dst, screen_size_x(src),
- screen_hsize(src) + screen_size_y(src), src->grid->hlimit);
- grid_duplicate_lines(dst->grid, 0, src->grid, 0,
- screen_hsize(src) + screen_size_y(src));
- dst->grid->sy = screen_size_y(src);
- dst->grid->hsize = screen_hsize(src);
+
+ sy = screen_hsize(src) + screen_size_y(src);
+ if (screen_size_y(hint) > sy)
+ dy = screen_size_y(hint);
+ else
+ dy = sy;
+ screen_init(dst, screen_size_x(src), dy, src->grid->hlimit);
+
+ grid_duplicate_lines(dst->grid, 0, src->grid, 0, sy);
+ if (screen_size_y(hint) < sy) {
+ dst->grid->sy = screen_size_y(hint);
+ dst->grid->hsize = sy - screen_size_y(hint);
+ }
screen_write_start(&ctx, NULL, dst);
- screen_write_cursormove(&ctx, src->cx, src->cy, 0);
+ screen_write_cursormove(&ctx, 0, dst->grid->sy - 1, 0);
screen_write_stop(&ctx);
return (dst);
@@ -361,14 +369,14 @@ static struct screen *
window_copy_init(struct window_mode_entry *wme,
__unused struct cmd_find_state *fs, struct args *args)
{
- struct window_pane *wp = wme->wp;
+ struct window_pane *wp = wme->swp;
struct window_copy_mode_data *data;
struct screen_write_ctx ctx;
u_int i;
data = window_copy_common_init(wme);
- data->backing = window_copy_clone_screen(&wp->base);
+ data->backing = window_copy_clone_screen(&wp->base, &data->screen);
data->cx = data->backing->cx;
data->cy = data->backing->cy;
@@ -2001,7 +2009,7 @@ static enum window_copy_cmd_action
window_copy_cmd_refresh_from_pane(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
- struct window_pane *wp = wme->wp;
+ struct window_pane *wp = wme->swp;
struct window_copy_mode_data *data = wme->data;
if (data->viewmode)
@@ -2009,7 +2017,7 @@ window_copy_cmd_refresh_from_pane(struct window_copy_cmd_state *cs)
screen_free(data->backing);
free(data->backing);
- data->backing = window_copy_clone_screen(&wp->base);
+ data->backing = window_copy_clone_screen(&wp->base, &data->screen);
return (WINDOW_COPY_CMD_REDRAW);
}
@@ -2964,6 +2972,7 @@ window_copy_write_line(struct window_mode_entry *wme,
struct grid_cell gc;
char hdr[512];
size_t size = 0;
+ u_int hsize = screen_hsize(data->backing);
style_apply(&gc, oo, "mode-style");
gc.flags |= GRID_FLAG_NOPALETTE;
@@ -2972,23 +2981,20 @@ window_copy_write_line(struct window_mode_entry *wme,
if (data->searchmark == NULL) {
if (data->timeout) {
size = xsnprintf(hdr, sizeof hdr,
- "(timed out) [%u/%u]", data->oy,
- screen_hsize(data->backing));
+ "(timed out) [%u/%u]", data->oy, hsize);
} else {
size = xsnprintf(hdr, sizeof hdr,
- "[%u/%u]", data->oy,
- screen_hsize(data->backing));
+ "[%u/%u]", data->oy, hsize);
}
} else {
if (data->searchthis == -1) {
size = xsnprintf(hdr, sizeof hdr,
"(%u results) [%d/%u]", data->searchcount,
- data->oy, screen_hsize(data->backing));
+ data->oy, hsize);
} else {
size = xsnprintf(hdr, sizeof hdr,
"(%u/%u results) [%d/%u]", data->searchthis,
- data->searchcount, data->oy,
- screen_hsize(data->backing));
+ data->searchcount, data->oy, hsize);
}
}
if (size > screen_size_x(s))
@@ -3000,8 +3006,7 @@ window_copy_write_line(struct window_mode_entry *wme,
if (size < screen_size_x(s)) {
screen_write_cursormove(ctx, 0, py, 0);
- screen_write_copy(ctx, data->backing, 0,
- (screen_hsize(data->backing) - data->oy) + py,
+ screen_write_copy(ctx, data->backing, 0, hsize - data->oy + py,
screen_size_x(s) - size, 1, data->searchmark, &gc);
}
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index fff57abdfeb..c866fb67ccc 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.254 2020/04/09 13:49:21 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.255 2020/04/10 07:44:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1067,8 +1067,9 @@ window_pane_get_palette(struct window_pane *wp, int c)
}
int
-window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode,
- struct cmd_find_state *fs, struct args *args)
+window_pane_set_mode(struct window_pane *wp, struct window_pane *swp,
+ const struct window_mode *mode, struct cmd_find_state *fs,
+ struct args *args)
{
struct window_mode_entry *wme;
@@ -1085,6 +1086,7 @@ window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode,
} else {
wme = xcalloc(1, sizeof *wme);
wme->wp = wp;
+ wme->swp = swp;
wme->mode = mode;
wme->prefix = 1;
TAILQ_INSERT_HEAD(&wp->modes, wme, entry);