summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2021-01-22 10:24:53 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2021-01-22 10:24:53 +0000
commit32460b2f63116f769c6b7cdf5ee19921184e8f50 (patch)
treeaaa1f008a927a03603b2169f0f82cfd64fcef000 /usr.bin
parent5a8fdd2e9ce3681ed50d9979d6636b19a20b138a (diff)
Add rectangle-on and rectangle-off copy mode commands, GitHub isse 2546
from author at will dot party.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/tmux.16
-rw-r--r--usr.bin/tmux/window-copy.c38
2 files changed, 37 insertions, 7 deletions
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 9ca90db3451..d47460d5086 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.812 2021/01/20 07:16:54 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.813 2021/01/22 10:24:52 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: January 20 2021 $
+.Dd $Mdocdate: January 22 2021 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1657,6 +1657,8 @@ The following commands are supported in copy mode:
.It Li "previous-paragraph" Ta "{" Ta "M-{"
.It Li "previous-space" Ta "B" Ta ""
.It Li "previous-word" Ta "b" Ta "M-b"
+.It Li "rectangle-on" Ta "" Ta ""
+.It Li "rectangle-off" Ta "" Ta ""
.It Li "rectangle-toggle" Ta "v" Ta "R"
.It Li "refresh-from-pane" Ta "r" Ta "r"
.It Li "scroll-down" Ta "C-e" Ta "C-Down"
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 5ae90e0ad48..bf7138a8099 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.312 2021/01/22 10:21:24 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.313 2021/01/22 10:24:52 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -128,7 +128,7 @@ static void window_copy_cursor_previous_word(struct window_mode_entry *,
const char *, int);
static void window_copy_scroll_up(struct window_mode_entry *, u_int);
static void window_copy_scroll_down(struct window_mode_entry *, u_int);
-static void window_copy_rectangle_toggle(struct window_mode_entry *);
+static void window_copy_rectangle_set(struct window_mode_entry *, int);
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 *);
@@ -1626,13 +1626,37 @@ window_copy_cmd_previous_word(struct window_copy_cmd_state *cs)
}
static enum window_copy_cmd_action
+window_copy_cmd_rectangle_on(struct window_copy_cmd_state *cs)
+{
+ struct window_mode_entry *wme = cs->wme;
+ struct window_copy_mode_data *data = wme->data;
+
+ data->lineflag = LINE_SEL_NONE;
+ window_copy_rectangle_set(wme, 1);
+
+ return (WINDOW_COPY_CMD_NOTHING);
+}
+
+static enum window_copy_cmd_action
+window_copy_cmd_rectangle_off(struct window_copy_cmd_state *cs)
+{
+ struct window_mode_entry *wme = cs->wme;
+ struct window_copy_mode_data *data = wme->data;
+
+ data->lineflag = LINE_SEL_NONE;
+ window_copy_rectangle_set(wme, 0);
+
+ return (WINDOW_COPY_CMD_NOTHING);
+}
+
+static enum window_copy_cmd_action
window_copy_cmd_rectangle_toggle(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
data->lineflag = LINE_SEL_NONE;
- window_copy_rectangle_toggle(wme);
+ window_copy_rectangle_set(wme, !data->rectflag);
return (WINDOW_COPY_CMD_NOTHING);
}
@@ -2251,6 +2275,10 @@ static const struct {
window_copy_cmd_previous_space },
{ "previous-word", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
window_copy_cmd_previous_word },
+ { "rectangle-on", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
+ window_copy_cmd_rectangle_on },
+ { "rectangle-off", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
+ window_copy_cmd_rectangle_off },
{ "rectangle-toggle", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
window_copy_cmd_rectangle_toggle },
{ "refresh-from-pane", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
@@ -4726,12 +4754,12 @@ window_copy_scroll_down(struct window_mode_entry *wme, u_int ny)
}
static void
-window_copy_rectangle_toggle(struct window_mode_entry *wme)
+window_copy_rectangle_set(struct window_mode_entry *wme, int rectflag)
{
struct window_copy_mode_data *data = wme->data;
u_int px, py;
- data->rectflag = !data->rectflag;
+ data->rectflag = rectflag;
py = screen_hsize(data->backing) + data->cy - data->oy;
px = window_copy_find_length(wme, py);