Merge branch 'obsd-master'

Sync from OpenBSD.
This commit is contained in:
Thomas Adam 2012-11-27 22:24:00 +00:00
commit 739a76634c
6 changed files with 72 additions and 50 deletions

View File

@ -30,7 +30,7 @@
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *); enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
void cmd_paste_buffer_filter(struct window_pane *, 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 = { const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "pasteb", "paste-buffer", "pasteb",
@ -86,9 +86,8 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
else else
sepstr = "\r"; sepstr = "\r";
} }
pflag = args_has(args, 'p') && pflag = (wp->screen->mode & MODE_BRACKETPASTE);
(wp->screen->mode & MODE_BRACKETPASTE); paste_send_pane(pb, wp, sepstr, args_has(args, 'p') && pflag);
cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr, pflag);
} }
/* Delete the buffer if -d. */ /* Delete the buffer if -d. */
@ -101,30 +100,3 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_NORMAL); 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);
}

View File

@ -201,8 +201,9 @@ input_key(struct window_pane *wp, int key)
void void
input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m) input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
{ {
char buf[10]; char buf[10];
size_t len; size_t len;
struct paste_buffer *pb;
if (wp->screen->mode & ALL_MOUSE_MODES) { if (wp->screen->mode & ALL_MOUSE_MODES) {
if (wp->screen->mode & MODE_MOUSE_UTF8) { if (wp->screen->mode & MODE_MOUSE_UTF8) {
@ -222,13 +223,19 @@ input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
return; 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) { options_get_number(&wp->window->options, "mode-mouse") == 1) {
if (window_pane_set_mode(wp, &window_copy_mode) == 0) { if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
window_copy_init_from_pane(wp); window_copy_init_from_pane(wp);
if (wp->mode->mouse != NULL) if (wp->mode->mouse != NULL)
wp->mode->mouse(wp, s, m); wp->mode->mouse(wp, s, m);
} }
return;
} }
} }

12
input.c
View File

@ -1255,8 +1255,12 @@ input_csi_dispatch(struct input_ctx *ictx)
case 1005: case 1005:
screen_write_utf8mousemode(&ictx->ctx, 0); screen_write_utf8mousemode(&ictx->ctx, 0);
break; break;
case 47:
case 1047:
window_pane_alternate_off(wp, &ictx->cell, 0);
break;
case 1049: case 1049:
window_pane_alternate_off(wp, &ictx->cell); window_pane_alternate_off(wp, &ictx->cell, 1);
break; break;
case 2004: case 2004:
screen_write_bracketpaste(&ictx->ctx, 0); screen_write_bracketpaste(&ictx->ctx, 0);
@ -1310,8 +1314,12 @@ input_csi_dispatch(struct input_ctx *ictx)
case 1005: case 1005:
screen_write_utf8mousemode(&ictx->ctx, 1); screen_write_utf8mousemode(&ictx->ctx, 1);
break; break;
case 47:
case 1047:
window_pane_alternate_on(wp, &ictx->cell, 0);
break;
case 1049: case 1049:
window_pane_alternate_on(wp, &ictx->cell); window_pane_alternate_on(wp, &ictx->cell, 1);
break; break;
case 2004: case 2004:
screen_write_bracketpaste(&ictx->ctx, 1); screen_write_bracketpaste(&ictx->ctx, 1);

26
paste.c
View File

@ -166,3 +166,29 @@ paste_print(struct paste_buffer *pb, size_t width)
return (buf); 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);
}

17
tmux.h
View File

