summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2015-05-08 16:18:04 +0000
committernicm <nicm>2015-05-08 16:18:04 +0000
commitc4a4bd6ac5748939c7c17beba9e14bee5929c552 (patch)
tree015353e19d24a55e9da47a7acf3a8faee09a832f
parent879de25583a5a0bce57bd816ced96e0caf62c436 (diff)
Move input parser structs into input.c (removing fairly useless
saved_cursor_[xy] formats as a side-effect).
-rw-r--r--cmd-capture-pane.c14
-rw-r--r--cmd-send-keys.c18
-rw-r--r--format.c2
-rw-r--r--input.c93
-rw-r--r--tmux.12
-rw-r--r--tmux.h54
6 files changed, 100 insertions, 83 deletions
diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c
index b44ebe9d..a348e155 100644
--- a/cmd-capture-pane.c
+++ b/cmd-capture-pane.c
@@ -57,15 +57,17 @@ char *
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
size_t *len)
{
- char *buf, *line, tmp[5];
- size_t linelen;
- u_int i;
+ struct evbuffer *pending;
+ char *buf, *line, tmp[5];
+ size_t linelen;
+ u_int i;
- if (wp->ictx.since_ground == NULL)
+ pending = input_pending(wp);
+ if (pending == NULL)
return (xstrdup(""));
- line = EVBUFFER_DATA(wp->ictx.since_ground);
- linelen = EVBUFFER_LENGTH(wp->ictx.since_ground);
+ line = EVBUFFER_DATA(pending);
+ linelen = EVBUFFER_LENGTH(pending);
buf = xstrdup("");
if (args_has(args, 'C')) {
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
index 27da410d..b1f8d672 100644
--- a/cmd-send-keys.c
+++ b/cmd-send-keys.c
@@ -52,7 +52,6 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
struct mouse_event *m = &cmdq->item->mouse;
struct window_pane *wp;
struct session *s;
- struct input_ctx *ictx;
const u_char *str;
int i, key;
@@ -78,21 +77,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
- if (args_has(args, 'R')) {
- 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);
- }
+ if (args_has(args, 'R'))
+ input_reset(wp);
for (i = 0; i < args->argc; i++) {
str = args->argv[i];
diff --git a/format.c b/format.c
index ac28604d..39351fc3 100644
--- a/format.c
+++ b/format.c
@@ -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, "scroll_region_upper", "%u", wp->base.rupper);
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_saved_x", "%u", wp->saved_cx);
diff --git a/input.c b/input.c
index 9f7d4413..384ab45d 100644
--- a/input.c
+++ b/input.c
@@ -46,6 +46,55 @@
* 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. */
struct input_transition;
int input_split(struct input_ctx *);
@@ -706,7 +755,9 @@ input_reset_cell(struct input_ctx *ictx)
void
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);
@@ -732,18 +783,46 @@ input_init(struct window_pane *wp)
void
input_free(struct window_pane *wp)
{
- if (wp == NULL)
- return;
+ struct input_ctx *ictx = wp->ictx;
- free(wp->ictx.input_buf);
- evbuffer_free(wp->ictx.since_ground);
+ free(ictx->input_buf);
+ 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. */
void
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)
ictx->state->exit(ictx);
@@ -756,7 +835,7 @@ input_set_state(struct window_pane *wp, const struct input_transition *itr)
void
input_parse(struct window_pane *wp)
{
- struct input_ctx *ictx = &wp->ictx;
+ struct input_ctx *ictx = wp->ictx;
const struct input_transition *itr;
struct evbuffer *evb = wp->event->input;
u_char *buf;
diff --git a/tmux.1 b/tmux.1
index ea178b78..9debeaf4 100644
--- a/tmux.1
+++ b/tmux.1
@@ -3318,8 +3318,6 @@ The following variables are available, where appropriate:
.It Li "pane_top" Ta "" Ta "Top of pane"
.It Li "pane_tty" Ta "" Ta "Pseudo terminal 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_upper" Ta "" Ta "Top of scroll region in pane"
.It Li "session_attached" Ta "" Ta "Number of clients session is attached to"
diff --git a/tmux.h b/tmux.h
index 72e172e6..ad79d79d 100644
--- a/tmux.h
+++ b/tmux.h
@@ -785,55 +785,6 @@ struct screen_write_ctx {
#define screen_hsize(s) ((s)->grid->hsize)
#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
* right function to handle input and output.
@@ -881,6 +832,7 @@ struct window_choose_mode_item {
};
/* Child window structure. */
+struct input_ctx;
struct window_pane {
u_int id;
u_int active_point;
@@ -920,7 +872,7 @@ struct window_pane {
int fd;
struct bufferevent *event;
- struct input_ctx ictx;
+ struct input_ctx *ictx;
struct grid_cell colgc;
@@ -1983,6 +1935,8 @@ void recalculate_sizes(void);
/* input.c */
void input_init(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 *);
/* input-key.c */