From 24d7d073fffbf5137176ef474f13f4cfe1f032e9 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 27 Nov 2012 20:08:42 +0000 Subject: [PATCH 1/2] Support the 47 and 1047 SM and RM sequences (alternate screen without cursor), requested by I forget who ages ago. --- input.c | 12 ++++++++++-- tmux.h | 8 ++++---- window.c | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/input.c b/input.c index bc4af1f7..71ef3b00 100644 --- a/input.c +++ b/input.c @@ -1255,8 +1255,12 @@ input_csi_dispatch(struct input_ctx *ictx) case 1005: screen_write_utf8mousemode(&ictx->ctx, 0); break; + case 47: + case 1047: + window_pane_alternate_off(wp, &ictx->cell, 0); + break; case 1049: - window_pane_alternate_off(wp, &ictx->cell); + window_pane_alternate_off(wp, &ictx->cell, 1); break; case 2004: screen_write_bracketpaste(&ictx->ctx, 0); @@ -1310,8 +1314,12 @@ input_csi_dispatch(struct input_ctx *ictx) case 1005: screen_write_utf8mousemode(&ictx->ctx, 1); break; + case 47: + case 1047: + window_pane_alternate_on(wp, &ictx->cell, 0); + break; case 1049: - window_pane_alternate_on(wp, &ictx->cell); + window_pane_alternate_on(wp, &ictx->cell, 1); break; case 2004: screen_write_bracketpaste(&ictx->ctx, 1); diff --git a/tmux.h b/tmux.h index 2b5f19d8..8549e142 100644 --- a/tmux.h +++ b/tmux.h @@ -2145,10 +2145,10 @@ int window_pane_spawn(struct window_pane *, const char *, const char *, const char *, struct environ *, struct termios *, char **); void window_pane_resize(struct window_pane *, u_int, u_int); -void window_pane_alternate_on( - struct window_pane *, struct grid_cell *); -void window_pane_alternate_off( - struct window_pane *, struct grid_cell *); +void window_pane_alternate_on(struct window_pane *, + struct grid_cell *, int); +void window_pane_alternate_off(struct window_pane *, + struct grid_cell *, int); int window_pane_set_mode( struct window_pane *, const struct window_mode *); void window_pane_reset_mode(struct window_pane *); diff --git a/window.c b/window.c index fc9fa5f3..97e5b4a3 100644 --- a/window.c +++ b/window.c @@ -867,7 +867,8 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) * history is not updated */ void -window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc) +window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc, + int cursor) { struct screen *s = &wp->base; u_int sx, sy; @@ -881,8 +882,10 @@ window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc) wp->saved_grid = grid_create(sx, sy, 0); grid_duplicate_lines(wp->saved_grid, 0, s->grid, screen_hsize(s), sy); - wp->saved_cx = s->cx; - wp->saved_cy = s->cy; + if (cursor) { + wp->saved_cx = s->cx; + wp->saved_cy = s->cy; + } memcpy(&wp->saved_cell, gc, sizeof wp->saved_cell); grid_view_clear(s->grid, 0, 0, sx, sy); @@ -894,7 +897,8 @@ window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc) /* Exit alternate screen mode and restore the copied grid. */ void -window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc) +window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc, + int cursor) { struct screen *s = &wp->base; u_int sx, sy; @@ -915,10 +919,12 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc) /* Restore the grid, cursor position and cell. */ grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy); - s->cx = wp->saved_cx; + if (cursor) + s->cx = wp->saved_cx; if (s->cx > screen_size_x(s) - 1) s->cx = screen_size_x(s) - 1; - s->cy = wp->saved_cy; + if (cursor) + s->cy = wp->saved_cy; if (s->cy > screen_size_y(s) - 1) s->cy = screen_size_y(s) - 1; memcpy(gc, &wp->saved_cell, sizeof *gc); From 47c097cb51da9622180963af5391d142e7d4ade3 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 27 Nov 2012 20:22:12 +0000 Subject: [PATCH 2/2] Support middle-click paste, based on a diff from Ailin Nemui. --- cmd-paste-buffer.c | 34 +++------------------------------- input-keys.c | 15 +++++++++++---- paste.c | 26 ++++++++++++++++++++++++++ tmux.h | 9 ++++++--- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c index 9bf27fcd..06402ebb 100644 --- a/cmd-paste-buffer.c +++ b/cmd-paste-buffer.c @@ -31,7 +31,7 @@ enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *); void cmd_paste_buffer_filter(struct window_pane *, - const char *, size_t, const char *, int bracket); + const char *, size_t, const char *, int); const struct cmd_entry cmd_paste_buffer_entry = { "paste-buffer", "pasteb", @@ -87,9 +87,8 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) else sepstr = "\r"; } - pflag = args_has(args, 'p') && - (wp->screen->mode & MODE_BRACKETPASTE); - cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr, pflag); + pflag = (wp->screen->mode & MODE_BRACKETPASTE); + paste_send_pane(pb, wp, sepstr, args_has(args, 'p') && pflag); } /* Delete the buffer if -d. */ @@ -102,30 +101,3 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) return (CMD_RETURN_NORMAL); } - -/* Add bytes to a buffer and filter '\n' according to separator. */ -void -cmd_paste_buffer_filter(struct window_pane *wp, - const char *data, size_t size, const char *sep, int bracket) -{ - const char *end = data + size; - const char *lf; - size_t seplen; - - if (bracket) - bufferevent_write(wp->event, "\033[200~", 6); - - seplen = strlen(sep); - while ((lf = memchr(data, '\n', end - data)) != NULL) { - if (lf != data) - bufferevent_write(wp->event, data, lf - data); - bufferevent_write(wp->event, sep, seplen); - data = lf + 1; - } - - if (end != data) - bufferevent_write(wp->event, data, end - data); - - if (bracket) - bufferevent_write(wp->event, "\033[201~", 6); -} diff --git a/input-keys.c b/input-keys.c index eee469e8..2111f5f3 100644 --- a/input-keys.c +++ b/input-keys.c @@ -202,8 +202,9 @@ input_key(struct window_pane *wp, int key) void input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m) { - char buf[10]; - size_t len; + char buf[10]; + size_t len; + struct paste_buffer *pb; if (wp->screen->mode & ALL_MOUSE_MODES) { if (wp->screen->mode & MODE_MOUSE_UTF8) { @@ -223,13 +224,19 @@ input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m) return; } - if ((m->xb & 3) != 1 && + if (m->button == 1 && (m->event & MOUSE_EVENT_CLICK) && + options_get_number(&wp->window->options, "mode-mouse") == 1) { + pb = paste_get_top(&global_buffers); + if (pb != NULL) { + paste_send_pane(pb, wp, "\r", + wp->screen->mode & MODE_BRACKETPASTE); + } + } else if ((m->xb & 3) != 1 && options_get_number(&wp->window->options, "mode-mouse") == 1) { if (window_pane_set_mode(wp, &window_copy_mode) == 0) { window_copy_init_from_pane(wp); if (wp->mode->mouse != NULL) wp->mode->mouse(wp, s, m); } - return; } } diff --git a/paste.c b/paste.c index 886231a2..2e89a5ef 100644 --- a/paste.c +++ b/paste.c @@ -167,3 +167,29 @@ paste_print(struct paste_buffer *pb, size_t width) return (buf); } + +/* Paste into a window pane, filtering '\n' according to separator. */ +void +paste_send_pane (struct paste_buffer *pb, struct window_pane *wp, + const char *sep, int bracket) +{ + const char *data = pb->data, *end = data + pb->size, *lf; + size_t seplen; + + if (bracket) + bufferevent_write(wp->event, "\033[200~", 6); + + seplen = strlen(sep); + while ((lf = memchr(data, '\n', end - data)) != NULL) { + if (lf != data) + bufferevent_write(wp->event, data, lf - data); + bufferevent_write(wp->event, sep, seplen); + data = lf + 1; + } + + if (end != data) + bufferevent_write(wp->event, data, end - data); + + if (bracket) + bufferevent_write(wp->event, "\033[201~", 6); +} diff --git a/tmux.h b/tmux.h index 8549e142..981d4f21 100644 --- a/tmux.h +++ b/tmux.h @@ -1682,8 +1682,8 @@ const char *tty_term_string2( struct tty_term *, enum tty_code_code, int, int); const char *tty_term_ptr1( struct tty_term *, enum tty_code_code, const void *); -const char *tty_term_ptr2( - struct tty_term *, enum tty_code_code, const void *, const void *); +const char *tty_term_ptr2(struct tty_term *, enum tty_code_code, + const void *, const void *); int tty_term_number(struct tty_term *, enum tty_code_code); int tty_term_flag(struct tty_term *, enum tty_code_code); @@ -1704,6 +1704,9 @@ int paste_free_index(struct paste_stack *, u_int); void paste_add(struct paste_stack *, char *, size_t, u_int); int paste_replace(struct paste_stack *, u_int, char *, size_t); char *paste_print(struct paste_buffer *, size_t); +void paste_send_pane(struct paste_buffer *, struct window_pane *, + const char *, int); + /* clock.c */ extern const char clock_table[14][5][5]; @@ -1906,7 +1909,7 @@ void server_unlink_window(struct session *, struct winlink *); void server_destroy_pane(struct window_pane *); void server_destroy_session_group(struct session *); void server_destroy_session(struct session *); -void server_check_unattached (void); +void server_check_unattached(void); void server_set_identify(struct client *); void server_clear_identify(struct client *); void server_update_event(struct client *);