aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2016-06-15 12:01:11 +0100
committerThomas Adam <thomas@xteddy.org>2016-06-15 12:01:11 +0100
commit5c12230a0879c7dd3ac5332dfdb9d0d7416b3557 (patch)
tree2721e0016e2ca721635e51aa6bf745ed880e6a3b
parent150c9f3fe0f7d74677d391d798efe2d49aa58cd9 (diff)
parentbee3e3e28d04a237b1013b1dd3d36cddcd326891 (diff)
downloadrtmux-5c12230a0879c7dd3ac5332dfdb9d0d7416b3557.tar.gz
rtmux-5c12230a0879c7dd3ac5332dfdb9d0d7416b3557.tar.bz2
rtmux-5c12230a0879c7dd3ac5332dfdb9d0d7416b3557.zip
Merge branch 'obsd-master'
-rw-r--r--cmd-list-keys.c53
-rw-r--r--tmux.17
-rw-r--r--tmux.h3
-rw-r--r--window.c27
4 files changed, 74 insertions, 16 deletions
diff --git a/cmd-list-keys.c b/cmd-list-keys.c
index c3ace8de..06f0e8c5 100644
--- a/cmd-list-keys.c
+++ b/cmd-list-keys.c
@@ -27,10 +27,10 @@
* List key bindings.
*/
-enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
+static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
-enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
-enum cmd_retval cmd_list_keys_commands(struct cmd_q *);
+static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
+static enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_keys_entry = {
.name = "list-keys",
@@ -47,14 +47,14 @@ const struct cmd_entry cmd_list_commands_entry = {
.name = "list-commands",
.alias = "lscm",
- .args = { "", 0, 0 },
- .usage = "",
+ .args = { "F:", 0, 0 },
+ .usage = "[-F format]",
.flags = CMD_STARTSERVER,
.exec = cmd_list_keys_exec
};
-enum cmd_retval
+static enum cmd_retval
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
@@ -65,7 +65,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
int repeat, width, tablewidth, keywidth;
if (self->entry == &cmd_list_commands_entry)
- return (cmd_list_keys_commands(cmdq));
+ return (cmd_list_keys_commands(self, cmdq));
if (args_has(args, 't'))
return (cmd_list_keys_table(self, cmdq));
@@ -131,7 +131,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
-enum cmd_retval
+static enum cmd_retval
cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
@@ -180,21 +180,44 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
-enum cmd_retval
-cmd_list_keys_commands(struct cmd_q *cmdq)
+static enum cmd_retval
+cmd_list_keys_commands(struct cmd *self, struct cmd_q *cmdq)
{
+ struct args *args = self->args;
const struct cmd_entry **entryp;
const struct cmd_entry *entry;
+ struct format_tree *ft;
+ const char *template;
+ char *line;
+
+ if ((template = args_get(args, 'F')) == NULL) {
+ template = "#{command_list_name}"
+ "#{?command_list_alias, (#{command_list_alias}),} "
+ "#{command_list_usage}";
+ }
+
+ ft = format_create(cmdq, 0);
+ format_defaults(ft, NULL, NULL, NULL, NULL);
for (entryp = cmd_table; *entryp != NULL; entryp++) {
entry = *entryp;
- if (entry->alias == NULL) {
- cmdq_print(cmdq, "%s %s", entry->name, entry->usage);
- continue;
+
+ format_add(ft, "command_list_name", "%s", entry->name);
+ if (entry->alias != NULL) {
+ format_add(ft, "command_list_alias", "%s",
+ entry->alias);
+ }
+ if (entry->alias != NULL) {
+ format_add(ft, "command_list_usage", "%s",
+ entry->usage);
}
- cmdq_print(cmdq, "%s (%s) %s", entry->name, entry->alias,
- entry->usage);
+
+ line = format_expand(ft, template);
+ if (*line != '\0')
+ cmdq_print(cmdq, "%s", line);
+ free(line);
}
+ format_free(ft);
return (CMD_RETURN_NORMAL);
}
diff --git a/tmux.1 b/tmux.1
index 23a82caf..bb93c499 100644
--- a/tmux.1
+++ b/tmux.1
@@ -777,7 +777,9 @@ section.
If
.Ar target-session
is specified, list only clients connected to that session.
-.It Ic list-commands
+.It Xo Ic list-commands
+.Op Fl F Ar format
+.Xc
.D1 (alias: Ic lscm )
List the syntax of all commands supported by
.Nm .
@@ -3496,6 +3498,9 @@ The following variables are available, where appropriate:
.It Li "client_width" Ta "" Ta "Width of client"
.It Li "command_hooked" Ta "" Ta "Name of command hooked, if any"
.It Li "command_name" Ta "" Ta "Name of command in use, if any"
+.It Li "command_list_name" Ta "" Ta "Command name if listing commands"
+.It Li "command_list_alias" Ta "" Ta "Command alias if listing commands"
+.It Li "command_list_usage" Ta "" Ta "Command usage if listing commands"
.It Li "cursor_flag" Ta "" Ta "Pane cursor flag"
.It Li "cursor_x" Ta "" Ta "Cursor X position in pane"
.It Li "cursor_y" Ta "" Ta "Cursor Y position in pane"
diff --git a/tmux.h b/tmux.h
index e5c546eb..a596de21 100644
--- a/tmux.h
+++ b/tmux.h
@@ -825,6 +825,7 @@ struct window_mode {
void (*key)(struct window_pane *, struct client *, struct session *,
key_code, struct mouse_event *);
};
+#define WINDOW_MODE_TIMEOUT 180
/* Structures for choose mode. */
struct window_choose_data {
@@ -907,6 +908,8 @@ struct window_pane {
const struct window_mode *mode;
void *modedata;
+ struct event modetimer;
+ time_t modelast;
TAILQ_ENTRY(window_pane) entry;
RB_ENTRY(window_pane) tree_entry;
diff --git a/window.c b/window.c
index 6d14c181..0ee6756e 100644
--- a/window.c
+++ b/window.c
@@ -17,6 +17,7 @@
*/
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
@@ -1061,15 +1062,38 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc,
wp->flags |= PANE_REDRAW;
}
+static void
+window_pane_mode_timer(__unused int fd, __unused short events, void *arg)
+{
+ struct window_pane *wp = arg;
+ struct timeval tv = { .tv_sec = 10 };
+ int n = 0;
+
+ evtimer_del(&wp->modetimer);
+ evtimer_add(&wp->modetimer, &tv);
+
+ log_debug("%%%u in mode: last=%ld", wp->id, (long)wp->modelast);
+
+ if (wp->modelast < time(NULL) - WINDOW_MODE_TIMEOUT) {
+ if (ioctl(wp->fd, FIONREAD, &n) == -1 || n > 0)
+ window_pane_reset_mode(wp);
+ }
+}
+
int
window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode)
{
struct screen *s;
+ struct timeval tv = { .tv_sec = 10 };
if (wp->mode != NULL)
return (1);
wp->mode = mode;
+ wp->modelast = time(NULL);
+ evtimer_set(&wp->modetimer, window_pane_mode_timer, wp);
+ evtimer_add(&wp->modetimer, &tv);
+
if ((s = wp->mode->init(wp)) != NULL)
wp->screen = s;
wp->flags |= (PANE_REDRAW|PANE_CHANGED);
@@ -1084,6 +1108,8 @@ window_pane_reset_mode(struct window_pane *wp)
if (wp->mode == NULL)
return;
+ evtimer_del(&wp->modetimer);
+
wp->mode->free(wp);
wp->mode = NULL;
@@ -1103,6 +1129,7 @@ window_pane_key(struct window_pane *wp, struct client *c, struct session *s,
return;
if (wp->mode != NULL) {
+ wp->modelast = time(NULL);
if (wp->mode->key != NULL)
wp->mode->key(wp, c, s, key, m);
return;