1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Synchronize copy-mode

This commit is contained in:
Nicolas Viennot 2013-06-12 22:38:41 -04:00
parent fc4eaeb89f
commit edd194c23c
6 changed files with 126 additions and 67 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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 */

64
tmux.h
View File

@ -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 *);

View File

@ -22,6 +22,7 @@
#include <string.h>
#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)
{

View File

@ -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