mirror of
https://github.com/tmux/tmux.git
synced 2025-01-14 12:48:56 +00:00
Support command sequences separated by " ; ". Also clean up command printing.
This commit is contained in:
parent
c4d5989a4e
commit
a15f8fc4a6
15
CHANGES
15
CHANGES
@ -1,5 +1,18 @@
|
||||
18 January 2009
|
||||
|
||||
* Cleaned up command printing code, also enclose arguments with spaces in "s.
|
||||
* Added command sequences. These are entered by separating each argument by a ;
|
||||
argument (spaces on both sides), for example:
|
||||
|
||||
lsk ; lsc
|
||||
|
||||
To use a literal ; as the argument prefix it with \, for example:
|
||||
|
||||
bind x lsk \; lsc
|
||||
|
||||
Commands are executed from left to right and, importantly, an error does NOT
|
||||
stop execution. Also note that command sequences do not support repeat-time
|
||||
repetition unless all commands making up the sequence support it.
|
||||
* suspend-client command to suspend a client. Don't try to background it
|
||||
though...
|
||||
* Mark attached sessions in sessions lists. Suggested by Simon Kuhnle.
|
||||
@ -938,7 +951,7 @@
|
||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||
customisation.
|
||||
|
||||
$Id: CHANGES,v 1.216 2009-01-18 12:13:21 nicm Exp $
|
||||
$Id: CHANGES,v 1.217 2009-01-18 14:40:48 nicm Exp $
|
||||
|
||||
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
||||
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $Id: GNUmakefile,v 1.59 2009-01-18 12:09:42 nicm Exp $
|
||||
# $Id: GNUmakefile,v 1.60 2009-01-18 14:40:48 nicm Exp $
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
@ -17,7 +17,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
|
||||
grid.c grid-view.c \
|
||||
window.c session.c log.c client.c client-msg.c client-fn.c cfg.c \
|
||||
key-string.c key-bindings.c resize.c arg.c mode-key.c \
|
||||
cmd.c cmd-generic.c cmd-string.c \
|
||||
cmd.c cmd-generic.c cmd-string.c cmd-list.c \
|
||||
cmd-detach-client.c cmd-list-sessions.c cmd-new-window.c cmd-bind-key.c \
|
||||
cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.c \
|
||||
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
|
||||
|
4
Makefile
4
Makefile
@ -1,4 +1,4 @@
|
||||
# $Id: Makefile,v 1.98 2009-01-18 12:09:42 nicm Exp $
|
||||
# $Id: Makefile,v 1.99 2009-01-18 14:40:48 nicm Exp $
|
||||
|
||||
.SUFFIXES: .c .o .y .h
|
||||
.PHONY: clean update-index.html upload-index.html
|
||||
@ -21,7 +21,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
|
||||
grid.c grid-view.c \
|
||||
window.c session.c log.c client.c client-msg.c client-fn.c cfg.c \
|
||||
key-string.c key-bindings.c resize.c arg.c mode-key.c \
|
||||
cmd.c cmd-generic.c cmd-string.c \
|
||||
cmd.c cmd-generic.c cmd-string.c cmd-list.c \
|
||||
cmd-detach-client.c cmd-list-sessions.c cmd-new-window.c cmd-bind-key.c \
|
||||
cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.c \
|
||||
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
|
||||
|
6
TODO
6
TODO
@ -70,10 +70,12 @@
|
||||
- command: load-buffer -b number filename
|
||||
- command: copy-buffer -s src-session -t dst-session -a src-index -b dst-index
|
||||
(copy from other session)
|
||||
- function groups, bind-key ^W { select-window 0; send-key ^W } etc ***
|
||||
- neww should support -k
|
||||
- document suspend-client
|
||||
- flag to scroll-mode/copy-mode to automatically scroll up a page
|
||||
- would be nice if tmux could be the shell
|
||||
- key to switch to copy mode from scroll mode
|
||||
- clone session command
|
||||
- document suspend-client
|
||||
- document command sequences
|
||||
- make command sequences more usable: don't require space around ;, handle
|
||||
errors better
|
||||
|
22
cfg.c
22
cfg.c
@ -1,4 +1,4 @@
|
||||
/* $Id: cfg.c,v 1.13 2008-07-25 17:20:40 nicm Exp $ */
|
||||
/* $Id: cfg.c,v 1.14 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -53,12 +53,12 @@ cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
|
||||
int
|
||||
load_cfg(const char *path, char **cause)
|
||||
{
|
||||
FILE *f;
|
||||
u_int n;
|
||||
char *buf, *line, *ptr;
|
||||
size_t len;
|
||||
struct cmd *cmd;
|
||||
struct cmd_ctx ctx;
|
||||
FILE *f;
|
||||
u_int n;
|
||||
char *buf, *line, *ptr;
|
||||
size_t len;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
xasprintf(cause, "%s: %s", path, strerror(errno));
|
||||
@ -78,12 +78,12 @@ load_cfg(const char *path, char **cause)
|
||||
}
|
||||
n++;
|
||||
|
||||
if (cmd_string_parse(buf, &cmd, cause) != 0) {
|
||||
if (cmd_string_parse(buf, &cmdlist, cause) != 0) {
|
||||
if (*cause == NULL)
|
||||
continue;
|
||||
goto error;
|
||||
}
|
||||
if (cmd == NULL)
|
||||
if (cmdlist == NULL)
|
||||
continue;
|
||||
cfg_cause = NULL;
|
||||
|
||||
@ -98,8 +98,8 @@ load_cfg(const char *path, char **cause)
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cfg_cause = NULL;
|
||||
cmd_exec(cmd, &ctx);
|
||||
cmd_free(cmd);
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
if (cfg_cause != NULL) {
|
||||
*cause = cfg_cause;
|
||||
goto error;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-bind-key.c,v 1.17 2008-12-10 20:25:41 nicm Exp $ */
|
||||
/* $Id: cmd-bind-key.c,v 1.18 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -29,11 +29,11 @@ void cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_bind_key_send(struct cmd *, struct buffer *);
|
||||
void cmd_bind_key_recv(struct cmd *, struct buffer *);
|
||||
void cmd_bind_key_free(struct cmd *);
|
||||
void cmd_bind_key_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_bind_key_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_bind_key_data {
|
||||
int key;
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *cmdlist;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_bind_key_entry = {
|
||||
@ -56,7 +56,7 @@ cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
int opt;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->cmd = NULL;
|
||||
data->cmdlist = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "")) != -1) {
|
||||
switch (opt) {
|
||||
@ -76,7 +76,7 @@ cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if ((data->cmd = cmd_parse(argc, argv, cause)) == NULL)
|
||||
if ((data->cmdlist = cmd_list_parse(argc, argv, cause)) == NULL)
|
||||
goto error;
|
||||
|
||||
return (0);
|
||||
@ -97,8 +97,8 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (data == NULL)
|
||||
return;
|
||||
|
||||
key_bindings_add(data->key, data->cmd);
|
||||
data->cmd = NULL; /* avoid free */
|
||||
key_bindings_add(data->key, data->cmdlist);
|
||||
data->cmdlist = NULL; /* avoid free */
|
||||
|
||||
if (ctx->cmdclient != NULL)
|
||||
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
|
||||
@ -110,7 +110,7 @@ cmd_bind_key_send(struct cmd *self, struct buffer *b)
|
||||
struct cmd_bind_key_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send(data->cmd, b);
|
||||
cmd_list_send(data->cmdlist, b);
|
||||
}
|
||||
|
||||
void
|
||||
@ -120,7 +120,7 @@ cmd_bind_key_recv(struct cmd *self, struct buffer *b)
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->cmd = cmd_recv(b);
|
||||
data->cmdlist = cmd_list_recv(b);
|
||||
}
|
||||
|
||||
void
|
||||
@ -128,26 +128,26 @@ cmd_bind_key_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_bind_key_data *data = self->data;
|
||||
|
||||
if (data->cmd != NULL)
|
||||
cmd_free(data->cmd);
|
||||
if (data->cmdlist != NULL)
|
||||
cmd_list_free(data->cmdlist);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_bind_key_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_bind_key_data *data = self->data;
|
||||
size_t off = 0;
|
||||
const char *skey;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len) {
|
||||
off += xsnprintf(buf + off,
|
||||
len - off, " %s", key_string_lookup_key(data->key));
|
||||
}
|
||||
if (off < len && data->cmd != NULL) {
|
||||
off += xsnprintf(buf + off, len - off, " ");
|
||||
data->cmd->entry->print(data->cmd, buf + off, len - off);
|
||||
skey = key_string_lookup_key(data->key);
|
||||
off += xsnprintf(buf + off, len - off, " %s ", skey);
|
||||
}
|
||||
if (off < len)
|
||||
off += cmd_list_print(data->cmdlist, buf + off, len - off);
|
||||
return (off);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-command-prompt.c,v 1.9 2009-01-14 22:16:56 nicm Exp $ */
|
||||
/* $Id: cmd-command-prompt.c,v 1.10 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -60,7 +60,7 @@ cmd_command_prompt_init(struct cmd *self, int key)
|
||||
|
||||
switch (key) {
|
||||
case ',':
|
||||
data->arg = xstrdup("rename-window \"%%\"");
|
||||
data->arg = xstrdup("rename-window '%%'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -102,7 +102,7 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
{
|
||||
struct cmd_command_prompt_data *cdata = data;
|
||||
struct client *c = cdata->c;
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *cause, *ptr, *buf, ch;
|
||||
size_t len, slen;
|
||||
@ -139,17 +139,17 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
}
|
||||
xfree(cdata);
|
||||
|
||||
if (cmd_string_parse(s, &cmd, &cause) != 0) {
|
||||
if (cmd_string_parse(s, &cmdlist, &cause) != 0) {
|
||||
if (cause == NULL)
|
||||
return (0);
|
||||
*cause = toupper((u_char) *cause);
|
||||
server_set_client_message(c, cause);
|
||||
xfree(cause);
|
||||
cmd = NULL;
|
||||
cmdlist = NULL;
|
||||
}
|
||||
if (buf != NULL)
|
||||
xfree(buf);
|
||||
if (cmd == NULL)
|
||||
if (cmdlist == NULL)
|
||||
return (0);
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
@ -162,7 +162,7 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cmd_exec(cmd, &ctx);
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
|
||||
if (c->prompt_callback != (void *) &cmd_command_prompt_callback)
|
||||
return (1);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-generic.c,v 1.21 2009-01-14 22:16:56 nicm Exp $ */
|
||||
/* $Id: cmd-generic.c,v 1.22 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -19,6 +19,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@ -28,6 +29,14 @@ int cmd_do_flags(int, int, int *);
|
||||
size_t cmd_print_flags(char *, size_t, size_t, int);
|
||||
int cmd_fill_argument(int, char **, int, char **);
|
||||
|
||||
size_t
|
||||
cmd_prarg(char *buf, size_t len, const char *prefix, char *arg)
|
||||
{
|
||||
if (strchr(arg, ' ' ) != NULL)
|
||||
return (xsnprintf(buf, len, "%s\"%s\"", prefix, arg));
|
||||
return (xsnprintf(buf, len, "%s%s", prefix, arg));
|
||||
}
|
||||
|
||||
int
|
||||
cmd_do_flags(int opt, int iflags, int *oflags)
|
||||
{
|
||||
@ -194,7 +203,7 @@ cmd_target_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_target_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
@ -202,12 +211,13 @@ cmd_target_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->arg);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
@ -302,7 +312,7 @@ cmd_srcdst_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_srcdst_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
@ -310,14 +320,15 @@ cmd_srcdst_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
if (off < len && data->src != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -s %s", data->src);
|
||||
if (off < len && data->dst != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->dst);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->arg);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
@ -416,7 +427,7 @@ cmd_buffer_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
@ -424,14 +435,15 @@ cmd_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
if (off < len && data->buffer != -1)
|
||||
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->arg);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
@ -528,7 +540,7 @@ cmd_option_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_option_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
@ -536,14 +548,15 @@ cmd_option_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->option != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->option);
|
||||
if (off < len && data->value != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->value);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
@ -643,7 +656,7 @@ cmd_pane_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_pane_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
@ -651,10 +664,11 @@ cmd_pane_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->arg);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
return (off);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list-keys.c,v 1.11 2009-01-06 14:10:32 nicm Exp $ */
|
||||
/* $Id: cmd-list-keys.c,v 1.12 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -44,17 +44,15 @@ cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct key_binding *bd;
|
||||
const char *key;
|
||||
char s[BUFSIZ];
|
||||
char tmp[BUFSIZ];
|
||||
|
||||
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||
if ((key = key_string_lookup_key(bd->key)) == NULL)
|
||||
continue;
|
||||
if (bd->cmd->entry->print == NULL) {
|
||||
ctx->print(ctx, "%11s: %s", key, bd->cmd->entry->name);
|
||||
continue;
|
||||
}
|
||||
bd->cmd->entry->print(bd->cmd, s, sizeof s);
|
||||
ctx->print(ctx, "%11s: %s", key, s);
|
||||
|
||||
*tmp = '\0';
|
||||
cmd_list_print(bd->cmdlist, tmp, sizeof tmp);
|
||||
ctx->print(ctx, "%11s: %s", key, tmp);
|
||||
}
|
||||
|
||||
if (ctx->cmdclient != NULL)
|
||||
|
137
cmd-list.c
Normal file
137
cmd-list.c
Normal file
@ -0,0 +1,137 @@
|
||||
/* $Id: cmd-list.c,v 1.1 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct cmd_list *
|
||||
cmd_list_parse(int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
int i, lastsplit;
|
||||
|
||||
cmdlist = xmalloc(sizeof *cmdlist);
|
||||
TAILQ_INIT(cmdlist);
|
||||
|
||||
lastsplit = 0;
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (strcmp(argv[i], "\\;") == 0) {
|
||||
argv[i][0] = ';';
|
||||
argv[i][1] = '\0';
|
||||
} else if (strcmp(argv[i], ";") == 0) {
|
||||
cmd = cmd_parse(i - lastsplit, argv + lastsplit, cause);
|
||||
if (cmd == NULL)
|
||||
goto bad;
|
||||
TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
|
||||
lastsplit = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
cmd = cmd_parse(argc - lastsplit, argv + lastsplit, cause);
|
||||
if (cmd == NULL) {
|
||||
cmd_list_free(cmdlist);
|
||||
return (NULL);
|
||||
}
|
||||
TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
|
||||
|
||||
return (cmdlist);
|
||||
|
||||
bad:
|
||||
cmd_list_free(cmdlist);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry)
|
||||
cmd_exec(cmd, ctx);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_send(struct cmd_list *cmdlist, struct buffer *b)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
u_int n;
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry)
|
||||
n++;
|
||||
|
||||
buffer_write(b, &n, sizeof n);
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry)
|
||||
cmd_send(cmd, b);
|
||||
}
|
||||
|
||||
struct cmd_list *
|
||||
cmd_list_recv(struct buffer *b)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
u_int n;
|
||||
|
||||
buffer_read(b, &n, sizeof n);
|
||||
|
||||
cmdlist = xmalloc(sizeof *cmdlist);
|
||||
TAILQ_INIT(cmdlist);
|
||||
|
||||
while (n-- > 0) {
|
||||
cmd = cmd_recv(b);
|
||||
TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
|
||||
}
|
||||
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_free(struct cmd_list *cmdlist)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
while (!TAILQ_EMPTY(cmdlist)) {
|
||||
cmd = TAILQ_FIRST(cmdlist);
|
||||
TAILQ_REMOVE(cmdlist, cmd, qentry);
|
||||
cmd_free(cmd);
|
||||
}
|
||||
xfree(cmdlist);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
size_t off;
|
||||
|
||||
off = 0;
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry) {
|
||||
if (off >= len)
|
||||
break;
|
||||
off += cmd_print(cmd, buf + off, len - off);
|
||||
if (off >= len)
|
||||
break;
|
||||
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " ; ");
|
||||
}
|
||||
return (off);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-new-session.c,v 1.34 2009-01-11 00:48:42 nicm Exp $ */
|
||||
/* $Id: cmd-new-session.c,v 1.35 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -30,7 +30,7 @@ void cmd_new_session_send(struct cmd *, struct buffer *);
|
||||
void cmd_new_session_recv(struct cmd *, struct buffer *);
|
||||
void cmd_new_session_free(struct cmd *);
|
||||
void cmd_new_session_init(struct cmd *, int);
|
||||
void cmd_new_session_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_new_session_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_new_session_data {
|
||||
char *newname;
|
||||
@ -218,7 +218,7 @@ cmd_new_session_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_new_session_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_new_session_data *data = self->data;
|
||||
@ -226,13 +226,14 @@ cmd_new_session_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len && data->flag_detached)
|
||||
off += xsnprintf(buf + off, len - off, " -d");
|
||||
if (off < len && data->newname != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -s %s", data->newname);
|
||||
off += cmd_prarg(buf + off, len - off, " -s ", data->newname);
|
||||
if (off < len && data->winname != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -n %s", data->winname);
|
||||
off += cmd_prarg(buf + off, len - off, " -n ", data->winname);
|
||||
if (off < len && data->cmd != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->cmd);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||
return (off);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-new-window.c,v 1.27 2009-01-10 19:37:35 nicm Exp $ */
|
||||
/* $Id: cmd-new-window.c,v 1.28 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -32,7 +32,7 @@ void cmd_new_window_send(struct cmd *, struct buffer *);
|
||||
void cmd_new_window_recv(struct cmd *, struct buffer *);
|
||||
void cmd_new_window_free(struct cmd *);
|
||||
void cmd_new_window_init(struct cmd *, int);
|
||||
void cmd_new_window_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_new_window_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_new_window_data {
|
||||
char *target;
|
||||
@ -194,7 +194,7 @@ cmd_new_window_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_new_window_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_new_window_data *data = self->data;
|
||||
@ -202,13 +202,14 @@ cmd_new_window_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len && data->flag_detached)
|
||||
off += xsnprintf(buf + off, len - off, " -d");
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->name != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -n %s", data->name);
|
||||
off += cmd_prarg(buf + off, len - off, " -n ", data->name);
|
||||
if (off < len && data->cmd != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->cmd);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||
return (off);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-send-keys.c,v 1.16 2009-01-11 23:31:46 nicm Exp $ */
|
||||
/* $Id: cmd-send-keys.c,v 1.17 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -31,7 +31,7 @@ void cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_send_keys_send(struct cmd *, struct buffer *);
|
||||
void cmd_send_keys_recv(struct cmd *, struct buffer *);
|
||||
void cmd_send_keys_free(struct cmd *);
|
||||
void cmd_send_keys_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_send_keys_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_send_keys_data {
|
||||
char *target;
|
||||
@ -160,7 +160,7 @@ cmd_send_keys_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_send_keys_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_send_keys_data *data = self->data;
|
||||
@ -169,9 +169,9 @@ cmd_send_keys_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->idx != -1)
|
||||
off += xsnprintf(buf + off, len - off, " -i %d", data->idx);
|
||||
|
||||
@ -181,4 +181,5 @@ cmd_send_keys_print(struct cmd *self, char *buf, size_t len)
|
||||
off += xsnprintf(buf + off,
|
||||
len - off, " %s", key_string_lookup_key(data->keys[i]));
|
||||
}
|
||||
return (off);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-set-password.c,v 1.1 2009-01-11 00:48:42 nicm Exp $ */
|
||||
/* $Id: cmd-set-password.c,v 1.2 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -33,7 +33,7 @@ void cmd_set_password_send(struct cmd *, struct buffer *);
|
||||
void cmd_set_password_recv(struct cmd *, struct buffer *);
|
||||
void cmd_set_password_free(struct cmd *);
|
||||
void cmd_set_password_init(struct cmd *, int);
|
||||
void cmd_set_password_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_set_password_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_set_password_data {
|
||||
char *password;
|
||||
@ -153,7 +153,7 @@ cmd_set_password_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_set_password_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_set_password_data *data = self->data;
|
||||
@ -161,9 +161,10 @@ cmd_set_password_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len && data->flag_encrypted)
|
||||
off += xsnprintf(buf + off, len - off, " -c");
|
||||
if (off < len && data->password != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " password");
|
||||
return (off);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-set-window-option.c,v 1.19 2009-01-10 19:35:39 nicm Exp $ */
|
||||
/* $Id: cmd-set-window-option.c,v 1.20 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -32,7 +32,7 @@ void cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_set_window_option_send(struct cmd *, struct buffer *);
|
||||
void cmd_set_window_option_recv(struct cmd *, struct buffer *);
|
||||
void cmd_set_window_option_free(struct cmd *);
|
||||
void cmd_set_window_option_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_set_window_option_print(struct cmd *, char *, size_t);
|
||||
|
||||
const struct cmd_entry cmd_set_window_option_entry = {
|
||||
"set-window-option", "setw",
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-source-file.c,v 1.3 2009-01-07 08:10:02 nicm Exp $ */
|
||||
/* $Id: cmd-source-file.c,v 1.4 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
|
||||
@ -30,7 +30,7 @@ void cmd_source_file_send(struct cmd *, struct buffer *);
|
||||
void cmd_source_file_recv(struct cmd *, struct buffer *);
|
||||
void cmd_source_file_free(struct cmd *);
|
||||
void cmd_source_file_init(struct cmd *, int);
|
||||
void cmd_source_file_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_source_file_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_source_file_data {
|
||||
char *path;
|
||||
@ -133,7 +133,7 @@ cmd_source_file_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_source_file_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_source_file_data *data = self->data;
|
||||
@ -141,7 +141,8 @@ cmd_source_file_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len && data->path != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->path);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->path);
|
||||
return (off);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-split-window.c,v 1.4 2009-01-14 19:29:32 nicm Exp $ */
|
||||
/* $Id: cmd-split-window.c,v 1.5 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -33,7 +33,7 @@ void cmd_split_window_send(struct cmd *, struct buffer *);
|
||||
void cmd_split_window_recv(struct cmd *, struct buffer *);
|
||||
void cmd_split_window_free(struct cmd *);
|
||||
void cmd_split_window_init(struct cmd *, int);
|
||||
void cmd_split_window_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_split_window_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_split_window_data {
|
||||
char *target;
|
||||
@ -185,7 +185,7 @@ cmd_split_window_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_split_window_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_split_window_data *data = self->data;
|
||||
@ -193,11 +193,12 @@ cmd_split_window_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len && data->flag_detached)
|
||||
off += xsnprintf(buf + off, len - off, " -d");
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->cmd != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->cmd);
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||
return (off);
|
||||
}
|
||||
|
11
cmd-string.c
11
cmd-string.c
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-string.c,v 1.10 2009-01-10 01:51:21 nicm Exp $ */
|
||||
/* $Id: cmd-string.c,v 1.11 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -53,7 +53,7 @@ cmd_string_ungetc(unused const char *s, size_t *p)
|
||||
* string, or NULL for empty command.
|
||||
*/
|
||||
int
|
||||
cmd_string_parse(const char *s, struct cmd **cmd, char **cause)
|
||||
cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
{
|
||||
size_t p;
|
||||
int ch, argc, rval;
|
||||
@ -67,7 +67,7 @@ cmd_string_parse(const char *s, struct cmd **cmd, char **cause)
|
||||
xasprintf(cause, "assignment failed: %s", s);
|
||||
return (-1);
|
||||
}
|
||||
*cmd = NULL;
|
||||
*cmdlist = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ cmd_string_parse(const char *s, struct cmd **cmd, char **cause)
|
||||
|
||||
*cause = NULL;
|
||||
|
||||
*cmd = NULL;
|
||||
*cmdlist = NULL;
|
||||
rval = -1;
|
||||
|
||||
p = 0;
|
||||
@ -131,7 +131,8 @@ cmd_string_parse(const char *s, struct cmd **cmd, char **cause)
|
||||
if (argc == 0)
|
||||
goto out;
|
||||
|
||||
if ((*cmd = cmd_parse(argc, argv, cause)) == NULL)
|
||||
*cmdlist = cmd_list_parse(argc, argv, cause);
|
||||
if (*cmdlist == NULL)
|
||||
goto out;
|
||||
|
||||
rval = 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-switch-client.c,v 1.13 2008-12-10 20:25:41 nicm Exp $ */
|
||||
/* $Id: cmd-switch-client.c,v 1.14 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -32,7 +32,7 @@ void cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_switch_client_send(struct cmd *, struct buffer *);
|
||||
void cmd_switch_client_recv(struct cmd *, struct buffer *);
|
||||
void cmd_switch_client_free(struct cmd *);
|
||||
void cmd_switch_client_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_switch_client_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_switch_client_data {
|
||||
char *name;
|
||||
@ -145,7 +145,7 @@ cmd_switch_client_free(struct cmd *self)
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void
|
||||
size_t
|
||||
cmd_switch_client_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_switch_client_data *data = self->data;
|
||||
@ -153,9 +153,10 @@ cmd_switch_client_print(struct cmd *self, char *buf, size_t len)
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return;
|
||||
return (off);
|
||||
if (off < len && data->name != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -c %s", data->name);
|
||||
off += cmd_prarg(buf + off, len - off, " -c ", data->name);
|
||||
if (off < len && data->target != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
return (off);
|
||||
}
|
||||
|
11
cmd.c
11
cmd.c
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd.c,v 1.80 2009-01-18 12:09:42 nicm Exp $ */
|
||||
/* $Id: cmd.c,v 1.81 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -234,6 +234,15 @@ cmd_free(struct cmd *cmd)
|
||||
xfree(cmd);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_print(struct cmd *cmd, char *buf, size_t len)
|
||||
{
|
||||
if (cmd->entry->print == NULL) {
|
||||
return (xsnprintf(buf, len, "%s", cmd->entry->name));
|
||||
}
|
||||
return (cmd->entry->print(cmd, buf, len));
|
||||
}
|
||||
|
||||
void
|
||||
cmd_send_string(struct buffer *b, const char *s)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: key-bindings.c,v 1.54 2009-01-18 12:09:42 nicm Exp $ */
|
||||
/* $Id: key-bindings.c,v 1.55 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -44,7 +44,7 @@ key_bindings_lookup(int key)
|
||||
}
|
||||
|
||||
void
|
||||
key_bindings_add(int key, struct cmd *cmd)
|
||||
key_bindings_add(int key, struct cmd_list *cmdlist)
|
||||
{
|
||||
struct key_binding *bd;
|
||||
|
||||
@ -53,8 +53,8 @@ key_bindings_add(int key, struct cmd *cmd)
|
||||
bd->key = key;
|
||||
SPLAY_INSERT(key_bindings, &key_bindings, bd);
|
||||
} else
|
||||
cmd_free(bd->cmd);
|
||||
bd->cmd = cmd;
|
||||
cmd_list_free(bd->cmdlist);
|
||||
bd->cmdlist = cmdlist;
|
||||
}
|
||||
|
||||
void
|
||||
@ -66,7 +66,7 @@ key_bindings_remove(int key)
|
||||
return;
|
||||
SPLAY_REMOVE(key_bindings, &key_bindings, bd);
|
||||
|
||||
cmd_free(bd->cmd);
|
||||
cmd_list_free(bd->cmdlist);
|
||||
xfree(bd);
|
||||
}
|
||||
|
||||
@ -120,16 +120,22 @@ key_bindings_init(void)
|
||||
};
|
||||
u_int i;
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
SPLAY_INIT(&key_bindings);
|
||||
|
||||
for (i = 0; i < nitems(table); i++) {
|
||||
cmdlist = xmalloc(sizeof *cmdlist);
|
||||
TAILQ_INIT(cmdlist);
|
||||
|
||||
cmd = xmalloc(sizeof *cmd);
|
||||
cmd->entry = table[i].entry;
|
||||
cmd->data = NULL;
|
||||
if (cmd->entry->init != NULL)
|
||||
cmd->entry->init(cmd, table[i].key);
|
||||
key_bindings_add(table[i].key, cmd);
|
||||
TAILQ_INSERT_HEAD(cmdlist, cmd, qentry);
|
||||
|
||||
key_bindings_add(table[i].key, cmdlist);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +147,7 @@ key_bindings_free(void)
|
||||
while (!SPLAY_EMPTY(&key_bindings)) {
|
||||
bd = SPLAY_ROOT(&key_bindings);
|
||||
SPLAY_REMOVE(key_bindings, &key_bindings, bd);
|
||||
cmd_free(bd->cmd);
|
||||
cmd_list_free(bd->cmdlist);
|
||||
xfree(bd);
|
||||
}
|
||||
}
|
||||
@ -207,5 +213,5 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c)
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cmd_exec(bd->cmd, &ctx);
|
||||
cmd_list_exec(bd->cmdlist, &ctx);
|
||||
}
|
||||
|
17
server.c
17
server.c
@ -1,4 +1,4 @@
|
||||
/* $Id: server.c,v 1.107 2009-01-18 12:09:42 nicm Exp $ */
|
||||
/* $Id: server.c,v 1.108 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -587,7 +587,8 @@ server_handle_client(struct client *c)
|
||||
struct window_pane *wp;
|
||||
struct timeval tv;
|
||||
struct key_binding *bd;
|
||||
int key, prefix, status, flags, xtimeout;
|
||||
struct cmd *cmd;
|
||||
int key, prefix, status, xtimeout, can_repeat;
|
||||
|
||||
xtimeout = options_get_number(&c->session->options, "repeat-time");
|
||||
if (xtimeout != 0 && c->flags & CLIENT_REPEAT) {
|
||||
@ -636,10 +637,16 @@ server_handle_client(struct client *c)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
flags = bd->cmd->entry->flags;
|
||||
|
||||
/* Check repeat flag. */
|
||||
can_repeat = 1;
|
||||
TAILQ_FOREACH(cmd, bd->cmdlist, qentry) {
|
||||
if (!(cmd->entry->flags & CMD_CANREPEAT))
|
||||
can_repeat = 0;
|
||||
}
|
||||
|
||||
/* If already repeating, but this key can't repeat, skip it. */
|
||||
if (c->flags & CLIENT_REPEAT && !(flags & CMD_CANREPEAT)) {
|
||||
if (c->flags & CLIENT_REPEAT && !can_repeat) {
|
||||
c->flags &= ~CLIENT_REPEAT;
|
||||
if (key == prefix)
|
||||
c->flags |= CLIENT_PREFIX;
|
||||
@ -649,7 +656,7 @@ server_handle_client(struct client *c)
|
||||
}
|
||||
|
||||
/* If this key can repeat, reset the repeat flags and timer. */
|
||||
if (xtimeout != 0 && flags & CMD_CANREPEAT) {
|
||||
if (xtimeout != 0 && can_repeat) {
|
||||
c->flags |= CLIENT_PREFIX|CLIENT_REPEAT;
|
||||
|
||||
tv.tv_sec = xtimeout / 1000;
|
||||
|
35
tmux.h
35
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.237 2009-01-18 12:09:42 nicm Exp $ */
|
||||
/* $Id: tmux.h,v 1.238 2009-01-18 14:40:48 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -19,7 +19,7 @@
|
||||
#ifndef TMUX_H
|
||||
#define TMUX_H
|
||||
|
||||
#define PROTOCOL_VERSION -8
|
||||
#define PROTOCOL_VERSION -9
|
||||
|
||||
/* Shut up gcc warnings about empty if bodies. */
|
||||
#define RB_AUGMENT(x) do {} while (0)
|
||||
@ -807,7 +807,10 @@ struct cmd_ctx {
|
||||
struct cmd {
|
||||
const struct cmd_entry *entry;
|
||||
void *data;
|
||||
|
||||
TAILQ_ENTRY(cmd) qentry;
|
||||
};
|
||||
TAILQ_HEAD(cmd_list, cmd);
|
||||
|
||||
struct cmd_entry {
|
||||
const char *name;
|
||||
@ -832,7 +835,7 @@ struct cmd_entry {
|
||||
void (*send)(struct cmd *, struct buffer *);
|
||||
void (*recv)(struct cmd *, struct buffer *);
|
||||
void (*free)(struct cmd *);
|
||||
void (*print)(struct cmd *, char *, size_t);
|
||||
size_t (*print)(struct cmd *, char *, size_t);
|
||||
};
|
||||
|
||||
/* Generic command data. */
|
||||
@ -873,7 +876,7 @@ struct cmd_pane_data {
|
||||
/* Key binding. */
|
||||
struct key_binding {
|
||||
int key;
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
SPLAY_ENTRY(key_binding) entry;
|
||||
};
|
||||
@ -1080,6 +1083,7 @@ void cmd_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_send(struct cmd *, struct buffer *);
|
||||
struct cmd *cmd_recv(struct buffer *);
|
||||
void cmd_free(struct cmd *);
|
||||
size_t cmd_print(struct cmd *, char *, size_t);
|
||||
void cmd_send_string(struct buffer *, const char *);
|
||||
char *cmd_recv_string(struct buffer *);
|
||||
struct session *cmd_current_session(struct cmd_ctx *);
|
||||
@ -1149,10 +1153,19 @@ extern const struct cmd_entry cmd_unbind_key_entry;
|
||||
extern const struct cmd_entry cmd_unlink_window_entry;
|
||||
extern const struct cmd_entry cmd_up_pane_entry;
|
||||
|
||||
/* cmd-list.c */
|
||||
struct cmd_list *cmd_list_parse(int, char **, char **);
|
||||
void cmd_list_exec(struct cmd_list *, struct cmd_ctx *);
|
||||
void cmd_list_send(struct cmd_list *, struct buffer *);
|
||||
struct cmd_list *cmd_list_recv(struct buffer *);
|
||||
void cmd_list_free(struct cmd_list *);
|
||||
size_t cmd_list_print(struct cmd_list *, char *, size_t);
|
||||
|
||||
/* cmd-string.c */
|
||||
int cmd_string_parse(const char *, struct cmd **, char **);
|
||||
int cmd_string_parse(const char *, struct cmd_list **, char **);
|
||||
|
||||
/* cmd-generic.c */
|
||||
size_t cmd_prarg(char *, size_t, const char *, char *);
|
||||
#define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
|
||||
#define CMD_TARGET_SESSION_USAGE "[-t target-session]"
|
||||
#define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
|
||||
@ -1162,7 +1175,7 @@ void cmd_target_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_target_send(struct cmd *, struct buffer *);
|
||||
void cmd_target_recv(struct cmd *, struct buffer *);
|
||||
void cmd_target_free(struct cmd *);
|
||||
void cmd_target_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_target_print(struct cmd *, char *, size_t);
|
||||
#define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
|
||||
#define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
|
||||
#define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
|
||||
@ -1172,7 +1185,7 @@ void cmd_srcdst_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_srcdst_send(struct cmd *, struct buffer *);
|
||||
void cmd_srcdst_recv(struct cmd *, struct buffer *);
|
||||
void cmd_srcdst_free(struct cmd *);
|
||||
void cmd_srcdst_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_srcdst_print(struct cmd *, char *, size_t);
|
||||
#define CMD_BUFFER_WINDOW_USAGE "[-b buffer-index] [-t target-window]"
|
||||
#define CMD_BUFFER_SESSION_USAGE "[-b buffer-index] [-t target-session]"
|
||||
#define CMD_BUFFER_CLIENT_USAGE "[-b buffer-index] [-t target-client]"
|
||||
@ -1182,7 +1195,7 @@ void cmd_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_buffer_send(struct cmd *, struct buffer *);
|
||||
void cmd_buffer_recv(struct cmd *, struct buffer *);
|
||||
void cmd_buffer_free(struct cmd *);
|
||||
void cmd_buffer_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_buffer_print(struct cmd *, char *, size_t);
|
||||
#define CMD_OPTION_WINDOW_USAGE "[-gu] [-t target-window] option [value]"
|
||||
#define CMD_OPTION_SESSION_USAGE "[-gu] [-t target-session] option [value]"
|
||||
#define CMD_OPTION_CLIENT_USAGE "[-gu] [-t target-client] option [value]"
|
||||
@ -1192,7 +1205,7 @@ void cmd_option_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_option_send(struct cmd *, struct buffer *);
|
||||
void cmd_option_recv(struct cmd *, struct buffer *);
|
||||
void cmd_option_free(struct cmd *);
|
||||
void cmd_option_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_option_print(struct cmd *, char *, size_t);
|
||||
#define CMD_PANE_WINDOW_USAGE "[-t target-window] [-p pane-index]"
|
||||
#define CMD_PANE_SESSION_USAGE "[-t target-session] [-p pane-index]"
|
||||
#define CMD_PANE_CLIENT_USAGE "[-t target-client] [-p pane-index]"
|
||||
@ -1202,7 +1215,7 @@ void cmd_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_pane_send(struct cmd *, struct buffer *);
|
||||
void cmd_pane_recv(struct cmd *, struct buffer *);
|
||||
void cmd_pane_free(struct cmd *);
|
||||
void cmd_pane_print(struct cmd *, char *, size_t);
|
||||
size_t cmd_pane_print(struct cmd *, char *, size_t);
|
||||
|
||||
/* client.c */
|
||||
int client_init(const char *, struct client_ctx *, int, int);
|
||||
@ -1223,7 +1236,7 @@ extern struct key_bindings key_bindings;
|
||||
int key_bindings_cmp(struct key_binding *, struct key_binding *);
|
||||
SPLAY_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
|
||||
struct key_binding *key_bindings_lookup(int);
|
||||
void key_bindings_add(int, struct cmd *);
|
||||
void key_bindings_add(int, struct cmd_list *);
|
||||
void key_bindings_remove(int);
|
||||
void key_bindings_init(void);
|
||||
void key_bindings_free(void);
|
||||
|
Loading…
Reference in New Issue
Block a user