From a7c55074643b06041f24aabf9fcec827ae4906b7 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Sun, 27 Mar 2016 00:30:20 -0400 Subject: [PATCH] snapshot --- tmate-encoder.c | 46 ++++++++++++++++++++++++++++------------------ tmate.h | 2 +- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/tmate-encoder.c b/tmate-encoder.c index 4155237b..10c9e8c8 100644 --- a/tmate-encoder.c +++ b/tmate-encoder.c @@ -2,7 +2,7 @@ #include "tmate-protocol.h" #include "window-copy.h" -#define pack(what, ...) _pack(&tmate_session.encoder, what, __VA_ARGS__) +#define pack(what, ...) _pack(&tmate_session.encoder, what, ##__VA_ARGS__) void tmate_write_header(void) { @@ -237,29 +237,14 @@ void tmate_write_fin(void) pack(int, TMATE_OUT_FIN); } -static void do_snapshot(unsigned int max_history_lines, - struct window_pane *pane) +static void do_snapshot_grid(struct grid *grid, unsigned int max_history_lines) { - struct screen *screen; - struct grid *grid; struct grid_line *line; struct grid_cell gc; unsigned int line_i, i; unsigned int max_lines; size_t str_len; - screen = &pane->base; - grid = screen->grid; - - pack(array, 4); - pack(int, pane->id); - - pack(array, 2); - pack(int, screen->cx); - pack(int, screen->cy); - - pack(unsigned_int, screen->mode); - max_lines = max_history_lines + grid->sy; #define grid_num_lines(grid) (grid->hsize + grid->sy) @@ -295,6 +280,31 @@ static void do_snapshot(unsigned int max_history_lines, gc.fg )); } } + +} + +static void do_snapshot_pane(struct window_pane *wp, unsigned int max_history_lines) +{ + struct screen *screen = &wp->base; + + pack(array, 4); + pack(int, wp->id); + + pack(unsigned_int, screen->mode); + + pack(array, 3); + pack(int, screen->cx); + pack(int, screen->cy); + do_snapshot_grid(screen->grid, max_history_lines); + + if (wp->saved_grid) { + pack(array, 3); + pack(int, wp->saved_cx); + pack(int, wp->saved_cy); + do_snapshot_grid(wp->saved_grid, max_history_lines); + } else { + pack(nil); + } } static void tmate_send_session_snapshot(unsigned int max_history_lines) @@ -329,7 +339,7 @@ static void tmate_send_session_snapshot(unsigned int max_history_lines) continue; TAILQ_FOREACH(pane, &w->panes, entry) - do_snapshot(max_history_lines, pane); + do_snapshot_pane(pane, max_history_lines); } } diff --git a/tmate.h b/tmate.h index 5e799e7e..0dca56f9 100644 --- a/tmate.h +++ b/tmate.h @@ -38,7 +38,7 @@ extern void tmate_encoder_set_ready_callback(struct tmate_encoder *encoder, extern void msgpack_pack_string(msgpack_packer *pk, const char *str); extern void msgpack_pack_boolean(msgpack_packer *pk, bool value); -#define _pack(enc, what, ...) msgpack_pack_##what(&(enc)->pk, __VA_ARGS__) +#define _pack(enc, what, ...) msgpack_pack_##what(&(enc)->pk, ##__VA_ARGS__) struct tmate_unpacker; struct tmate_decoder;