aboutsummaryrefslogtreecommitdiff
path: root/window-copy.c
diff options
context:
space:
mode:
authorThomas Adam <thomas.adam@smoothwall.net>2013-03-25 14:59:29 +0000
committerThomas Adam <thomas.adam@smoothwall.net>2013-03-25 14:59:29 +0000
commitf90eb43fcb12720711ea01b110c5b474111e6600 (patch)
tree43b2e85bcf1626e3810ade10578ac18399931772 /window-copy.c
parent418ba99078a2712ece398e17a5a9bc1f6600126b (diff)
parent58bb6f8c5650d496fb3b872766c0278aa024631d (diff)
downloadrtmux-f90eb43fcb12720711ea01b110c5b474111e6600.tar.gz
rtmux-f90eb43fcb12720711ea01b110c5b474111e6600.tar.bz2
rtmux-f90eb43fcb12720711ea01b110c5b474111e6600.zip
Merge branch 'obsd-master'
Diffstat (limited to 'window-copy.c')
-rw-r--r--window-copy.c81
1 files changed, 67 insertions, 14 deletions
diff --git a/window-copy.c b/window-copy.c
index c319aba6..51a8f108 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -52,6 +52,10 @@ void window_copy_goto_line(struct window_pane *, const char *);
void window_copy_update_cursor(struct window_pane *, u_int, u_int);
void window_copy_start_selection(struct window_pane *);
int window_copy_update_selection(struct window_pane *);
+void *window_copy_get_selection(struct window_pane *, size_t *);
+void window_copy_copy_buffer(struct window_pane *, int, void *, size_t);
+void window_copy_copy_pipe(
+ struct window_pane *, struct session *, int, const char *);
void window_copy_copy_selection(struct window_pane *, int);
void window_copy_clear_selection(struct window_pane *);
void window_copy_copy_line(
@@ -364,6 +368,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key)
u_int n;
int np, keys;
enum mode_key_cmd cmd;
+ const char *arg;
np = data->numprefix;
if (np <= 0)
@@ -405,7 +410,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key)
return;
}
- cmd = mode_key_lookup(&data->mdata, key);
+ cmd = mode_key_lookup(&data->mdata, key, &arg);
switch (cmd) {
case MODEKEYCOPY_CANCEL:
window_pane_reset_mode(wp);
@@ -533,6 +538,13 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key)
window_copy_clear_selection(wp);
window_copy_redraw_screen(wp);
break;
+ case MODEKEYCOPY_COPYPIPE:
+ if (sess != NULL) {
+ window_copy_copy_pipe(wp, sess, data->numprefix, arg);
+ window_pane_reset_mode(wp);
+ return;
+ }
+ break;
case MODEKEYCOPY_COPYSELECTION:
if (sess != NULL) {
window_copy_copy_selection(wp, data->numprefix);
@@ -735,7 +747,7 @@ window_copy_key_input(struct window_pane *wp, int key)
size_t inputlen;
int np;
- switch (mode_key_lookup(&data->mdata, key)) {
+ switch (mode_key_lookup(&data->mdata, key, NULL)) {
case MODEKEYEDIT_CANCEL:
data->numprefix = -1;
return (-1);
@@ -814,7 +826,6 @@ window_copy_key_numeric_prefix(struct window_pane *wp, int key)
return (0);
}
-/* ARGSUSED */
void
window_copy_mouse(
struct window_pane *wp, struct session *sess, struct mouse_event *m)
@@ -1260,19 +1271,19 @@ window_copy_update_selection(struct window_pane *wp)
return (1);
}
-void
-window_copy_copy_selection(struct window_pane *wp, int idx)
+void *
+window_copy_get_selection(struct window_pane *wp, size_t *len)
{
struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen;
char *buf;
size_t off;
- u_int i, xx, yy, sx, sy, ex, ey, limit;
+ u_int i, xx, yy, sx, sy, ex, ey;
u_int firstsx, lastex, restex, restsx;
int keys;
if (!s->sel.flag)
- return;
+ return (NULL);
buf = xmalloc(1);
off = 0;
@@ -1365,19 +1376,61 @@ window_copy_copy_selection(struct window_pane *wp, int idx)
/* Don't bother if no data. */
if (off == 0) {
free(buf);
- return;
+ return (NULL);
}
- off--; /* remove final \n */
+ *len = off - 1; /* remove final \n */
+ return (buf);
+}
+
+void
+window_copy_copy_buffer(struct window_pane *wp, int idx, void *buf, size_t len)
+{
+ u_int limit;
+ struct screen_write_ctx ctx;
- if (options_get_number(&global_options, "set-clipboard"))
- screen_write_setselection(&wp->ictx.ctx, buf, off);
+ if (options_get_number(&global_options, "set-clipboard")) {
+ screen_write_start(&ctx, wp, NULL);
+ screen_write_setselection(&ctx, buf, len);
+ screen_write_stop(&ctx);
+ }
- /* Add the buffer to the stack. */
if (idx == -1) {
limit = options_get_number(&global_options, "buffer-limit");
- paste_add(&global_buffers, buf, off, limit);
+ paste_add(&global_buffers, buf, len, limit);
} else
- paste_replace(&global_buffers, idx, buf, off);
+ paste_replace(&global_buffers, idx, buf, len);
+}
+
+void
+window_copy_copy_pipe(
+ struct window_pane *wp, struct session *sess, int idx, const char *arg)
+{
+ void *buf;
+ size_t len;
+ struct job *job;
+
+
+ buf = window_copy_get_selection(wp, &len);
+ if (buf == NULL)
+ return;
+
+ job = job_run(arg, sess, NULL, NULL, NULL);
+ bufferevent_write(job->event, buf, len);
+
+ window_copy_copy_buffer(wp, idx, buf, len);
+}
+
+void
+window_copy_copy_selection(struct window_pane *wp, int idx)
+{
+ void* buf;
+ size_t len;
+
+ buf = window_copy_get_selection(wp, &len);
+ if (buf == NULL)
+ return;
+
+ window_copy_copy_buffer(wp, idx, buf, len);
}
void