-/* $OpenBSD: window-copy.c,v 1.354 2024/10/01 08:01:19 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.355 2024/10/04 07:03:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
static void window_copy_synchronize_cursor(struct window_mode_entry *, int);
static void *window_copy_get_selection(struct window_mode_entry *, size_t *);
static void window_copy_copy_buffer(struct window_mode_entry *,
- const char *, void *, size_t);
+ const char *, void *, size_t, int, int);
static void window_copy_pipe(struct window_mode_entry *,
struct session *, const char *);
static void window_copy_copy_pipe(struct window_mode_entry *,
- struct session *, const char *, const char *);
+ struct session *, const char *, const char *,
+ int, int);
static void window_copy_copy_selection(struct window_mode_entry *,
- const char *);
+ const char *, int, int);
static void window_copy_append_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_cursor_previous_word(struct window_mode_entry *,
const char *, int);
static void window_copy_cursor_prompt(struct window_mode_entry *, int,
- 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_set(struct window_mode_entry *, int);
struct window_copy_cmd_state {
struct window_mode_entry *wme;
struct args *args;
+ struct args *wargs;
struct mouse_event *m;
struct client *c;
{
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
- const char *ss = args_string(cs->args, 1);
+ const char *ss = args_string(cs->wargs, 0);
char *expanded;
if (ss == NULL || *ss == '\0')
struct session *s = cs->s;
struct winlink *wl = cs->wl;
struct window_pane *wp = wme->wp;
- u_int count = args_count(cs->args);
+ u_int count = args_count(cs->wargs);
u_int np = wme->prefix, ocx, ocy, ooy;
struct window_copy_mode_data *data = wme->data;
char *prefix = NULL, *command = NULL;
- const char *arg1 = args_string(cs->args, 1);
- const char *arg2 = args_string(cs->args, 2);
+ const char *arg0 = args_string(cs->wargs, 0);
+ const char *arg1 = args_string(cs->wargs, 1);
+ int set_paste = !args_has(cs->wargs, 'P');
+ int set_clip = !args_has(cs->wargs, 'C');
if (pipe) {
- if (count == 3)
- prefix = format_single(NULL, arg2, c, s, wl, wp);
- if (s != NULL && count > 1 && *arg1 != '\0')
- command = format_single(NULL, arg1, c, s, wl, wp);
- } else {
if (count == 2)
prefix = format_single(NULL, arg1, c, s, wl, wp);
+ if (s != NULL && count > 0 && *arg0 != '\0')
+ command = format_single(NULL, arg0, c, s, wl, wp);
+ } else {
+ if (count == 1)
+ prefix = format_single(NULL, arg0, c, s, wl, wp);
}
ocx = data->cx;
if (s != NULL) {
if (pipe)
- window_copy_copy_pipe(wme, s, prefix, command);
+ window_copy_copy_pipe(wme, s, prefix, command,
+ set_paste, set_clip);
else
- window_copy_copy_selection(wme, prefix);
+ window_copy_copy_selection(wme, prefix,
+ set_paste, set_clip);
if (cancel) {
free(prefix);
struct winlink *wl = cs->wl;
struct window_pane *wp = wme->wp;
struct window_copy_mode_data *data = wme->data;
- u_int count = args_count(cs->args);
+ u_int count = args_count(cs->wargs);
u_int np = wme->prefix, ocx, ocy, ooy;
char *prefix = NULL, *command = NULL;
- const char *arg1 = args_string(cs->args, 1);
- const char *arg2 = args_string(cs->args, 2);
+ const char *arg0 = args_string(cs->wargs, 0);
+ const char *arg1 = args_string(cs->wargs, 1);
+ int set_paste = !args_has(cs->wargs, 'P');
+ int set_clip = !args_has(cs->wargs, 'C');
if (pipe) {
- if (count == 3)
- prefix = format_single(NULL, arg2, c, s, wl, wp);
- if (s != NULL && count > 1 && *arg1 != '\0')
- command = format_single(NULL, arg1, c, s, wl, wp);
- } else {
if (count == 2)
prefix = format_single(NULL, arg1, c, s, wl, wp);
+ if (s != NULL && count > 0 && *arg0 != '\0')
+ command = format_single(NULL, arg0, c, s, wl, wp);
+ } else {
+ if (count == 1)
+ prefix = format_single(NULL, arg0, c, s, wl, wp);
}
ocx = data->cx;
if (s != NULL) {
if (pipe)
- window_copy_copy_pipe(wme, s, prefix, command);
+ window_copy_copy_pipe(wme, s, prefix, command,
+ set_paste, set_clip);
else
- window_copy_copy_selection(wme, prefix);
+ window_copy_copy_selection(wme, prefix,
+ set_paste, set_clip);
if (cancel) {
free(prefix);
struct winlink *wl = cs->wl;
struct window_pane *wp = wme->wp;
char *prefix = NULL;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
+ int set_paste = !args_has(cs->wargs, 'P');
+ int set_clip = !args_has(cs->wargs, 'C');
- if (arg1 != NULL)
- prefix = format_single(NULL, arg1, c, s, wl, wp);
+ if (arg0 != NULL)
+ prefix = format_single(NULL, arg0, c, s, wl, wp);
if (s != NULL)
- window_copy_copy_selection(wme, prefix);
+ window_copy_copy_selection(wme, prefix, set_paste, set_clip);
free(prefix);
return (WINDOW_COPY_CMD_NOTHING);
struct winlink *wl = cs->wl;
struct window_pane *wp = wme->wp;
char *command = NULL, *prefix = NULL;
- const char *arg1 = args_string(cs->args, 1);
- const char *arg2 = args_string(cs->args, 2);
+ const char *arg0 = args_string(cs->wargs, 0);
+ const char *arg1 = args_string(cs->wargs, 1);
+ int set_paste = !args_has(cs->wargs, 'P');
+ int set_clip = !args_has(cs->wargs, 'C');
- if (arg2 != NULL)
- prefix = format_single(NULL, arg2, c, s, wl, wp);
+ if (arg1 != NULL)
+ prefix = format_single(NULL, arg1, c, s, wl, wp);
- if (s != NULL && arg1 != NULL && *arg1 != '\0')
- command = format_single(NULL, arg1, c, s, wl, wp);
- window_copy_copy_pipe(wme, s, prefix, command);
+ if (s != NULL && arg0 != NULL && *arg0 != '\0')
+ command = format_single(NULL, arg0, c, s, wl, wp);
+ window_copy_copy_pipe(wme, s, prefix, command,
+ set_paste, set_clip);
free(command);
free(prefix);
struct winlink *wl = cs->wl;
struct window_pane *wp = wme->wp;
char *command = NULL;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
- if (s != NULL && arg1 != NULL && *arg1 != '\0')
- command = format_single(NULL, arg1, c, s, wl, wp);
+ if (s != NULL && arg0 != NULL && *arg0 != '\0')
+ command = format_single(NULL, arg0, c, s, wl, wp);
window_copy_pipe(wme, s, command);
free(command);
window_copy_cmd_goto_line(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
- if (*arg1 != '\0')
- window_copy_goto_line(wme, arg1);
+ if (*arg0 != '\0')
+ window_copy_goto_line(wme, arg0);
return (WINDOW_COPY_CMD_NOTHING);
}
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
u_int np = wme->prefix;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
- if (*arg1 != '\0') {
+ if (*arg0 != '\0') {
data->jumptype = WINDOW_COPY_JUMPBACKWARD;
free(data->jumpchar);
- data->jumpchar = utf8_fromcstr(arg1);
+ data->jumpchar = utf8_fromcstr(arg0);
for (; np != 0; np--)
window_copy_cursor_jump_back(wme);
}
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
u_int np = wme->prefix;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
- if (*arg1 != '\0') {
+ if (*arg0 != '\0') {
data->jumptype = WINDOW_COPY_JUMPFORWARD;
free(data->jumpchar);
- data->jumpchar = utf8_fromcstr(arg1);
+ data->jumpchar = utf8_fromcstr(arg0);
for (; np != 0; np--)
window_copy_cursor_jump(wme);
}
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
u_int np = wme->prefix;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
- if (*arg1 != '\0') {
+ if (*arg0 != '\0') {
data->jumptype = WINDOW_COPY_JUMPTOBACKWARD;
free(data->jumpchar);
- data->jumpchar = utf8_fromcstr(arg1);
+ data->jumpchar = utf8_fromcstr(arg0);
for (; np != 0; np--)
window_copy_cursor_jump_to_back(wme);
}
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
u_int np = wme->prefix;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
- if (*arg1 != '\0') {
+ if (*arg0 != '\0') {
data->jumptype = WINDOW_COPY_JUMPTOFORWARD;
free(data->jumpchar);
- data->jumpchar = utf8_fromcstr(arg1);
+ data->jumpchar = utf8_fromcstr(arg0);
for (; np != 0; np--)
window_copy_cursor_jump_to(wme);
}
window_copy_cmd_next_prompt(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
- const char *arg1 = args_string(cs->args, 1);
- window_copy_cursor_prompt(wme, 1, arg1);
+ window_copy_cursor_prompt(wme, 1, args_has(cs->wargs, 'o'));
return (WINDOW_COPY_CMD_NOTHING);
}
window_copy_cmd_previous_prompt(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
- const char *arg1 = args_string(cs->args, 1);
- window_copy_cursor_prompt(wme, 0, arg1);
+ window_copy_cursor_prompt(wme, 0, args_has(cs->wargs, 'o'));
return (WINDOW_COPY_CMD_NOTHING);
}
{
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
const char *ss = data->searchstr;
char prefix;
enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING;
data->timeout = 0;
- log_debug("%s: %s", __func__, arg1);
+ log_debug("%s: %s", __func__, arg0);
- prefix = *arg1++;
+ prefix = *arg0++;
if (data->searchx == -1 || data->searchy == -1) {
data->searchx = data->cx;
data->searchy = data->cy;
data->searcho = data->oy;
- } else if (ss != NULL && strcmp(arg1, ss) != 0) {
+ } else if (ss != NULL && strcmp(arg0, ss) != 0) {
data->cx = data->searchx;
data->cy = data->searchy;
data->oy = data->searcho;
action = WINDOW_COPY_CMD_REDRAW;
}
- if (*arg1 == '\0') {
+ if (*arg0 == '\0') {
window_copy_clear_marks(wme);
return (WINDOW_COPY_CMD_REDRAW);
}
data->searchtype = WINDOW_COPY_SEARCHUP;
data->searchregex = 0;
free(data->searchstr);
- data->searchstr = xstrdup(arg1);
+ data->searchstr = xstrdup(arg0);
if (!window_copy_search_up(wme, 0)) {
window_copy_clear_marks(wme);
return (WINDOW_COPY_CMD_REDRAW);
data->searchtype = WINDOW_COPY_SEARCHDOWN;
data->searchregex = 0;
free(data->searchstr);
- data->searchstr = xstrdup(arg1);
+ data->searchstr = xstrdup(arg0);
if (!window_copy_search_down(wme, 0)) {
window_copy_clear_marks(wme);
return (WINDOW_COPY_CMD_REDRAW);
{
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
- const char *arg1 = args_string(cs->args, 1);
+ const char *arg0 = args_string(cs->wargs, 0);
const char *ss = data->searchstr;
char prefix;
enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING;
data->timeout = 0;
- log_debug("%s: %s", __func__, arg1);
+ log_debug("%s: %s", __func__, arg0);
- prefix = *arg1++;
+ prefix = *arg0++;
if (data->searchx == -1 || data->searchy == -1) {
data->searchx = data->cx;
data->searchy = data->cy;
data->searcho = data->oy;
- } else if (ss != NULL && strcmp(arg1, ss) != 0) {
+ } else if (ss != NULL && strcmp(arg0, ss) != 0) {
data->cx = data->searchx;
data->cy = data->searchy;
data->oy = data->searcho;
action = WINDOW_COPY_CMD_REDRAW;
}
- if (*arg1 == '\0') {
+ if (*arg0 == '\0') {
window_copy_clear_marks(wme);
return (WINDOW_COPY_CMD_REDRAW);
}
data->searchtype = WINDOW_COPY_SEARCHDOWN;
data->searchregex = 0;
free(data->searchstr);
- data->searchstr = xstrdup(arg1);
+ data->searchstr = xstrdup(arg0);
if (!window_copy_search_down(wme, 0)) {
window_copy_clear_marks(wme);
return (WINDOW_COPY_CMD_REDRAW);
data->searchtype = WINDOW_COPY_SEARCHUP;
data->searchregex = 0;
free(data->searchstr);
- data->searchstr = xstrdup(arg1);
+ data->searchstr = xstrdup(arg0);
if (!window_copy_search_up(wme, 0)) {
window_copy_clear_marks(wme);
return (WINDOW_COPY_CMD_REDRAW);
const char *command;
u_int minargs;
u_int maxargs;
+ struct args_parse args;
enum window_copy_cmd_clear clear;
enum window_copy_cmd_action (*f)(struct window_copy_cmd_state *);
} window_copy_cmd_table[] = {
{ .command = "append-selection",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_append_selection
},
{ .command = "append-selection-and-cancel",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_append_selection_and_cancel
},
{ .command = "back-to-indentation",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_back_to_indentation
},
{ .command = "begin-selection",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_begin_selection
},
{ .command = "bottom-line",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_bottom_line
},
{ .command = "cancel",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_cancel
},
{ .command = "clear-selection",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_clear_selection
},
{ .command = "copy-end-of-line",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "CP", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_end_of_line
},
{ .command = "copy-end-of-line-and-cancel",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "CP", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_end_of_line_and_cancel
},
{ .command = "copy-pipe-end-of-line",
- .minargs = 0,
- .maxargs = 2,
+ .args = { "CP", 0, 2, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_pipe_end_of_line
},
{ .command = "copy-pipe-end-of-line-and-cancel",
- .minargs = 0,
- .maxargs = 2,
+ .args = { "CP", 0, 2, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_pipe_end_of_line_and_cancel
},
{ .command = "copy-line",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "CP", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_line
},
{ .command = "copy-line-and-cancel",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "CP", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_line_and_cancel
},
{ .command = "copy-pipe-line",
- .minargs = 0,
- .maxargs = 2,
+ .args = { "CP", 0, 2, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_pipe_line
},
{ .command = "copy-pipe-line-and-cancel",
- .minargs = 0,
- .maxargs = 2,
+ .args = { "CP", 0, 2, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_pipe_line_and_cancel
},
{ .command = "copy-pipe-no-clear",
- .minargs = 0,
- .maxargs = 2,
+ .args = { "CP", 0, 2, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_NEVER,
.f = window_copy_cmd_copy_pipe_no_clear
},
{ .command = "copy-pipe",
- .minargs = 0,
- .maxargs = 2,
+ .args = { "CP", 0, 2, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_pipe
},
{ .command = "copy-pipe-and-cancel",
- .minargs = 0,
- .maxargs = 2,
+ .args = { "CP", 0, 2, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_pipe_and_cancel
},
{ .command = "copy-selection-no-clear",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "CP", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_NEVER,
.f = window_copy_cmd_copy_selection_no_clear
},
{ .command = "copy-selection",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "CP", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_selection
},
{ .command = "copy-selection-and-cancel",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "CP", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_copy_selection_and_cancel
},
{ .command = "cursor-down",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_cursor_down
},
{ .command = "cursor-down-and-cancel",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_cursor_down_and_cancel
},
{ .command = "cursor-left",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_cursor_left
},
{ .command = "cursor-right",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_cursor_right
},
{ .command = "cursor-up",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_cursor_up
},
{ .command = "end-of-line",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_end_of_line
},
{ .command = "goto-line",
- .minargs = 1,
- .maxargs = 1,
+ .args = { "", 1, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_goto_line
},
{ .command = "halfpage-down",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_halfpage_down
},
{ .command = "halfpage-down-and-cancel",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_halfpage_down_and_cancel
},
{ .command = "halfpage-up",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_halfpage_up
},
{ .command = "history-bottom",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_history_bottom
},
{ .command = "history-top",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_history_top
},
{ .command = "jump-again",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_jump_again
},
{ .command = "jump-backward",
- .minargs = 1,
- .maxargs = 1,
+ .args = { "", 1, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_jump_backward
},
{ .command = "jump-forward",
- .minargs = 1,
- .maxargs = 1,
+ .args = { "", 1, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_jump_forward
},
{ .command = "jump-reverse",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_jump_reverse
},
{ .command = "jump-to-backward",
- .minargs = 1,
- .maxargs = 1,
+ .args = { "", 1, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_jump_to_backward
},
{ .command = "jump-to-forward",
- .minargs = 1,
- .maxargs = 1,
+ .args = { "", 1, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_jump_to_forward
},
{ .command = "jump-to-mark",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_jump_to_mark
},
{ .command = "next-prompt",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "o", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_next_prompt
},
{ .command = "previous-prompt",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "o", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_previous_prompt
},
{ .command = "middle-line",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_middle_line
},
{ .command = "next-matching-bracket",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_next_matching_bracket
},
{ .command = "next-paragraph",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_next_paragraph
},
{ .command = "next-space",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_next_space
},
{ .command = "next-space-end",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_next_space_end
},
{ .command = "next-word",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_next_word
},
{ .command = "next-word-end",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_next_word_end
},
{ .command = "other-end",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_other_end
},
{ .command = "page-down",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_page_down
},
{ .command = "page-down-and-cancel",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_page_down_and_cancel
},
{ .command = "page-up",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_page_up
},
{ .command = "pipe-no-clear",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_NEVER,
.f = window_copy_cmd_pipe_no_clear
},
{ .command = "pipe",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_pipe
},
{ .command = "pipe-and-cancel",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_pipe_and_cancel
},
{ .command = "previous-matching-bracket",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_previous_matching_bracket
},
{ .command = "previous-paragraph",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_previous_paragraph
},
{ .command = "previous-space",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_previous_space
},
{ .command = "previous-word",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_previous_word
},
{ .command = "rectangle-on",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_rectangle_on
},
{ .command = "rectangle-off",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_rectangle_off
},
{ .command = "rectangle-toggle",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_rectangle_toggle
},
{ .command = "refresh-from-pane",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_refresh_from_pane
},
{ .command = "scroll-bottom",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_scroll_bottom
},
{ .command = "scroll-down",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_scroll_down
},
{ .command = "scroll-down-and-cancel",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_scroll_down_and_cancel
},
{ .command = "scroll-middle",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_scroll_middle
},
{ .command = "scroll-top",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_scroll_top
},
{ .command = "scroll-up",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_scroll_up
},
{ .command = "search-again",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_again
},
{ .command = "search-backward",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_backward
},
{ .command = "search-backward-text",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_backward_text
},
{ .command = "search-backward-incremental",
- .minargs = 1,
- .maxargs = 1,
+ .args = { "", 1, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_backward_incremental
},
{ .command = "search-forward",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_forward
},
{ .command = "search-forward-text",
- .minargs = 0,
- .maxargs = 1,
+ .args = { "", 0, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_forward_text
},
{ .command = "search-forward-incremental",
- .minargs = 1,
- .maxargs = 1,
+ .args = { "", 1, 1, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_forward_incremental
},
{ .command = "search-reverse",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_search_reverse
},
{ .command = "select-line",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_select_line
},
{ .command = "select-word",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_select_word
},
{ .command = "set-mark",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_set_mark
},
{ .command = "start-of-line",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_start_of_line
},
{ .command = "stop-selection",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_ALWAYS,
.f = window_copy_cmd_stop_selection
},
{ .command = "toggle-position",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_NEVER,
.f = window_copy_cmd_toggle_position
},
{ .command = "top-line",
- .minargs = 0,
- .maxargs = 0,
+ .args = { "", 0, 0, NULL },
.clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
.f = window_copy_cmd_top_line
}
struct mouse_event *m)
{
struct window_copy_mode_data *data = wme->data;
+ struct window_pane *wp = wme->wp;
struct window_copy_cmd_state cs;
enum window_copy_cmd_action action;
enum window_copy_cmd_clear clear = WINDOW_COPY_CMD_CLEAR_NEVER;
const char *command;
u_int i, count = args_count(args);
int keys;
+ char *error = NULL;
if (count == 0)
return;
cs.wme = wme;
cs.args = args;
+ cs.wargs = NULL;
cs.m = m;
cs.c = c;
action = WINDOW_COPY_CMD_NOTHING;
for (i = 0; i < nitems(window_copy_cmd_table); i++) {
if (strcmp(window_copy_cmd_table[i].command, command) == 0) {
- if (count - 1 < window_copy_cmd_table[i].minargs ||
- count - 1 > window_copy_cmd_table[i].maxargs)
+ cs.wargs = args_parse(&window_copy_cmd_table[i].args,
+ args_values(args), count, &error);
+
+ if (error != NULL) {
+ free(error);
+ error = NULL;
+ }
+ if (cs.wargs == NULL)
break;
+
clear = window_copy_cmd_table[i].clear;
action = window_copy_cmd_table[i].f(&cs);
+ args_free(cs.wargs);
+ cs.wargs = NULL;
break;
}
}
if (strncmp(command, "search-", 7) != 0 && data->searchmark != NULL) {
- keys = options_get_number(wme->wp->window->options, "mode-keys");
+ keys = options_get_number(wp->window->options, "mode-keys");
if (clear == WINDOW_COPY_CMD_CLEAR_EMACS_ONLY &&
keys == MODEKEY_VI)
clear = WINDOW_COPY_CMD_CLEAR_NEVER;
wme->prefix = 1;
if (action == WINDOW_COPY_CMD_CANCEL)
- window_pane_reset_mode(wme->wp);
+ window_pane_reset_mode(wp);
else if (action == WINDOW_COPY_CMD_REDRAW)
window_copy_redraw_screen(wme);
}
static void
window_copy_copy_buffer(struct window_mode_entry *wme, const char *prefix,
- void *buf, size_t len)
+ void *buf, size_t len, int set_paste, int set_clip)
{
struct window_pane *wp = wme->wp;
struct screen_write_ctx ctx;
- if (options_get_number(global_options, "set-clipboard") != 0) {
+ if (set_clip && options_get_number(global_options, "set-clipboard") != 0) {
screen_write_start_pane(&ctx, wp, NULL);
screen_write_setselection(&ctx, "", buf, len);
screen_write_stop(&ctx);
notify_pane("pane-set-clipboard", wp);
}
- paste_add(prefix, buf, len);
+ if (set_paste)
+ paste_add(prefix, buf, len);
}
static void *
static void
window_copy_copy_pipe(struct window_mode_entry *wme, struct session *s,
- const char *prefix, const char *cmd)
+ const char *prefix, const char *cmd, int set_paste, int set_clip)
{
void *buf;
size_t len;
buf = window_copy_pipe_run(wme, s, cmd, &len);
if (buf != NULL)
- window_copy_copy_buffer(wme, prefix, buf, len);
+ window_copy_copy_buffer(wme, prefix, buf, len, set_paste,
+ set_clip);
}
static void
-window_copy_copy_selection(struct window_mode_entry *wme, const char *prefix)
+window_copy_copy_selection(struct window_mode_entry *wme, const char *prefix,
+ int set_paste, int set_clip)
{
char *buf;
size_t len;
buf = window_copy_get_selection(wme, &len);
if (buf != NULL)
- window_copy_copy_buffer(wme, prefix, buf, len);
+ window_copy_copy_buffer(wme, prefix, buf, len, set_paste,
+ set_clip);
}
static void
static void
window_copy_cursor_prompt(struct window_mode_entry *wme, int direction,
- const char *args)
+ int start_output)
{
struct window_copy_mode_data *data = wme->data;
struct screen *s = data->backing;
u_int line = gd->hsize - data->oy + data->cy;
int add, line_flag;
- if (args != NULL && strcmp(args, "-o") == 0)
+ if (start_output)
line_flag = GRID_LINE_START_OUTPUT;
else
line_flag = GRID_LINE_START_PROMPT;