summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2012-11-27 20:22:12 +0000
committernicm <nicm@openbsd.org>2012-11-27 20:22:12 +0000
commit7a3aab4efb9ba3115a1bf31c2bca19c7329ca554 (patch)
tree3b79c895182e05f65924bea4af8e49ff4fcc42ea
parentSupport the 47 and 1047 SM and RM sequences (alternate screen without (diff)
downloadwireguard-openbsd-7a3aab4efb9ba3115a1bf31c2bca19c7329ca554.tar.xz
wireguard-openbsd-7a3aab4efb9ba3115a1bf31c2bca19c7329ca554.zip
Support middle-click paste, based on a diff from Ailin Nemui.
-rw-r--r--usr.bin/tmux/cmd-paste-buffer.c36
-rw-r--r--usr.bin/tmux/input-keys.c17
-rw-r--r--usr.bin/tmux/paste.c28
-rw-r--r--usr.bin/tmux/tmux.h11
4 files changed, 50 insertions, 42 deletions
diff --git a/usr.bin/tmux/cmd-paste-buffer.c b/usr.bin/tmux/cmd-paste-buffer.c
index 2d100d19929..4885f3e4e5b 100644
--- a/usr.bin/tmux/cmd-paste-buffer.c
+++ b/usr.bin/tmux/cmd-paste-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-paste-buffer.c,v 1.19 2012/07/11 07:10:15 nicm Exp $ */
+/* $OpenBSD: cmd-paste-buffer.c,v 1.20 2012/11/27 20:22:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,7 +31,7 @@
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
void cmd_paste_buffer_filter(struct window_pane *,
- const char *, size_t, const char *, int bracket);
+ const char *, size_t, const char *, int);
const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "pasteb",
@@ -87,9 +87,8 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
else
sepstr = "\r";
}
- pflag = args_has(args, 'p') &&
- (wp->screen->mode & MODE_BRACKETPASTE);
- cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr, pflag);
+ pflag = (wp->screen->mode & MODE_BRACKETPASTE);
+ paste_send_pane(pb, wp, sepstr, args_has(args, 'p') && pflag);
}
/* Delete the buffer if -d. */
@@ -102,30 +101,3 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_NORMAL);
}
-
-/* Add bytes to a buffer and filter '\n' according to separator. */
-void
-cmd_paste_buffer_filter(struct window_pane *wp,
- const char *data, size_t size, const char *sep, int bracket)
-{
- const char *end = data + size;
- const char *lf;
- size_t seplen;
-
- if (bracket)
- bufferevent_write(wp->event, "\033[200~", 6);
-
- seplen = strlen(sep);
- while ((lf = memchr(data, '\n', end - data)) != NULL) {
- if (lf != data)
- bufferevent_write(wp->event, data, lf - data);
- bufferevent_write(wp->event, sep, seplen);
- data = lf + 1;
- }
-
- if (end != data)
- bufferevent_write(wp->event, data, end - data);
-
- if (bracket)
- bufferevent_write(wp->event, "\033[201~", 6);
-}
diff --git a/usr.bin/tmux/input-keys.c b/usr.bin/tmux/input-keys.c
index c8642fc615e..67140a35d1e 100644
--- a/usr.bin/tmux/input-keys.c
+++ b/usr.bin/tmux/input-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input-keys.c,v 1.29 2012/11/27 14:26:48 nicm Exp $ */
+/* $OpenBSD: input-keys.c,v 1.30 2012/11/27 20:22:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -202,8 +202,9 @@ input_key(struct window_pane *wp, int key)
void
input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
{
- char buf[10];
- size_t len;
+ char buf[10];
+ size_t len;
+ struct paste_buffer *pb;
if (wp->screen->mode & ALL_MOUSE_MODES) {
if (wp->screen->mode & MODE_MOUSE_UTF8) {
@@ -223,13 +224,19 @@ input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
return;
}
- if ((m->xb & 3) != 1 &&
+ if (m->button == 1 && (m->event & MOUSE_EVENT_CLICK) &&
+ options_get_number(&wp->window->options, "mode-mouse") == 1) {
+ pb = paste_get_top(&global_buffers);
+ if (pb != NULL) {
+ paste_send_pane(pb, wp, "\r",
+ wp->screen->mode & MODE_BRACKETPASTE);
+ }
+ } else if ((m->xb & 3) != 1 &&
options_get_number(&wp->window->options, "mode-mouse") == 1) {
if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
window_copy_init_from_pane(wp);
if (wp->mode->mouse != NULL)
wp->mode->mouse(wp, s, m);
}
- return;
}
}
diff --git a/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c
index affdbe4070f..b79d41c76d0 100644
--- a/usr.bin/tmux/paste.c
+++ b/usr.bin/tmux/paste.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paste.c,v 1.13 2012/09/04 13:24:50 nicm Exp $ */
+/* $OpenBSD: paste.c,v 1.14 2012/11/27 20:22:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -167,3 +167,29 @@ paste_print(struct paste_buffer *pb, size_t width)
return (buf);
}
+
+/* Paste into a window pane, filtering '\n' according to separator. */
+void
+paste_send_pane (struct paste_buffer *pb, struct window_pane *wp,
+ const char *sep, int bracket)
+{
+ const char *data = pb->data, *end = data + pb->size, *lf;
+ size_t seplen;
+
+ if (bracket)
+ bufferevent_write(wp->event, "\033[200~", 6);
+
+ seplen = strlen(sep);
+ while ((lf = memchr(data, '\n', end - data)) != NULL) {
+ if (lf != data)
+ bufferevent_write(wp->event, data, lf - data);
+ bufferevent_write(wp->event, sep, seplen);
+ data = lf + 1;
+ }
+
+ if (end != data)
+ bufferevent_write(wp->event, data, end - data);
+
+ if (bracket)
+ bufferevent_write(wp->event, "\033[201~", 6);
+}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 9fc5ef9aded..8d88176bf6f 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.366 2012/11/27 20:08:42 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.367 2012/11/27 20:22:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1682,8 +1682,8 @@ const char *tty_term_string2(
struct tty_term *, enum tty_code_code, int, int);
const char *tty_term_ptr1(
struct tty_term *, enum tty_code_code, const void *);
-const char *tty_term_ptr2(
- struct tty_term *, enum tty_code_code, const void *, const void *);
+const char *tty_term_ptr2(struct tty_term *, enum tty_code_code,
+ const void *, const void *);
int tty_term_number(struct tty_term *, enum tty_code_code);
int tty_term_flag(struct tty_term *, enum tty_code_code);
@@ -1704,6 +1704,9 @@ int paste_free_index(struct paste_stack *, u_int);
void paste_add(struct paste_stack *, char *, size_t, u_int);
int paste_replace(struct paste_stack *, u_int, char *, size_t);
char *paste_print(struct paste_buffer *, size_t);
+void paste_send_pane(struct paste_buffer *, struct window_pane *,
+ const char *, int);
+
/* clock.c */
extern const char clock_table[14][5][5];
@@ -1906,7 +1909,7 @@ void server_unlink_window(struct session *, struct winlink *);
void server_destroy_pane(struct window_pane *);
void server_destroy_session_group(struct session *);
void server_destroy_session(struct session *);
-void server_check_unattached (void);
+void server_check_unattached(void);
void server_set_identify(struct client *);
void server_clear_identify(struct client *);
void server_update_event(struct client *);