diff options
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | COPYING | 7 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | cfg.c | 3 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | format.c | 17 | ||||
-rw-r--r-- | input.c | 2 | ||||
-rw-r--r-- | paste.c | 9 | ||||
-rw-r--r-- | tmux.1 | 21 | ||||
-rw-r--r-- | tmux.h | 2 | ||||
-rw-r--r-- | tty-keys.c | 2 | ||||
-rw-r--r-- | window-buffer.c | 16 | ||||
-rw-r--r-- | window-copy.c | 1555 |
13 files changed, 1182 insertions, 462 deletions
@@ -1,3 +1,8 @@ +CHANGES FROM 2.9 to X.X + +* Allow the prefix used for new buffer names to be given as an argument to the + copy commands in copy mode. + CHANGES FROM 2.8 to 2.9 * Add format variables for the default formats in the various modes @@ -19,7 +24,7 @@ CHANGES FROM 2.8 to 2.9 Now that it is possible to configure their content, enable the existing code that lets the status line be multiple lines in height. The status option can - now take a value of 2, 3, 4 or 5 (as well as the previou s on or off) to + now take a value of 2, 3, 4 or 5 (as well as the previous on or off) to configure more than one line. The new status-format array option configures the format of each line, the default just references the existing status-* options, although some of the more obscure status options may be eliminated @@ -1,10 +1,7 @@ THIS IS FOR INFORMATION ONLY, CODE IS UNDER THE LICENCE AT THE TOP OF ITS FILE. -The README, CHANGES, FAQ and TODO files are licensed under the ISC -license. Files under examples/ remain copyright their authors unless otherwise -stated in the file but permission has been received to distribute them with -tmux. All other files have a license and copyright notice at their start, -typically: +The README, CHANGES, FAQ and TODO files are licensed under the ISC license. All +other files have a license and copyright notice at their start, typically: Copyright (c) <author> @@ -159,3 +159,4 @@ TODO soonish maybe: collected LRU. - Command aliases should be able to override builtin commands in order to add default flags (some mechanism needed to avoid recursion). GitHub issue 1630. +- window-size latest, GitHub issue 1637. @@ -101,7 +101,8 @@ start_cfg(void) cmdq_append(c, cfg_item); } - load_cfg(TMUX_CONF, NULL, NULL, 1); + if (cfg_file == NULL) + load_cfg(TMUX_CONF, NULL, NULL, 1); if (cfg_file == NULL && (home = find_home()) != NULL) { xasprintf(&cfg_file, "%s/.tmux.conf", home); diff --git a/configure.ac b/configure.ac index 79e3ba8c..1e7578ee 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # configure.ac -AC_INIT([tmux], 2.9-rc2) +AC_INIT([tmux], next-3.0) AC_PREREQ([2.60]) AC_CONFIG_AUX_DIR(etc) @@ -1822,6 +1822,23 @@ void format_defaults(struct format_tree *ft, struct client *c, struct session *s, struct winlink *wl, struct window_pane *wp) { + if (c != NULL) + log_debug("%s: c=%s", __func__, c->name); + else + log_debug("%s: s=none", __func__); + if (s != NULL) + log_debug("%s: s=$%u", __func__, s->id); + else + log_debug("%s: s=none", __func__); + if (wl != NULL) + log_debug("%s: wl=%u w=@%u", __func__, wl->idx, wl->window->id); + else + log_debug("%s: wl=none", __func__); + if (wp != NULL) + log_debug("%s: wp=%%%u", __func__, wp->id); + else + log_debug("%s: wp=none", __func__); + if (c != NULL && s != NULL && c->session != s) log_debug("%s: session does not match", __func__); @@ -2432,7 +2432,7 @@ input_osc_52(struct input_ctx *ictx, const char *p) screen_write_stop(&ctx); notify_pane("pane-set-clipboard", wp); - paste_add(out, outlen); + paste_add(NULL, out, outlen); } /* Handle the OSC 104 sequence for unsetting (multiple) palette entries. */ @@ -157,11 +157,14 @@ paste_free(struct paste_buffer *pb) * that the caller is responsible for allocating data. */ void -paste_add(char *data, size_t size) +paste_add(const char *prefix, char *data, size_t size) { struct paste_buffer *pb, *pb1; u_int limit; + if (prefix == NULL) + prefix = "buffer"; + if (size == 0) { free(data); return; @@ -180,7 +183,7 @@ paste_add(char *data, size_t size) pb->name = NULL; do { free(pb->name); - xasprintf(&pb->name, "buffer%04u", paste_next_index); + xasprintf(&pb->name, "%s%u", prefix, paste_next_index); paste_next_index++; } while (paste_get_name(pb->name) != NULL); @@ -262,7 +265,7 @@ paste_set(char *data, size_t size, const char *name, char **cause) return (0); } if (name == NULL) { - paste_add(data, size); + paste_add(NULL, data, size); return (0); } @@ -1175,12 +1175,12 @@ The following commands are supported in copy mode: .It Li "bottom-line" Ta "L" Ta "" .It Li "cancel" Ta "q" Ta "Escape" .It Li "clear-selection" Ta "Escape" Ta "C-g" -.It Li "copy-end-of-line" Ta "D" Ta "C-k" -.It Li "copy-line" Ta "" Ta "" -.It Li "copy-pipe <command>" Ta "" Ta "" -.It Li "copy-pipe-and-cancel <command>" Ta "" Ta "" -.It Li "copy-selection" Ta "" Ta "" -.It Li "copy-selection-and-cancel" Ta "Enter" Ta "M-w" +.It Li "copy-end-of-line [<prefix>]" Ta "D" Ta "C-k" +.It Li "copy-line [<prefix>]" Ta "" Ta "" +.It Li "copy-pipe <command> [<prefix>]" Ta "" Ta "" +.It Li "copy-pipe-and-cancel <command> [<prefix>]" Ta "" Ta "" +.It Li "copy-selection [<prefix>]" Ta "" Ta "" +.It Li "copy-selection-and-cancel [<prefix>]" Ta "Enter" Ta "M-w" .It Li "cursor-down" Ta "j" Ta "Down" .It Li "cursor-left" Ta "h" Ta "Left" .It Li "cursor-right" Ta "l" Ta "Right" @@ -1227,6 +1227,15 @@ The following commands are supported in copy mode: .It Li "top-line" Ta "H" Ta "M-R" .El .Pp +Copy commands may take an optional buffer prefix argument which is used +to generate the buffer name (the default is +.Ql buffer +so buffers are named +.Ql buffer0 , +.Ql buffer1 +and so on). +Pipe commands take a command argument which is the command to which the +copied text is piped. The .Ql -and-cancel variants of some commands exit copy mode after they have completed (for copy @@ -1613,7 +1613,7 @@ struct paste_buffer *paste_walk(struct paste_buffer *); struct paste_buffer *paste_get_top(const char **); struct paste_buffer *paste_get_name(const char *); void paste_free(struct paste_buffer *); -void paste_add(char *, size_t); +void paste_add(const char *, char *, size_t); int paste_rename(const char *, const char *, char **); int paste_set(char *, size_t, const char *, char **); char *paste_make_sample(struct paste_buffer *); @@ -976,7 +976,7 @@ tty_keys_clipboard(__unused struct tty *tty, const char *buf, size_t len, /* Create a new paste buffer. */ log_debug("%s: %.*s", __func__, outlen, out); - paste_add(out, outlen); + paste_add(NULL, out, outlen); return (0); } diff --git a/window-buffer.c b/window-buffer.c index 79b02e9b..07cdd80d 100644 --- a/window-buffer.c +++ b/window-buffer.c @@ -66,6 +66,7 @@ struct window_buffer_itemdata { }; struct window_buffer_modedata { + struct cmd_find_state fs; struct mode_tree_data *data; char *command; char *format; @@ -137,6 +138,9 @@ window_buffer_build(void *modedata, u_int sort_type, __unused uint64_t *tag, struct paste_buffer *pb; char *text, *cp; struct format_tree *ft; + struct session *s = NULL; + struct winlink *wl = NULL; + struct window_pane *wp = NULL; for (i = 0; i < data->item_size; i++) window_buffer_free_item(data->item_list[i]); @@ -167,6 +171,12 @@ window_buffer_build(void *modedata, u_int sort_type, __unused uint64_t *tag, break; } + if (cmd_find_valid_state(&data->fs)) { + s = data->fs.s; + wl = data->fs.wl; + wp = data->fs.wp; + } + for (i = 0; i < data->item_size; i++) { item = data->item_list[i]; @@ -174,6 +184,7 @@ window_buffer_build(void *modedata, u_int sort_type, __unused uint64_t *tag, if (pb == NULL) continue; ft = format_create(NULL, NULL, FORMAT_NONE, 0); + format_defaults(ft, NULL, s, wl, wp); format_defaults_paste_buffer(ft, pb); if (filter != NULL) { @@ -253,14 +264,15 @@ window_buffer_search(__unused void *modedata, void *itemdata, const char *ss) } static struct screen * -window_buffer_init(struct window_mode_entry *wme, - __unused struct cmd_find_state *fs, struct args *args) +window_buffer_init(struct window_mode_entry *wme, struct cmd_find_state *fs, + struct args *args) { struct window_pane *wp = wme->wp; struct window_buffer_modedata *data; struct screen *s; wme->data = data = xcalloc(1, sizeof *data); + cmd_find_copy_state(&data->fs, fs); if (args == NULL || !args_has(args, 'F')) data->format = xstrdup(WINDOW_BUFFER_DEFAULT_FORMAT); diff --git a/window-copy.c b/window-copy.c index 062d687f..aacea5c5 100644 --- a/window-copy.c +++ b/window-copy.c @@ -79,11 +79,12 @@ static int window_copy_set_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_get_selection(struct window_mode_entry *, size_t *); -static void window_copy_copy_buffer(struct window_mode_entry *, void *, - size_t); +static void window_copy_copy_buffer(struct window_mode_entry *, + const char *, void *, size_t); static void window_copy_copy_pipe(struct window_mode_entry *, - struct session *, const char *); -static void window_copy_copy_selection(struct window_mode_entry *); + struct session *, const char *, const char *); +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_clear_selection(struct window_mode_entry *); static void window_copy_copy_line(struct window_mode_entry *, char **, @@ -154,6 +155,22 @@ enum { WINDOW_COPY_REL_POS_BELOW, }; +enum window_copy_cmd_action { + WINDOW_COPY_CMD_NOTHING, + WINDOW_COPY_CMD_REDRAW, + WINDOW_COPY_CMD_CANCEL, +}; + +struct window_copy_cmd_state { + struct window_mode_entry *wme; + struct args *args; + struct mouse_event *m; + + struct client *c; + struct session *s; + struct winlink *wl; +}; + /* * Copy mode's visible screen (the "screen" field) is filled from one of two * sources: the original contents of the pane (used when we actually enter via @@ -565,18 +582,1076 @@ window_copy_key_table(struct window_mode_entry *wme) return ("copy-mode"); } +static enum window_copy_cmd_action +window_copy_cmd_append_selection(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct session *s = cs->s; + + if (s != NULL) + window_copy_append_selection(wme); + window_copy_clear_selection(wme); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_append_selection_and_cancel(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct session *s = cs->s; + + if (s != NULL) + window_copy_append_selection(wme); + window_copy_clear_selection(wme); + return (WINDOW_COPY_CMD_CANCEL); +} + +static enum window_copy_cmd_action +window_copy_cmd_back_to_indentation(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + + window_copy_cursor_back_to_indentation(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_begin_selection(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + struct mouse_event *m = cs->m; + struct window_copy_mode_data *data = wme->data; + + if (m != NULL) { + window_copy_start_drag(c, m); + return (WINDOW_COPY_CMD_NOTHING); + } + + data->lineflag = LINE_SEL_NONE; + window_copy_start_selection(wme); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_stop_selection(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + + data->cursordrag = CURSORDRAG_NONE; + data->lineflag = LINE_SEL_NONE; + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_bottom_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + + data->cx = 0; + data->cy = screen_size_y(&data->screen) - 1; + + window_copy_update_selection(wme, 1); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_cancel(__unused struct window_copy_cmd_state *cs) +{ + return (WINDOW_COPY_CMD_CANCEL); +} + +static enum window_copy_cmd_action +window_copy_cmd_clear_selection(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + + window_copy_clear_selection(wme); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + struct session *s = cs->s; + struct winlink *wl = cs->wl; + struct window_pane *wp = wme->wp; + 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); + for (; np > 1; np--) + window_copy_cursor_down(wme, 0); + window_copy_cursor_end_of_line(wme); + + if (s != NULL) { + window_copy_copy_selection(wme, prefix); + + free(prefix); + return (WINDOW_COPY_CMD_CANCEL); + } + + free(prefix); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + struct session *s = cs->s; + struct winlink *wl = cs->wl; + struct window_pane *wp = wme->wp; + 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_start_selection(wme); + for (; np > 1; np--) + window_copy_cursor_down(wme, 0); + window_copy_cursor_end_of_line(wme); + + if (s != NULL) { + window_copy_copy_selection(wme, prefix); + + free(prefix); + return (WINDOW_COPY_CMD_CANCEL); + } + + free(prefix); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_selection(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + 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) + window_copy_copy_selection(wme, prefix); + window_copy_clear_selection(wme); + + free(prefix); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_selection_and_cancel(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + 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) + window_copy_copy_selection(wme, prefix); + window_copy_clear_selection(wme); + + free(prefix); + return (WINDOW_COPY_CMD_CANCEL); +} + +static enum window_copy_cmd_action +window_copy_cmd_cursor_down(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_down(wme, 0); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_cursor_left(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_left(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_cursor_right(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_right(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_cursor_up(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_up(wme, 0); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_end_of_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + + window_copy_cursor_end_of_line(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_halfpage_down(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + for (; np != 0; np--) { + if (window_copy_pagedown(wme, 1, data->scroll_exit)) + return (WINDOW_COPY_CMD_CANCEL); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_halfpage_down_and_cancel(struct window_copy_cmd_state *cs) +{ + + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) { + if (window_copy_pagedown(wme, 1, 1)) + return (WINDOW_COPY_CMD_CANCEL); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_halfpage_up(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_pageup1(wme, 1); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_history_bottom(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + + data->cx = 0; + data->cy = screen_size_y(&data->screen) - 1; + data->oy = 0; + + window_copy_update_selection(wme, 1); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_history_top(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + + data->cx = 0; + data->cy = 0; + data->oy = screen_hsize(data->backing); + + window_copy_update_selection(wme, 1); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_jump_again(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + switch (data->jumptype) { + case WINDOW_COPY_JUMPFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump(wme); + break; + case WINDOW_COPY_JUMPBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump_back(wme); + break; + case WINDOW_COPY_JUMPTOFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to(wme); + break; + case WINDOW_COPY_JUMPTOBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to_back(wme); + break; + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_jump_reverse(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + switch (data->jumptype) { + case WINDOW_COPY_JUMPFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump_back(wme); + break; + case WINDOW_COPY_JUMPBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump(wme); + break; + case WINDOW_COPY_JUMPTOFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to_back(wme); + break; + case WINDOW_COPY_JUMPTOBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to(wme); + break; + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_middle_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + + data->cx = 0; + data->cy = (screen_size_y(&data->screen) - 1) / 2; + + window_copy_update_selection(wme, 1); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_next_paragraph(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_next_paragraph(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_next_space(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_next_word(wme, " "); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_next_space_end(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_next_word_end(wme, " "); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_next_word(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct session *s = cs->s; + u_int np = wme->prefix; + const char *ws; + + ws = options_get_string(s->options, "word-separators"); + for (; np != 0; np--) + window_copy_cursor_next_word(wme, ws); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_next_word_end(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct session *s = cs->s; + u_int np = wme->prefix; + const char *ws; + + ws = options_get_string(s->options, "word-separators"); + for (; np != 0; np--) + window_copy_cursor_next_word_end(wme, ws); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_other_end(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + if ((np % 2) != 0) + window_copy_other_end(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_page_down(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + for (; np != 0; np--) { + if (window_copy_pagedown(wme, 0, data->scroll_exit)) + return (WINDOW_COPY_CMD_CANCEL); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_page_down_and_cancel(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) { + if (window_copy_pagedown(wme, 0, 1)) + return (WINDOW_COPY_CMD_CANCEL); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_page_up(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_pageup1(wme, 0); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_previous_paragraph(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_previous_paragraph(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_previous_space(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_previous_word(wme, " "); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_previous_word(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct session *s = cs->s; + u_int np = wme->prefix; + const char *ws; + + ws = options_get_string(s->options, "word-separators"); + for (; np != 0; np--) + window_copy_cursor_previous_word(wme, ws); + 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); + + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_scroll_down(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_down(wme, 1); + if (data->scroll_exit && data->oy == 0) + return (WINDOW_COPY_CMD_CANCEL); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_scroll_down_and_cancel(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_down(wme, 1); + if (data->oy == 0) + return (WINDOW_COPY_CMD_CANCEL); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_scroll_up(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + u_int np = wme->prefix; + + for (; np != 0; np--) + window_copy_cursor_up(wme, 1); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_search_again(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + if (data->searchtype == WINDOW_COPY_SEARCHUP) { + for (; np != 0; np--) + window_copy_search_up(wme); + } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) { + for (; np != 0; np--) + window_copy_search_down(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_search_reverse(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + if (data->searchtype == WINDOW_COPY_SEARCHUP) { + for (; np != 0; np--) + window_copy_search_down(wme); + } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) { + for (; np != 0; np--) + window_copy_search_up(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_select_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + + data->lineflag = LINE_SEL_LEFT_RIGHT; + data->rectflag = 0; + + window_copy_cursor_start_of_line(wme); + window_copy_start_selection(wme); + for (; np > 1; np--) + window_copy_cursor_down(wme, 0); + window_copy_cursor_end_of_line(wme); + + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_select_word(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct session *s = cs->s; + struct window_copy_mode_data *data = wme->data; + const char *ws; + + data->lineflag = LINE_SEL_LEFT_RIGHT; + data->rectflag = 0; + + ws = options_get_string(s->options, "word-separators"); + window_copy_cursor_previous_word(wme, ws); + window_copy_start_selection(wme); + window_copy_cursor_next_word_end(wme, ws); + + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_start_of_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + + window_copy_cursor_start_of_line(wme); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_top_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + + data->cx = 0; + data->cy = 0; + + window_copy_update_selection(wme, 1); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_pipe(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + struct session *s = cs->s; + struct winlink *wl = cs->wl; + struct window_pane *wp = wme->wp; + char *command = NULL; + char *prefix = NULL; + + if (cs->args->argc == 3) + 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); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_pipe_and_cancel(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + struct session *s = cs->s; + struct winlink *wl = cs->wl; + struct window_pane *wp = wme->wp; + char *command = NULL; + char *prefix = NULL; + + if (cs->args->argc == 3) + 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); + } + + free(prefix); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_goto_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + const char *argument = cs->args->argv[1]; + + if (*argument != '\0') + window_copy_goto_line(wme, argument); + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_jump_backward(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + const char *argument = cs->args->argv[1]; + + if (*argument != '\0') { + data->jumptype = WINDOW_COPY_JUMPBACKWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump_back(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_jump_forward(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + const char *argument = cs->args->argv[1]; + + if (*argument != '\0') { + data->jumptype = WINDOW_COPY_JUMPFORWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_jump_to_backward(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + const char *argument = cs->args->argv[1]; + + if (*argument != '\0') { + data->jumptype = WINDOW_COPY_JUMPTOBACKWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump_to_back(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_jump_to_forward(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + const char *argument = cs->args->argv[1]; + + if (*argument != '\0') { + data->jumptype = WINDOW_COPY_JUMPTOFORWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump_to(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_search_backward(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + const char *argument = cs->args->argv[1]; + + if (*argument != '\0') { + data->searchtype = WINDOW_COPY_SEARCHUP; + free(data->searchstr); + data->searchstr = xstrdup(argument); + for (; np != 0; np--) + window_copy_search_up(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_search_forward(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix; + const char *argument = cs->args->argv[1]; + + if (*argument != '\0') { + data->searchtype = WINDOW_COPY_SEARCHDOWN; + free(data->searchstr); + data->searchstr = xstrdup(argument); + for (; np != 0; np--) + window_copy_search_down(wme); + } + return (WINDOW_COPY_CMD_NOTHING); +} + +static enum window_copy_cmd_action +window_copy_cmd_search_backward_incremental(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + const char *argument = cs->args->argv[1]; + enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING; + const char *ss = data->searchstr; + + if (data->searchx == -1 || data->searchy == -1) { + data->searchx = data->cx; + data->searchy = data->cy; + data->searcho = data->oy; + } else if (ss != NULL && strcmp(argument, ss) != 0) { + data->cx = data->searchx; + data->cy = data->searchy; + data->oy = data->searcho; + action = WINDOW_COPY_CMD_REDRAW; + } + + if (*argument == '\0') { + window_copy_clear_marks(wme); + return (WINDOW_COPY_CMD_REDRAW); + } + + switch (*argument++) { + case '=': + case '-': + data->searchtype = WINDOW_COPY_SEARCHUP; + free(data->searchstr); + data->searchstr = xstrdup(argument); + if (!window_copy_search_up(wme)) { + window_copy_clear_marks(wme); + return (WINDOW_COPY_CMD_REDRAW); + } + break; + case '+': + data->searchtype = WINDOW_COPY_SEARCHDOWN; + free(data->searchstr); + data->searchstr = xstrdup(argument); + if (!window_copy_search_down(wme)) { + window_copy_clear_marks(wme); + return (WINDOW_COPY_CMD_REDRAW); + } + break; + } + return (action); +} + +static enum window_copy_cmd_action +window_copy_cmd_search_forward_incremental(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + const char *argument = cs->args->argv[1]; + enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING; + const char *ss = data->searchstr; + + if (data->searchx == -1 || data->searchy == -1) { + data->searchx = data->cx; + data->searchy = data->cy; + data->searcho = data->oy; + } else if (ss != NULL && strcmp(argument, ss) != 0) { + data->cx = data->searchx; + data->cy = data->searchy; + data->oy = data->searcho; + action = WINDOW_COPY_CMD_REDRAW; + } + + if (*argument == '\0') { + window_copy_clear_marks(wme); + return (WINDOW_COPY_CMD_REDRAW); + } + + switch (*argument++) { + case '=': + case '+': + data->searchtype = WINDOW_COPY_SEARCHDOWN; + free(data->searchstr); + data->searchstr = xstrdup(argument); + if (!window_copy_search_down(wme)) { + window_copy_clear_marks(wme); + return (WINDOW_COPY_CMD_REDRAW); + } + break; + case '-': + data->searchtype = WINDOW_COPY_SEARCHUP; + free(data->searchstr); + data->searchstr = xstrdup(argument); + if (!window_copy_search_up(wme)) { + window_copy_clear_marks(wme); + return (WINDOW_COPY_CMD_REDRAW); + } + } + return (action); +} + +static const struct { + const char *command; + int minargs; + int maxargs; + enum window_copy_cmd_action (*f)(struct window_copy_cmd_state *); +} window_copy_cmd_table[] = { + { "append-selection", 0, 0, + window_copy_cmd_append_selection }, + { "append-selection-and-cancel", 0, 0, + window_copy_cmd_append_selection_and_cancel }, + { "back-to-indentation", 0, 0, + window_copy_cmd_back_to_indentation }, + { "begin-selection", 0, 0, + window_copy_cmd_begin_selection }, + { "bottom-line", 0, 0, + window_copy_cmd_bottom_line }, + { "cancel", 0, 0, + window_copy_cmd_cancel }, + { "clear-selection", 0, 0, + window_copy_cmd_clear_selection }, + { "copy-end-of-line", 0, 1, + window_copy_cmd_copy_end_of_line }, + { "copy-line", 0, 1, + window_copy_cmd_copy_line }, + { "copy-pipe", 1, 2, + window_copy_cmd_copy_pipe }, + { "copy-pipe-and-cancel", 1, 2, + window_copy_cmd_copy_pipe_and_cancel }, + { "copy-selection", 0, 1, + window_copy_cmd_copy_selection }, + { "copy-selection-and-cancel", 0, 1, + window_copy_cmd_copy_selection_and_cancel }, + { "cursor-down", 0, 0, + window_copy_cmd_cursor_down }, + { "cursor-left", 0, 0, + window_copy_cmd_cursor_left }, + { "cursor-right", 0, 0, + window_copy_cmd_cursor_right }, + { "cursor-up", 0, 0, + window_copy_cmd_cursor_up }, + { "end-of-line", 0, 0, + window_copy_cmd_end_of_line }, + { "goto-line", 1, 1, + window_copy_cmd_goto_line }, + { "halfpage-down", 0, 0, + window_copy_cmd_halfpage_down }, + { "halfpage-down-and-cancel", 0, 0, + window_copy_cmd_halfpage_down_and_cancel }, + { "halfpage-up", 0, 0, + window_copy_cmd_halfpage_up }, + { "history-bottom", 0, 0, + window_copy_cmd_history_bottom }, + { "history-top", 0, 0, + window_copy_cmd_history_top }, + { "jump-again", 0, 0, + window_copy_cmd_jump_again }, + { "jump-backward", 1, 1, + window_copy_cmd_jump_backward }, + { "jump-forward", 1, 1, + window_copy_cmd_jump_forward }, + { "jump-reverse", 0, 0, + window_copy_cmd_jump_reverse }, + { "jump-to-backward", 1, 1, + window_copy_cmd_jump_to_backward }, + { "jump-to-forward", 1, 1, + window_copy_cmd_jump_to_forward }, + { "middle-line", 0, 0, + window_copy_cmd_middle_line }, + { "next-paragraph", 0, 0, + window_copy_cmd_next_paragraph }, + { "next-space", 0, 0, + window_copy_cmd_next_space }, + { "next-space-end", 0, 0, + window_copy_cmd_next_space_end }, + { "next-word", 0, 0, + window_copy_cmd_next_word }, + { "next-word-end", 0, 0, + window_copy_cmd_next_word_end }, + { "other-end", 0, 0, + window_copy_cmd_other_end }, + { "page-down", 0, 0, + window_copy_cmd_page_down }, + { "page-down-and-cancel", 0, 0, + window_copy_cmd_page_down_and_cancel }, + { "page-up", 0, 0, + window_copy_cmd_page_up }, + { "previous-paragraph", 0, 0, + window_copy_cmd_previous_paragraph }, + { "previous-space", 0, 0, + window_copy_cmd_previous_space }, + { "previous-word", 0, 0, + window_copy_cmd_previous_word }, + { "rectangle-toggle", 0, 0, + window_copy_cmd_rectangle_toggle }, + { "scroll-down", 0, 0, + window_copy_cmd_scroll_down }, + { "scroll-down-and-cancel", 0, 0, + window_copy_cmd_scroll_down_and_cancel }, + { "scroll-up", 0, 0, + window_copy_cmd_scroll_up }, + { "search-again", 0, 0, + window_copy_cmd_search_again }, + { "search-backward", 1, 1, + window_copy_cmd_search_backward }, + { "search-backward-incremental", 1, 1, + window_copy_cmd_search_backward_incremental }, + { "search-forward", 1, 1, + window_copy_cmd_search_forward }, + { "search-forward-incremental", 1, 1, + window_copy_cmd_search_forward_incremental }, + { "search-reverse", 0, 0, + window_copy_cmd_search_reverse }, + { "select-line", 0, 0, + window_copy_cmd_select_line }, + { "select-word", 0, 0, + window_copy_cmd_select_word }, + { "start-of-line", 0, 0, + window_copy_cmd_start_of_line }, + { "stop-selection", 0, 0, + window_copy_cmd_stop_selection }, + { "top-line", 0, 0, + window_copy_cmd_top_line }, +}; + static void 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 window_pane *wp = wme->wp; struct window_copy_mode_data *data = wme->data; - struct screen *sn = &data->screen; - const char *command, *argument, *ws; - u_int np = wme->prefix; - int cancel = 0, redraw = 0, scroll_exit; - char prefix; + struct window_copy_cmd_state cs; + enum window_copy_cmd_action action; + const char *command; + u_int i; if (args->argc == 0) return; @@ -585,431 +1660,36 @@ window_copy_command(struct window_mode_entry *wme, struct client *c, if (m != NULL && m->valid && !MOUSE_WHEEL(m->b)) window_copy_move_mouse(m); - if (args->argc == 1) { - if (strcmp(command, "append-selection") == 0) { - if (s != NULL) - window_copy_append_selection(wme); - window_copy_clear_selection(wme); - redraw = 1; - } - if (strcmp(command, "append-selection-and-cancel") == 0) { - if (s != NULL) - window_copy_append_selection(wme); - window_copy_clear_selection(wme); - redraw = 1; - cancel = 1; - } - if (strcmp(command, "back-to-indentation") == 0) - window_copy_cursor_back_to_indentation(wme); - if (strcmp(command, "begin-selection") == 0) { - if (m != NULL) - window_copy_start_drag(c, m); - else { - data->lineflag = LINE_SEL_NONE; - window_copy_start_selection(wme); - redraw = 1; - } - } - if (strcmp(command, "stop-selection") == 0) - data->cursordrag = CURSORDRAG_NONE; - if (strcmp(command, "bottom-line") == 0) { - data->cx = 0; - data->cy = screen_size_y(sn) - 1; - window_copy_update_selection(wme, 1); - redraw = 1; - } - if (strcmp(command, "cancel") == 0) - cancel = 1; - if (strcmp(command, "clear-selection") == 0) { - window_copy_clear_selection(wme); - redraw = 1; - } - if (strcmp(command, "copy-end-of-line") == 0) { - window_copy_start_selection(wme); - for (; np > 1; np--) - window_copy_cursor_down(wme, 0); - window_copy_cursor_end_of_line(wme); - redraw = 1; + cs.wme = wme; + cs.args = args; + cs.m = m; - if (s != NULL) { - window_copy_copy_selection(wme); - cancel = 1; - } - } - if (strcmp(command, "copy-line") == 0) { - window_copy_cursor_start_of_line(wme); - window_copy_start_selection(wme); - for (; np > 1; np--) - window_copy_cursor_down(wme, 0); - window_copy_cursor_end_of_line(wme); - redraw = 1; + cs.c = c; + cs.s = s; + cs.wl = wl; - if (s != NULL) { - window_copy_copy_selection(wme); - cancel = 1; - } - } - if (strcmp(command, "copy-selection") == 0) { - if (s != NULL) - window_copy_copy_selection(wme); - window_copy_clear_selection(wme); - redraw = 1; - } - if (strcmp(command, "copy-selection-and-cancel") == 0) { - if (s != NULL) - window_copy_copy_selection(wme); - window_copy_clear_selection(wme); - redraw = 1; - cancel = 1; - } - if (strcmp(command, "cursor-down") == 0) { - for (; np != 0; np--) - window_copy_cursor_down(wme, 0); - } - if (strcmp(command, "cursor-left") == 0) { - for (; np != 0; np--) - window_copy_cursor_left(wme); - } - if (strcmp(command, "cursor-right") == 0) { - for (; np != 0; np--) - window_copy_cursor_right(wme); - } - if (strcmp(command, "cursor-up") == 0) { - for (; np != 0; np--) - window_copy_cursor_up(wme, 0); - } - if (strcmp(command, "end-of-line") == 0) - window_copy_cursor_end_of_line(wme); - if (strcmp(command, "halfpage-down") == 0 || - strcmp(command, "halfpage-down-and-cancel") == 0) { - if (strcmp(command, "halfpage-down-and-cancel") == 0) - scroll_exit = 1; - else - scroll_exit = data->scroll_exit; - for (; np != 0; np--) { - if (window_copy_pagedown(wme, 1, scroll_exit)) { - cancel = 1; - break; - } - } - } - if (strcmp(command, "halfpage-up") == 0) { - for (; np != 0; np--) - window_copy_pageup1(wme, 1); - } - if (strcmp(command, "history-bottom") == 0) { - data->cx = 0; - data->cy = screen_size_y(sn) - 1; - data->oy = 0; - window_copy_update_selection(wme, 1); - redraw = 1; - } - if (strcmp(command, "history-top") == 0) { - data->cx = 0; - data->cy = 0; - data->oy = screen_hsize(data->backing); - window_copy_update_selection(wme, 1); - redraw = 1; - } - if (strcmp(command, "jump-again") == 0) { - switch (data->jumptype) { - case WINDOW_COPY_JUMPFORWARD: - for (; np != 0; np--) - window_copy_cursor_jump(wme); - break; - case WINDOW_COPY_JUMPBACKWARD: - for (; np != 0; np--) - window_copy_cursor_jump_back(wme); + 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 (args->argc - 1 < window_copy_cmd_table[i].minargs || + args->argc - 1 > window_copy_cmd_table[i].maxargs) break; - case WINDOW_COPY_JUMPTOFORWARD: - for (; np != 0; np--) - window_copy_cursor_jump_to(wme); - break; - case WINDOW_COPY_JUMPTOBACKWARD: - for (; np != 0; np--) - window_copy_cursor_jump_to_back(wme); - break; - } - } - if (strcmp(command, "jump-reverse") == 0) { - switch (data->jumptype) { - case WINDOW_COPY_JUMPFORWARD: - for (; np != 0; np--) - window_copy_cursor_jump_back(wme); - break; - case WINDOW_COPY_JUMPBACKWARD: - for (; np != 0; np--) - window_copy_cursor_jump(wme); - break; - case WINDOW_COPY_JUMPTOFORWARD: - for (; np != 0; np--) - window_copy_cursor_jump_to_back(wme); - break; - case WINDOW_COPY_JUMPTOBACKWARD: - for (; np != 0; np--) - window_copy_cursor_jump_to(wme); - break; - } - } - if (strcmp(command, "middle-line") == 0) { - data->cx = 0; - data->cy = (screen_size_y(sn) - 1) / 2; - window_copy_update_selection(wme, 1); - redraw = 1; - } - if (strcmp(command, "next-paragraph") == 0) { - for (; np != 0; np--) - window_copy_next_paragraph(wme); - } - if (strcmp(command, "next-space") == 0) { - for (; np != 0; np--) - window_copy_cursor_next_word(wme, " "); - } - if (strcmp(command, "next-space-end") == 0) { - for (; np != 0; np--) - window_copy_cursor_next_word_end(wme, " "); - } - if (strcmp(command, "next-word") == 0) { - ws = options_get_string(s->options, "word-separators"); - for (; np != 0; np--) - window_copy_cursor_next_word(wme, ws); - } - if (strcmp(command, "next-word-end") == 0) { - ws = options_get_string(s->options, "word-separators"); - for (; np != 0; np--) - window_copy_cursor_next_word_end(wme, ws); - } - if (strcmp(command, "other-end") == 0) { - if ((np % 2) != 0) - window_copy_other_end(wme); - } - if (strcmp(command, "page-down") == 0 || - strcmp(command, "page-down-and-cancel") == 0) { - if (strcmp(command, "page-down-and-cancel") == 0) - scroll_exit = 1; - else - scroll_exit = data->scroll_exit; - for (; np != 0; np--) { - if (window_copy_pagedown(wme, 0, scroll_exit)) { - cancel = 1; - break; - } - } - } - if (strcmp(command, "page-up") == 0) { - for (; np != 0; np--) - window_copy_pageup1(wme, 0); - } - if (strcmp(command, "previous-paragraph") == 0) { - for (; np != 0; np--) - window_copy_previous_paragraph(wme); - } - if (strcmp(command, "previous-space") == 0) { - for (; np != 0; np--) - window_copy_cursor_previous_word(wme, " "); - } - if (strcmp(command, "previous-word") == 0) { - ws = options_get_string(s->options, "word-separators"); - for (; np != 0; np--) - window_copy_cursor_previous_word(wme, ws); - } - if (strcmp(command, "rectangle-toggle") == 0) { - data->lineflag = LINE_SEL_NONE; - window_copy_rectangle_toggle(wme); - } - if (strcmp(command, "scroll-down") == 0 || - strcmp(command, "scroll-down-and-cancel") == 0) { - if (strcmp(command, "scroll-down-and-cancel") == 0) - scroll_exit = 1; - else - scroll_exit = data->scroll_exit; - for (; np != 0; np--) - window_copy_cursor_down(wme, 1); - if (scroll_exit && data->oy == 0) - cancel = 1; - } - if (strcmp(command, "scroll-up") == 0) { - for (; np != 0; np--) - window_copy_cursor_up(wme, 1); - } - if (strcmp(command, "search-again") == 0) { - if (data->searchtype == WINDOW_COPY_SEARCHUP) { - for (; np != 0; np--) - window_copy_search_up(wme); - } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) { - for (; np != 0; np--) - window_copy_search_down(wme); - } - } - if (strcmp(command, "search-reverse") == 0) { - if (data->searchtype == WINDOW_COPY_SEARCHUP) { - for (; np != 0; np--) - window_copy_search_down(wme); - } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) { - for (; np != 0; np--) - window_copy_search_up(wme); - } - } - if (strcmp(command, "select-line") == 0) { - data->lineflag = LINE_SEL_LEFT_RIGHT; - data->rectflag = 0; - window_copy_cursor_start_of_line(wme); - window_copy_start_selection(wme); - for (; np > 1; np--) - window_copy_cursor_down(wme, 0); - window_copy_cursor_end_of_line(wme); - redraw = 1; - } - if (strcmp(command, "select-word") == 0) { - data->lineflag = LINE_SEL_LEFT_RIGHT; - data->rectflag = 0; - ws = options_get_string(s->options, "word-separators"); - window_copy_cursor_previous_word(wme, ws); - window_copy_start_selection(wme); - window_copy_cursor_next_word_end(wme, ws); - redraw = 1; - } - if (strcmp(command, "start-of-line") == 0) - window_copy_cursor_start_of_line(wme); - if (strcmp(command, "top-line") == 0) { - data->cx = 0; - data->cy = 0; - window_copy_update_selection(wme, 1); - redraw = 1; - } - } else if (args->argc == 2 && *args->argv[1] != '\0') { - argument = args->argv[1]; - if (strcmp(command, "copy-pipe") == 0) { - if (s != NULL) - window_copy_copy_pipe(wme, s, argument); - } - if (strcmp(command, "copy-pipe-and-cancel") == 0) { - if (s != NULL) { - window_copy_copy_pipe(wme, s, argument); - cancel = 1; - } - } - if (strcmp(command, "goto-line") == 0) - window_copy_goto_line(wme, argument); - if (strcmp(command, "jump-backward") == 0) { - data->jumptype = WINDOW_COPY_JUMPBACKWARD; - data->jumpchar = *argument; - for (; np != 0; np--) - window_copy_cursor_jump_back(wme); - } - if (strcmp(command, "jump-forward") == 0) { - data->jumptype = WINDOW_COPY_JUMPFORWARD; - data->jumpchar = *argument; - for (; np != 0; np--) - window_copy_cursor_jump(wme); - } - if (strcmp(command, "jump-to-backward") == 0) { - data->jumptype = WINDOW_COPY_JUMPTOBACKWARD; - data->jumpchar = *argument; - for (; np != 0; np--) - window_copy_cursor_jump_to_back(wme); - } - if (strcmp(command, "jump-to-forward") == 0) { - data->jumptype = WINDOW_COPY_JUMPTOFORWARD; - data->jumpchar = *argument; - for (; np != 0; np--) - window_copy_cursor_jump_to(wme); - } - if (strcmp(command, "search-backward") == 0) { - data->searchtype = WINDOW_COPY_SEARCHUP; - free(data->searchstr); - data->searchstr = xstrdup(argument); - for (; np != 0; np--) - window_copy_search_up(wme); - } - if (strcmp(command, "search-forward") == 0) { - data->searchtype = WINDOW_COPY_SEARCHDOWN; - free(data->searchstr); - data->searchstr = xstrdup(argument); - for (; np != 0; np--) - window_copy_search_down(wme); - } - if (strcmp(command, "search-backward-incremental") == 0) { - prefix = *argument++; - if (data->searchx == -1 || data->searchy == -1) { - data->searchx = data->cx; - data->searchy = data->cy; - data->searcho = data->oy; - } else if (data->searchstr != NULL && - strcmp(argument, data->searchstr) != 0) { - data->cx = data->searchx; - data->cy = data->searchy; - data->oy = data->searcho; - redraw = 1; - } - if (*argument == '\0') { - window_copy_clear_marks(wme); - redraw = 1; - } else if (prefix == '=' || prefix == '-') { - data->searchtype = WINDOW_COPY_SEARCHUP; - free(data->searchstr); - data->searchstr = xstrdup(argument); - if (!window_copy_search_up(wme)) { - window_copy_clear_marks(wme); - redraw = 1; - } - } else if (prefix == '+') { - data->searchtype = WINDOW_COPY_SEARCHDOWN; - free(data->searchstr); - data->searchstr = xstrdup(argument); - if (!window_copy_search_down(wme)) { - window_copy_clear_marks(wme); - redraw = 1; - } - } - } - if (strcmp(command, "search-forward-incremental") == 0) { - prefix = *argument++; - if (data->searchx == -1 || data->searchy == -1) { - data->searchx = data->cx; - data->searchy = data->cy; - data->searcho = data->oy; - } else if (data->searchstr != NULL && - strcmp(argument, data->searchstr) != 0) { - data->cx = data->searchx; - data->cy = data->searchy; - data->oy = data->searcho; - redraw = 1; - } - if (*argument == '\0') { - window_copy_clear_marks(wme); - redraw = 1; - } else if (prefix == '=' || prefix == '+') { - data->searchtype = WINDOW_COPY_SEARCHDOWN; - free(data->searchstr); - data->searchstr = xstrdup(argument); - if (!window_copy_search_down(wme)) { - window_copy_clear_marks(wme); - redraw = 1; - } - } else if (prefix == '-') { - data->searchtype = WINDOW_COPY_SEARCHUP; - free(data->searchstr); - data->searchstr = xstrdup(argument); - if (!window_copy_search_up(wme)) { - window_copy_clear_marks(wme); - redraw = 1; - } - } + action = window_copy_cmd_table[i].f (&cs); + break; } } if (strncmp(command, "search-", 7) != 0 && data->searchmark != NULL) { window_copy_clear_marks(wme); - redraw = 1; + if (action == WINDOW_COPY_CMD_NOTHING) + action = WINDOW_COPY_CMD_REDRAW; data->searchx = data->searchy = -1; } - wme->prefix = 1; - if (cancel) - window_pane_reset_mode(wp); - else if (redraw) + if (action == WINDOW_COPY_CMD_CANCEL) + window_pane_reset_mode(wme->wp); + else if (action == WINDOW_COPY_CMD_REDRAW) window_copy_redraw_screen(wme); } @@ -1721,7 +2401,8 @@ window_copy_get_selection(struct window_mode_entry *wme, size_t *len) } 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 screen_write_ctx ctx; @@ -1733,41 +2414,35 @@ window_copy_copy_buffer(struct window_mode_entry *wme, void *buf, size_t len) notify_pane("pane-set-clipboard", wp); } - if (paste_set(buf, len, NULL, NULL) != 0) - free(buf); + paste_add(prefix, buf, len); } static void 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; - size_t len; - struct job *job; - char *expanded; + void *buf; + size_t len; + struct job *job; buf = window_copy_get_selection(wme, &len); if (buf == NULL) 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); - - free(expanded); - window_copy_copy_buffer(wme, buf, len); + window_copy_copy_buffer(wme, prefix, buf, len); } 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; size_t len; buf = window_copy_get_selection(wme, &len); if (buf != NULL) - window_copy_copy_buffer(wme, buf, len); + window_copy_copy_buffer(wme, prefix, buf, len); } static void |