summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-03-31 17:13:21 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-03-31 17:13:21 +0000
commita50cb7ffe73f1e00829305a3b87bced6370b8e48 (patch)
tree667d12bb563fc7b6311f68ecd18464673278426e /usr.bin
parent80fc65bc79a7f68cd2e17e4f1197dff3a3bf6718 (diff)
Add a -T flag to resize-pane to trim lines below the cursor, moving
lines out of the history. GitHub issue 2134.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-resize-pane.c19
-rw-r--r--usr.bin/tmux/grid.c15
-rw-r--r--usr.bin/tmux/tmux.17
3 files changed, 35 insertions, 6 deletions
diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c
index fcafe0a536c..9d76339b347 100644
--- a/usr.bin/tmux/cmd-resize-pane.c
+++ b/usr.bin/tmux/cmd-resize-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-resize-pane.c,v 1.40 2020/03/21 13:16:15 nicm Exp $ */
+/* $OpenBSD: cmd-resize-pane.c,v 1.41 2020/03/31 17:13:20 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -36,8 +36,8 @@ const struct cmd_entry cmd_resize_pane_entry = {
.name = "resize-pane",
.alias = "resizep",
- .args = { "DLMRt:Ux:y:Z", 0, 1 },
- .usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
+ .args = { "DLMRTt:Ux:y:Z", 0, 1 },
+ .usage = "[-DLMRTUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
"[adjustment]",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -60,6 +60,19 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
char *cause;
u_int adjust;
int x, y;
+ struct grid *gd = wp->base.grid;
+
+ if (args_has(args, 'T')) {
+ if (!TAILQ_EMPTY(&wp->modes))
+ return (CMD_RETURN_NORMAL);
+ adjust = screen_size_y(&wp->base) - 1 - wp->base.cy;
+ if (adjust > gd->hsize)
+ adjust = gd->hsize;
+ grid_remove_history(gd, adjust);
+ wp->base.cy += adjust;
+ wp->flags |= PANE_REDRAW;
+ return (CMD_RETURN_NORMAL);
+ }
if (args_has(args, 'M')) {
if (cmd_mouse_window(&shared->mouse, &s) == NULL)
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c
index 63af07bf461..f4f6b87e531 100644
--- a/usr.bin/tmux/grid.c
+++ b/usr.bin/tmux/grid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grid.c,v 1.103 2020/03/21 13:51:30 nicm Exp $ */
+/* $OpenBSD: grid.c,v 1.104 2020/03/31 17:13:20 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -351,6 +351,19 @@ grid_collect_history(struct grid *gd)
gd->hscrolled = gd->hsize;
}
+/* Remove lines from the bottom of the history. */
+void
+grid_remove_history(struct grid *gd, u_int ny)
+{
+ u_int yy;
+
+ if (ny > gd->hsize)
+ return;
+ for (yy = 0; yy < ny; yy++)
+ grid_free_line(gd, gd->hsize + gd->sy - 1 - yy);
+ gd->hsize -= ny;
+}
+
/*
* Scroll the entire visible screen, moving one line into the history. Just
* allocate a new line at the bottom and move the history size indicator.
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index a7d9868bb37..f16c043c7b0 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.726 2020/03/31 16:53:23 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.727 2020/03/31 17:13:20 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -2261,7 +2261,7 @@ Rename the current window, or the window at
if specified, to
.Ar new-name .
.It Xo Ic resize-pane
-.Op Fl DLMRUZ
+.Op Fl DLMRTUZ
.Op Fl t Ar target-pane
.Op Fl x Ar width
.Op Fl y Ar height
@@ -2300,6 +2300,9 @@ and unzoomed (its normal position in the layout).
.Fl M
begins mouse resizing (only valid if bound to a mouse key binding, see
.Sx MOUSE SUPPORT ) .
+.Pp T
+trims all lines below the current cursor position and moves lines out of the
+history to replace them.
.It Xo Ic resize-window
.Op Fl aADLRU
.Op Fl t Ar target-window