version 1.214, 2019/03/27 13:25:11 |
version 1.215, 2019/04/02 09:03:39 |
|
|
static int window_copy_update_selection(struct window_mode_entry *, int); |
static int window_copy_update_selection(struct window_mode_entry *, int); |
static void window_copy_synchronize_cursor(struct window_mode_entry *); |
static void window_copy_synchronize_cursor(struct window_mode_entry *); |
static void *window_copy_get_selection(struct window_mode_entry *, size_t *); |
static void *window_copy_get_selection(struct window_mode_entry *, size_t *); |
static void window_copy_copy_buffer(struct window_mode_entry *, void *, |
static void window_copy_copy_buffer(struct window_mode_entry *, |
size_t); |
const char *, void *, size_t); |
static void window_copy_copy_pipe(struct window_mode_entry *, |
static void window_copy_copy_pipe(struct window_mode_entry *, |
struct session *, const char *); |
struct session *, const char *, const char *); |
static void window_copy_copy_selection(struct window_mode_entry *); |
static void window_copy_copy_selection(struct window_mode_entry *, |
|
const char *); |
static void window_copy_append_selection(struct window_mode_entry *); |
static void window_copy_append_selection(struct window_mode_entry *); |
static void window_copy_clear_selection(struct window_mode_entry *); |
static void window_copy_clear_selection(struct window_mode_entry *); |
static void window_copy_copy_line(struct window_mode_entry *, char **, |
static void window_copy_copy_line(struct window_mode_entry *, char **, |
|
|
struct window_mode_entry *wme; |
struct window_mode_entry *wme; |
struct args *args; |
struct args *args; |
struct mouse_event *m; |
struct mouse_event *m; |
|
|
struct client *c; |
struct client *c; |
struct session *s; |
struct session *s; |
|
struct winlink *wl; |
}; |
}; |
|
|
/* |
/* |
|
|
window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs) |
window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs) |
{ |
{ |
struct window_mode_entry *wme = cs->wme; |
struct window_mode_entry *wme = cs->wme; |
|
struct client *c = cs->c; |
struct session *s = cs->s; |
struct session *s = cs->s; |
|
struct winlink *wl = cs->wl; |
|
struct window_pane *wp = wme->wp; |
u_int np = wme->prefix; |
u_int np = wme->prefix; |
|
char *prefix = NULL; |
|
|
|
if (cs->args->argc == 2) |
|
prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp); |
|
|
window_copy_start_selection(wme); |
window_copy_start_selection(wme); |
for (; np > 1; np--) |
for (; np > 1; np--) |
window_copy_cursor_down(wme, 0); |
window_copy_cursor_down(wme, 0); |
window_copy_cursor_end_of_line(wme); |
window_copy_cursor_end_of_line(wme); |
|
|
if (s != NULL) { |
if (s != NULL) { |
window_copy_copy_selection(wme); |
window_copy_copy_selection(wme, prefix); |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_CANCEL); |
return (WINDOW_COPY_CMD_CANCEL); |
} |
} |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_REDRAW); |
return (WINDOW_COPY_CMD_REDRAW); |
} |
} |
|
|
|
|
window_copy_cmd_copy_line(struct window_copy_cmd_state *cs) |
window_copy_cmd_copy_line(struct window_copy_cmd_state *cs) |
{ |
{ |
struct window_mode_entry *wme = cs->wme; |
struct window_mode_entry *wme = cs->wme; |
|
struct client *c = cs->c; |
struct session *s = cs->s; |
struct session *s = cs->s; |
|
struct winlink *wl = cs->wl; |
|
struct window_pane *wp = wme->wp; |
u_int np = wme->prefix; |
u_int np = wme->prefix; |
|
char *prefix = NULL; |
|
|
|
if (cs->args->argc == 2) |
|
prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp); |
|
|
window_copy_cursor_start_of_line(wme); |
window_copy_cursor_start_of_line(wme); |
window_copy_start_selection(wme); |
window_copy_start_selection(wme); |
for (; np > 1; np--) |
for (; np > 1; np--) |
|
|
window_copy_cursor_end_of_line(wme); |
window_copy_cursor_end_of_line(wme); |
|
|
if (s != NULL) { |
if (s != NULL) { |
window_copy_copy_selection(wme); |
window_copy_copy_selection(wme, prefix); |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_CANCEL); |
return (WINDOW_COPY_CMD_CANCEL); |
} |
} |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_REDRAW); |
return (WINDOW_COPY_CMD_REDRAW); |
} |
} |
|
|
|
|
window_copy_cmd_copy_selection(struct window_copy_cmd_state *cs) |
window_copy_cmd_copy_selection(struct window_copy_cmd_state *cs) |
{ |
{ |
struct window_mode_entry *wme = cs->wme; |
struct window_mode_entry *wme = cs->wme; |
|
struct client *c = cs->c; |
struct session *s = cs->s; |
struct session *s = cs->s; |
|
struct winlink *wl = cs->wl; |
|
struct window_pane *wp = wme->wp; |
|
char *prefix = NULL; |
|
|
|
if (cs->args->argc == 2) |
|
prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp); |
|
|
if (s != NULL) |
if (s != NULL) |
window_copy_copy_selection(wme); |
window_copy_copy_selection(wme, prefix); |
window_copy_clear_selection(wme); |
window_copy_clear_selection(wme); |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_REDRAW); |
return (WINDOW_COPY_CMD_REDRAW); |
} |
} |
|
|
|
|
window_copy_cmd_copy_selection_and_cancel(struct window_copy_cmd_state *cs) |
window_copy_cmd_copy_selection_and_cancel(struct window_copy_cmd_state *cs) |
{ |
{ |
struct window_mode_entry *wme = cs->wme; |
struct window_mode_entry *wme = cs->wme; |
|
struct client *c = cs->c; |
struct session *s = cs->s; |
struct session *s = cs->s; |
|
struct winlink *wl = cs->wl; |
|
struct window_pane *wp = wme->wp; |
|
char *prefix = NULL; |
|
|
|
if (cs->args->argc == 2) |
|
prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp); |
|
|
if (s != NULL) |
if (s != NULL) |
window_copy_copy_selection(wme); |
window_copy_copy_selection(wme, prefix); |
window_copy_clear_selection(wme); |
window_copy_clear_selection(wme); |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_CANCEL); |
return (WINDOW_COPY_CMD_CANCEL); |
} |
} |
|
|
|
|
window_copy_cmd_copy_pipe(struct window_copy_cmd_state *cs) |
window_copy_cmd_copy_pipe(struct window_copy_cmd_state *cs) |
{ |
{ |
struct window_mode_entry *wme = cs->wme; |
struct window_mode_entry *wme = cs->wme; |
|
struct client *c = cs->c; |
struct session *s = cs->s; |
struct session *s = cs->s; |
const char *argument = cs->args->argv[1]; |
struct winlink *wl = cs->wl; |
|
struct window_pane *wp = wme->wp; |
|
char *command = NULL; |
|
char *prefix = NULL; |
|
|
if (s != NULL && *argument != '\0') |
if (cs->args->argc == 3) |
window_copy_copy_pipe(wme, s, argument); |
prefix = format_single(NULL, cs->args->argv[2], c, s, wl, wp); |
|
|
|
if (s != NULL && *cs->args->argv[1] != '\0') { |
|
command = format_single(NULL, cs->args->argv[1], c, s, wl, wp); |
|
window_copy_copy_pipe(wme, s, prefix, command); |
|
free(command); |
|
} |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_NOTHING); |
return (WINDOW_COPY_CMD_NOTHING); |
} |
} |
|
|
|
|
window_copy_cmd_copy_pipe_and_cancel(struct window_copy_cmd_state *cs) |
window_copy_cmd_copy_pipe_and_cancel(struct window_copy_cmd_state *cs) |
{ |
{ |
struct window_mode_entry *wme = cs->wme; |
struct window_mode_entry *wme = cs->wme; |
|
struct client *c = cs->c; |
struct session *s = cs->s; |
struct session *s = cs->s; |
const char *argument = cs->args->argv[1]; |
struct winlink *wl = cs->wl; |
|
struct window_pane *wp = wme->wp; |
|
char *command = NULL; |
|
char *prefix = NULL; |
|
|
if (s != NULL && *argument != '\0') { |
if (cs->args->argc == 3) |
window_copy_copy_pipe(wme, s, argument); |
prefix = format_single(NULL, cs->args->argv[2], c, s, wl, wp); |
|
|
|
if (s != NULL && *cs->args->argv[1] != '\0') { |
|
command = format_single(NULL, cs->args->argv[1], c, s, wl, wp); |
|
window_copy_copy_pipe(wme, s, prefix, command); |
|
free(command); |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_CANCEL); |
return (WINDOW_COPY_CMD_CANCEL); |
} |
} |
|
|
|
free(prefix); |
return (WINDOW_COPY_CMD_NOTHING); |
return (WINDOW_COPY_CMD_NOTHING); |
} |
} |
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPFORWARD; |
data->jumptype = WINDOW_COPY_JUMPFORWARD; |
data->jumpchar = *argument; |
data->jumpchar = *argument; |
for (; np != 0; np--) |
for (; np != 0; np--) |
window_copy_cursor_jump(wme); |
window_copy_cursor_jump(wme); |
} |
} |
return (WINDOW_COPY_CMD_NOTHING); |
return (WINDOW_COPY_CMD_NOTHING); |
} |
} |
|
|
window_copy_cmd_cancel }, |
window_copy_cmd_cancel }, |
{ "clear-selection", 0, 0, |
{ "clear-selection", 0, 0, |
window_copy_cmd_clear_selection }, |
window_copy_cmd_clear_selection }, |
{ "copy-end-of-line", 0, 0, |
{ "copy-end-of-line", 0, 1, |
window_copy_cmd_copy_end_of_line }, |
window_copy_cmd_copy_end_of_line }, |
{ "copy-line", 0, 0, |
{ "copy-line", 0, 1, |
window_copy_cmd_copy_line }, |
window_copy_cmd_copy_line }, |
{ "copy-pipe", 1, 1, |
{ "copy-pipe", 1, 2, |
window_copy_cmd_copy_pipe }, |
window_copy_cmd_copy_pipe }, |
{ "copy-pipe-and-cancel", 1, 1, |
{ "copy-pipe-and-cancel", 1, 2, |
window_copy_cmd_copy_pipe_and_cancel }, |
window_copy_cmd_copy_pipe_and_cancel }, |
{ "copy-selection", 0, 0, |
{ "copy-selection", 0, 1, |
window_copy_cmd_copy_selection }, |
window_copy_cmd_copy_selection }, |
{ "copy-selection-and-cancel", 0, 0, |
{ "copy-selection-and-cancel", 0, 1, |
window_copy_cmd_copy_selection_and_cancel }, |
window_copy_cmd_copy_selection_and_cancel }, |
{ "cursor-down", 0, 0, |
{ "cursor-down", 0, 0, |
window_copy_cmd_cursor_down }, |
window_copy_cmd_cursor_down }, |
|
|
|
|
static void |
static void |
window_copy_command(struct window_mode_entry *wme, struct client *c, |
window_copy_command(struct window_mode_entry *wme, struct client *c, |
struct session *s, __unused struct winlink *wl, struct args *args, |
struct session *s, struct winlink *wl, struct args *args, |
struct mouse_event *m) |
struct mouse_event *m) |
{ |
{ |
struct window_copy_mode_data *data = wme->data; |
struct window_copy_mode_data *data = wme->data; |
|
|
cs.wme = wme; |
cs.wme = wme; |
cs.args = args; |
cs.args = args; |
cs.m = m; |
cs.m = m; |
|
|
cs.c = c; |
cs.c = c; |
cs.s = s; |
cs.s = s; |
|
cs.wl = wl; |
|
|
action = WINDOW_COPY_CMD_NOTHING; |
action = WINDOW_COPY_CMD_NOTHING; |
for (i = 0; i < nitems(window_copy_cmd_table); i++) { |
for (i = 0; i < nitems(window_copy_cmd_table); i++) { |
|
|
} |
} |
|
|
static void |
static void |
window_copy_copy_buffer(struct window_mode_entry *wme, void *buf, size_t len) |
window_copy_copy_buffer(struct window_mode_entry *wme, const char *prefix, |
|
void *buf, size_t len) |
{ |
{ |
struct window_pane *wp = wme->wp; |
struct window_pane *wp = wme->wp; |
struct screen_write_ctx ctx; |
struct screen_write_ctx ctx; |
|
|
notify_pane("pane-set-clipboard", wp); |
notify_pane("pane-set-clipboard", wp); |
} |
} |
|
|
if (paste_set(buf, len, NULL, NULL) != 0) |
paste_add(prefix, buf, len); |
free(buf); |
|
} |
} |
|
|
static void |
static void |
window_copy_copy_pipe(struct window_mode_entry *wme, struct session *s, |
window_copy_copy_pipe(struct window_mode_entry *wme, struct session *s, |
const char *fmt) |
const char *prefix, const char *command) |
{ |
{ |
struct window_pane *wp = wme->wp; |
void *buf; |
void *buf; |
size_t len; |
size_t len; |
struct job *job; |
struct job *job; |
|
char *expanded; |
|
|
|
buf = window_copy_get_selection(wme, &len); |
buf = window_copy_get_selection(wme, &len); |
if (buf == NULL) |
if (buf == NULL) |
return; |
return; |
expanded = format_single(NULL, fmt, NULL, s, NULL, wp); |
|
|
|
job = job_run(expanded, s, NULL, NULL, NULL, NULL, NULL, JOB_NOWAIT); |
job = job_run(command, s, NULL, NULL, NULL, NULL, NULL, JOB_NOWAIT); |
bufferevent_write(job_get_event(job), buf, len); |
bufferevent_write(job_get_event(job), buf, len); |
|
window_copy_copy_buffer(wme, prefix, buf, len); |
free(expanded); |
|
window_copy_copy_buffer(wme, buf, len); |
|
} |
} |
|
|
static void |
static void |
window_copy_copy_selection(struct window_mode_entry *wme) |
window_copy_copy_selection(struct window_mode_entry *wme, const char *prefix) |
{ |
{ |
char *buf; |
char *buf; |
size_t len; |
size_t len; |
|
|
buf = window_copy_get_selection(wme, &len); |
buf = window_copy_get_selection(wme, &len); |
if (buf != NULL) |
if (buf != NULL) |
window_copy_copy_buffer(wme, buf, len); |
window_copy_copy_buffer(wme, prefix, buf, len); |
} |
} |
|
|
static void |
static void |