From edd194c23cb965eb1cce38907e3b57ea3faeb299 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Wed, 12 Jun 2013 22:38:41 -0400 Subject: [PATCH] Synchronize copy-mode --- tmate-decoder.c | 1 - tmate-encoder.c | 36 ++++++++++++++++++++ tmate.h | 2 ++ tmux.h | 64 +++++++++++++++++++++++++++++++++++ window-copy.c | 88 +++++++++++++------------------------------------ window.c | 2 ++ 6 files changed, 126 insertions(+), 67 deletions(-) diff --git a/tmate-decoder.c b/tmate-decoder.c index 0bdca7d4..e18e6184 100644 --- a/tmate-decoder.c +++ b/tmate-decoder.c @@ -153,7 +153,6 @@ static void handle_message(msgpack_object obj) { struct tmate_unpacker _uk; struct tmate_unpacker *uk = &_uk; - int cmd; init_unpacker(uk, obj); diff --git a/tmate-encoder.c b/tmate-encoder.c index 0e4a2c09..7cd11dbb 100644 --- a/tmate-encoder.c +++ b/tmate-encoder.c @@ -180,3 +180,39 @@ void tmate_status(const char *left, const char *right) old_left = xstrdup(left); old_right = xstrdup(right); } + +void tmate_sync_copy_mode(struct window_pane *wp) +{ + struct window_copy_mode_data *data = wp->modedata; + + pack(array, 3); + pack(int, TMATE_SYNC_COPY_MODE); + + pack(int, wp->id); + + if (wp->mode != &window_copy_mode) { + pack(array, 0); + return; + } + pack(array, 5); + + pack(int, data->oy); + pack(int, data->cx); + pack(int, data->cy); + + if (data->screen.sel.flag) { + pack(array, 3); + pack(int, data->selx); + pack(int, data->sely); + pack(int, data->rectflag); + } else + pack(array, 0); + + if (data->inputprompt) { + pack(array, 3); + pack(int, data->inputtype); + pack(string, data->inputprompt); + pack(string, data->inputstr); + } else + pack(array, 0); +} diff --git a/tmate.h b/tmate.h index 0ff4cd23..9030c90e 100644 --- a/tmate.h +++ b/tmate.h @@ -25,6 +25,7 @@ enum tmate_commands { TMATE_EXEC_CMD, TMATE_FAILED_CMD, TMATE_STATUS, + TMATE_SYNC_COPY_MODE, }; struct tmate_encoder { @@ -42,6 +43,7 @@ extern int tmate_should_replicate_cmd(const struct cmd_entry *cmd); extern void tmate_exec_cmd(const char *cmd); extern void tmate_failed_cmd(int client_id, const char *cause); extern void tmate_status(const char *left, const char *right); +extern void tmate_sync_copy_mode(struct window_pane *wp); /* tmate-decoder.c */ diff --git a/tmux.h b/tmux.h index 7a3cbb3e..c28cb9d9 100644 --- a/tmux.h +++ b/tmux.h @@ -2235,6 +2235,70 @@ void layout_set_active_changed(struct window *); extern const struct window_mode window_clock_mode; /* window-copy.c */ +enum window_copy_input_type { + WINDOW_COPY_OFF, + WINDOW_COPY_NUMERICPREFIX, + WINDOW_COPY_SEARCHUP, + WINDOW_COPY_SEARCHDOWN, + WINDOW_COPY_JUMPFORWARD, + WINDOW_COPY_JUMPBACK, + WINDOW_COPY_JUMPTOFORWARD, + WINDOW_COPY_JUMPTOBACK, + WINDOW_COPY_GOTOLINE, +}; + +/* + * 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 the "copy-mode" command, to copy the contents of + * the current pane), or else a series of lines containing the output + * from an output-writing tmux command (such as any of the "show-*" or + * "list-*" commands). + * + * In either case, the full content of the copy-mode grid is pointed at + * by the "backing" field, and is copied into "screen" as needed (that + * is, when scrolling occurs). When copy-mode is backed by a pane, + * backing points directly at that pane's screen structure (&wp->base); + * when backed by a list of output-lines from a command, it points at + * a newly-allocated screen structure (which is deallocated when the + * mode ends). + */ +struct window_copy_mode_data { + struct screen screen; + + struct screen *backing; + int backing_written; /* backing display has started */ + + struct mode_key_data mdata; + + u_int oy; + + u_int selx; + u_int sely; + + u_int rectflag; /* are we in rectangle copy mode? */ + + u_int cx; + u_int cy; + + u_int lastcx; /* position in last line with content */ + u_int lastsx; /* size of last line with content */ + + enum window_copy_input_type inputtype; + const char *inputprompt; + char *inputstr; + + int numprefix; + + enum window_copy_input_type searchtype; + char *searchstr; + + enum window_copy_input_type jumptype; + char jumpchar; +}; + + + extern const struct window_mode window_copy_mode; void window_copy_init_from_pane(struct window_pane *); void window_copy_init_for_output(struct window_pane *); diff --git a/window-copy.c b/window-copy.c index 51a8f108..b19f77b5 100644 --- a/window-copy.c +++ b/window-copy.c @@ -22,6 +22,7 @@ #include #include "tmux.h" +#include "tmate.h" struct screen *window_copy_init(struct window_pane *); void window_copy_free(struct window_pane *); @@ -89,68 +90,6 @@ const struct window_mode window_copy_mode = { NULL, }; -enum window_copy_input_type { - WINDOW_COPY_OFF, - WINDOW_COPY_NUMERICPREFIX, - WINDOW_COPY_SEARCHUP, - WINDOW_COPY_SEARCHDOWN, - WINDOW_COPY_JUMPFORWARD, - WINDOW_COPY_JUMPBACK, - WINDOW_COPY_JUMPTOFORWARD, - WINDOW_COPY_JUMPTOBACK, - WINDOW_COPY_GOTOLINE, -}; - -/* - * 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 the "copy-mode" command, to copy the contents of - * the current pane), or else a series of lines containing the output - * from an output-writing tmux command (such as any of the "show-*" or - * "list-*" commands). - * - * In either case, the full content of the copy-mode grid is pointed at - * by the "backing" field, and is copied into "screen" as needed (that - * is, when scrolling occurs). When copy-mode is backed by a pane, - * backing points directly at that pane's screen structure (&wp->base); - * when backed by a list of output-lines from a command, it points at - * a newly-allocated screen structure (which is deallocated when the - * mode ends). - */ -struct window_copy_mode_data { - struct screen screen; - - struct screen *backing; - int backing_written; /* backing display has started */ - - struct mode_key_data mdata; - - u_int oy; - - u_int selx; - u_int sely; - - u_int rectflag; /* are we in rectangle copy mode? */ - - u_int cx; - u_int cy; - - u_int lastcx; /* position in last line with content */ - u_int lastsx; /* size of last line with content */ - - enum window_copy_input_type inputtype; - const char *inputprompt; - char *inputstr; - - int numprefix; - - enum window_copy_input_type searchtype; - char *searchstr; - - enum window_copy_input_type jumptype; - char jumpchar; -}; - struct screen * window_copy_init(struct window_pane *wp) { @@ -223,6 +162,8 @@ window_copy_init_from_pane(struct window_pane *wp) window_copy_write_line(wp, &ctx, i); screen_write_cursormove(&ctx, data->cx, data->cy); screen_write_stop(&ctx); + + tmate_sync_copy_mode(wp); } void @@ -359,8 +300,8 @@ window_copy_resize(struct window_pane *wp, u_int sx, u_int sy) window_copy_redraw_screen(wp); } -void -window_copy_key(struct window_pane *wp, struct session *sess, int key) +static void +__window_copy_key(struct window_pane *wp, struct session *sess, int key) { const char *word_separators; struct window_copy_mode_data *data = wp->modedata; @@ -739,6 +680,13 @@ input_off: window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); } +void +window_copy_key(struct window_pane *wp, struct session *sess, int key) +{ + __window_copy_key(wp, sess, key); + tmate_sync_copy_mode(wp); +} + int window_copy_key_input(struct window_pane *wp, int key) { @@ -826,8 +774,8 @@ window_copy_key_numeric_prefix(struct window_pane *wp, int key) return (0); } -void -window_copy_mouse( +static void +__window_copy_mouse( struct window_pane *wp, struct session *sess, struct mouse_event *m) { struct window_copy_mode_data *data = wp->modedata; @@ -888,6 +836,14 @@ reset_mode: } } +void +window_copy_mouse( + struct window_pane *wp, struct session *sess, struct mouse_event *m) +{ + __window_copy_mouse(wp, sess, m); + tmate_sync_copy_mode(wp); +} + void window_copy_scroll_to(struct window_pane *wp, u_int px, u_int py) { diff --git a/window.c b/window.c index 2108e001..5757cf88 100644 --- a/window.c +++ b/window.c @@ -1045,6 +1045,8 @@ window_pane_reset_mode(struct window_pane *wp) wp->screen = &wp->base; wp->flags |= PANE_REDRAW; + + tmate_sync_copy_mode(wp); } void