Move input parser structs into input.c (removing fairly useless

saved_cursor_[xy] formats as a side-effect).
pull/1/head
nicm 2015-05-08 16:18:04 +00:00
parent 879de25583
commit c4a4bd6ac5
6 changed files with 100 additions and 83 deletions

View File

@ -57,15 +57,17 @@ char *
cmd_capture_pane_pending(struct args *args, struct window_pane *wp, cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
size_t *len) size_t *len)
{ {
char *buf, *line, tmp[5]; struct evbuffer *pending;
size_t linelen; char *buf, *line, tmp[5];
u_int i; size_t linelen;
u_int i;
if (wp->ictx.since_ground == NULL) pending = input_pending(wp);
if (pending == NULL)
return (xstrdup("")); return (xstrdup(""));
line = EVBUFFER_DATA(wp->ictx.since_ground); line = EVBUFFER_DATA(pending);
linelen = EVBUFFER_LENGTH(wp->ictx.since_ground); linelen = EVBUFFER_LENGTH(pending);
buf = xstrdup(""); buf = xstrdup("");
if (args_has(args, 'C')) { if (args_has(args, 'C')) {

View File

@ -52,7 +52,6 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
struct mouse_event *m = &cmdq->item->mouse; struct mouse_event *m = &cmdq->item->mouse;
struct window_pane *wp; struct window_pane *wp;
struct session *s; struct session *s;
struct input_ctx *ictx;
const u_char *str; const u_char *str;
int i, key; int i, key;
@ -78,21 +77,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (args_has(args, 'R')) { if (args_has(args, 'R'))
ictx = &wp->ictx; input_reset(wp);
memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell);
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
ictx->old_cx = 0;
ictx->old_cy = 0;
if (wp->mode == NULL)
screen_write_start(&ictx->ctx, wp, &wp->base);
else
screen_write_start(&ictx->ctx, NULL, &wp->base);
screen_write_reset(&ictx->ctx);
screen_write_stop(&ictx->ctx);
}
for (i = 0; i < args->argc; i++) { for (i = 0; i < args->argc; i++) {
str = args->argv[i]; str = args->argv[i];

View File

@ -715,8 +715,6 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "cursor_y", "%u", wp->base.cy); format_add(ft, "cursor_y", "%u", wp->base.cy);
format_add(ft, "scroll_region_upper", "%u", wp->base.rupper); format_add(ft, "scroll_region_upper", "%u", wp->base.rupper);
format_add(ft, "scroll_region_lower", "%u", wp->base.rlower); format_add(ft, "scroll_region_lower", "%u", wp->base.rlower);
format_add(ft, "saved_cursor_x", "%u", wp->ictx.old_cx);
format_add(ft, "saved_cursor_y", "%u", wp->ictx.old_cy);
format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0); format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
format_add(ft, "alternate_saved_x", "%u", wp->saved_cx); format_add(ft, "alternate_saved_x", "%u", wp->saved_cx);

93
input.c
View File

@ -46,6 +46,55 @@
* be passed to the underlying teminal(s). * be passed to the underlying teminal(s).
*/ */
/* Input parser cell. */
struct input_cell {
struct grid_cell cell;
int set;
int g0set; /* 1 if ACS */
int g1set; /* 1 if ACS */
};
/* Input parser context. */
struct input_ctx {
struct window_pane *wp;
struct screen_write_ctx ctx;
struct input_cell cell;
struct input_cell old_cell;
u_int old_cx;
u_int old_cy;
u_char interm_buf[4];
size_t interm_len;
u_char param_buf[64];
size_t param_len;
#define INPUT_BUF_START 32
#define INPUT_BUF_LIMIT 1048576
u_char *input_buf;
size_t input_len;
size_t input_space;
int param_list[24]; /* -1 not present */
u_int param_list_len;
struct utf8_data utf8data;
int ch;
int flags;
#define INPUT_DISCARD 0x1
const struct input_state *state;
/*
* All input received since we were last in the ground state. Sent to
* control clients on connection.
*/
struct evbuffer *since_ground;
};
/* Helper functions. */ /* Helper functions. */
struct input_transition; struct input_transition;
int input_split(struct input_ctx *); int input_split(struct input_ctx *);
@ -706,7 +755,9 @@ input_reset_cell(struct input_ctx *ictx)
void void
input_init(struct window_pane *wp) input_init(struct window_pane *wp)
{ {
struct input_ctx *ictx = &wp->ictx; struct input_ctx *ictx;
ictx = wp->ictx = xcalloc(1, sizeof *ictx);
input_reset_cell(ictx); input_reset_cell(ictx);
@ -732,18 +783,46 @@ input_init(struct window_pane *wp)
void void
input_free(struct window_pane *wp) input_free(struct window_pane *wp)
{ {
if (wp == NULL) struct input_ctx *ictx = wp->ictx;
return;
free(wp->ictx.input_buf); free(ictx->input_buf);
evbuffer_free(wp->ictx.since_ground); evbuffer_free(ictx->since_ground);
free (ictx);
wp->ictx = NULL;
}
/* Reset input state and clear screen. */
void
input_reset(struct window_pane *wp)
{
struct input_ctx *ictx = wp->ictx;
memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell);
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
ictx->old_cx = 0;
ictx->old_cy = 0;
if (wp->mode == NULL)
screen_write_start(&ictx->ctx, wp, &wp->base);
else
screen_write_start(&ictx->ctx, NULL, &wp->base);
screen_write_reset(&ictx->ctx);
screen_write_stop(&ictx->ctx);
}
/* Return pending data. */
struct evbuffer *
input_pending(struct window_pane *wp)
{
return (wp->ictx->since_ground);
} }
/* Change input state. */ /* Change input state. */
void void
input_set_state(struct window_pane *wp, const struct input_transition *itr) input_set_state(struct window_pane *wp, const struct input_transition *itr)
{ {
struct input_ctx *ictx = &wp->ictx; struct input_ctx *ictx = wp->ictx;
if (ictx->state->exit != NULL) if (ictx->state->exit != NULL)
ictx->state->exit(ictx); ictx->state->exit(ictx);
@ -756,7 +835,7 @@ input_set_state(struct window_pane *wp, const struct input_transition *itr)
void void
input_parse(struct window_pane *wp) input_parse(struct window_pane *wp)
{ {
struct input_ctx *ictx = &wp->ictx; struct input_ctx *ictx = wp->ictx;
const struct input_transition *itr; const struct input_transition *itr;
struct evbuffer *evb = wp->event->input; struct evbuffer *evb = wp->event->input;
u_char *buf; u_char *buf;

2
tmux.1
View File

@ -3318,8 +3318,6 @@ The following variables are available, where appropriate:
.It Li "pane_top" Ta "" Ta "Top of pane" .It Li "pane_top" Ta "" Ta "Top of pane"
.It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane" .It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane"
.It Li "pane_width" Ta "" Ta "Width of pane" .It Li "pane_width" Ta "" Ta "Width of pane"
.It Li "saved_cursor_x" Ta "" Ta "Saved cursor X in pane"
.It Li "saved_cursor_y" Ta "" Ta "Saved cursor Y in pane"
.It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane" .It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane"
.It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane" .It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane"
.It Li "session_attached" Ta "" Ta "Number of clients session is attached to" .It Li "session_attached" Ta "" Ta "Number of clients session is attached to"

54
tmux.h
View File

@ -785,55 +785,6 @@ struct screen_write_ctx {
#define screen_hsize(s) ((s)->grid->hsize) #define screen_hsize(s) ((s)->grid->hsize)
#define screen_hlimit(s) ((s)->grid->hlimit) #define screen_hlimit(s) ((s)->grid->hlimit)
/* Input parser cell. */
struct input_cell {
struct grid_cell cell;
int set;
int g0set; /* 1 if ACS */
int g1set; /* 1 if ACS */
};
/* Input parser context. */
struct input_ctx {
struct window_pane *wp;
struct screen_write_ctx ctx;
struct input_cell cell;
struct input_cell old_cell;
u_int old_cx;
u_int old_cy;
u_char interm_buf[4];
size_t interm_len;
u_char param_buf[64];
size_t param_len;
#define INPUT_BUF_START 32
#define INPUT_BUF_LIMIT 1048576
u_char *input_buf;
size_t input_len;
size_t input_space;
int param_list[24]; /* -1 not present */
u_int param_list_len;
struct utf8_data utf8data;
int ch;
int flags;
#define INPUT_DISCARD 0x1
const struct input_state *state;
/*
* All input received since we were last in the ground state. Sent to
* control clients on connection.
*/
struct evbuffer *since_ground;
};
/* /*
* Window mode. Windows can be in several modes and this is used to call the * Window mode. Windows can be in several modes and this is used to call the
* right function to handle input and output. * right function to handle input and output.
@ -881,6 +832,7 @@ struct window_choose_mode_item {
}; };
/* Child window structure. */ /* Child window structure. */
struct input_ctx;
struct window_pane { struct window_pane {
u_int id; u_int id;
u_int active_point; u_int active_point;
@ -920,7 +872,7 @@ struct window_pane {
int fd; int fd;
struct bufferevent *event; struct bufferevent *event;
struct input_ctx ictx; struct input_ctx *ictx;
struct grid_cell colgc; struct grid_cell colgc;
@ -1983,6 +1935,8 @@ void recalculate_sizes(void);
/* input.c */ /* input.c */
void input_init(struct window_pane *); void input_init(struct window_pane *);
void input_free(struct window_pane *); void input_free(struct window_pane *);
void input_reset(struct window_pane *);
struct evbuffer *input_pending(struct window_pane *);
void input_parse(struct window_pane *); void input_parse(struct window_pane *);
/* input-key.c */ /* input-key.c */