@ -1678,8 +1678,8 @@ const char *tty_term_string2(
struct tty_term *, enum tty_code_code, int, int); struct tty_term *, enum tty_code_code, int, int);
const char *tty_term_ptr1( const char *tty_term_ptr1(
struct tty_term *, enum tty_code_code, const void *); struct tty_term *, enum tty_code_code, const void *);
const char *tty_term_ptr2( const char *tty_term_ptr2(struct tty_term *, enum tty_code_code,
struct tty_term *, enum tty_code_code, const void *, const void *); const void *, const void *);
int tty_term_number(struct tty_term *, enum tty_code_code); int tty_term_number(struct tty_term *, enum tty_code_code);
int tty_term_flag(struct tty_term *, enum tty_code_code); int tty_term_flag(struct tty_term *, enum tty_code_code);
@ -1700,6 +1700,9 @@ int paste_free_index(struct paste_stack *, u_int);
void paste_add(struct paste_stack *, char *, size_t, u_int); void paste_add(struct paste_stack *, char *, size_t, u_int);
int paste_replace(struct paste_stack *, u_int, char *, size_t); int paste_replace(struct paste_stack *, u_int, char *, size_t);
char *paste_print(struct paste_buffer *, 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 */ /* clock.c */
extern const char clock_table[14][5][5]; extern const char clock_table[14][5][5];
@ -1902,7 +1905,7 @@ void server_unlink_window(struct session *, struct winlink *);
void server_destroy_pane(struct window_pane *); void server_destroy_pane(struct window_pane *);
void server_destroy_session_group(struct session *); void server_destroy_session_group(struct session *);
void server_destroy_session(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_set_identify(struct client *);
void server_clear_identify(struct client *); void server_clear_identify(struct client *);
void server_update_event(struct client *); void server_update_event(struct client *);
@ -2141,10 +2144,10 @@ int window_pane_spawn(struct window_pane *, const char *,
const char *, const char *, struct environ *, const char *, const char *, struct environ *,
struct termios *, char **); struct termios *, char **);
void window_pane_resize(struct window_pane *, u_int, u_int); void window_pane_resize(struct window_pane *, u_int, u_int);
void window_pane_alternate_on( void window_pane_alternate_on(struct window_pane *,
struct window_pane *, struct grid_cell *); struct grid_cell *, int);
void window_pane_alternate_off( void window_pane_alternate_off(struct window_pane *,
struct window_pane *, struct grid_cell *); struct grid_cell *, int);
int window_pane_set_mode( int window_pane_set_mode(
struct window_pane *, const struct window_mode *); struct window_pane *, const struct window_mode *);
void window_pane_reset_mode(struct window_pane *); void window_pane_reset_mode(struct window_pane *);

View File

@ -877,7 +877,8 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
* history is not updated * history is not updated
*/ */
void 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; struct screen *s = &wp->base;
u_int sx, sy; u_int sx, sy;
@ -891,8 +892,10 @@ window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc)
wp->saved_grid = grid_create(sx, sy, 0); wp->saved_grid = grid_create(sx, sy, 0);
grid_duplicate_lines(wp->saved_grid, 0, s->grid, screen_hsize(s), sy); grid_duplicate_lines(wp->saved_grid, 0, s->grid, screen_hsize(s), sy);
wp->saved_cx = s->cx; if (cursor) {
wp->saved_cy = s->cy; wp->saved_cx = s->cx;
wp->saved_cy = s->cy;
}
memcpy(&wp->saved_cell, gc, sizeof wp->saved_cell); memcpy(&wp->saved_cell, gc, sizeof wp->saved_cell);
grid_view_clear(s->grid, 0, 0, sx, sy); grid_view_clear(s->grid, 0, 0, sx, sy);
@ -904,7 +907,8 @@ window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc)
/* Exit alternate screen mode and restore the copied grid. */ /* Exit alternate screen mode and restore the copied grid. */
void 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; struct screen *s = &wp->base;
u_int sx, sy; u_int sx, sy;
@ -925,10 +929,12 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc)
/* Restore the grid, cursor position and cell. */ /* Restore the grid, cursor position and cell. */
grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy); 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) if (s->cx > screen_size_x(s) - 1)
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) if (s->cy > screen_size_y(s) - 1)
s->cy = screen_size_y(s) - 1; s->cy = screen_size_y(s) - 1;
memcpy(gc, &wp->saved_cell, sizeof *gc); memcpy(gc, &wp->saved_cell, sizeof *gc);