mirror of
https://github.com/tmux/tmux.git
synced 2024-12-04 19:58:48 +00:00
Make struct cmd local to cmd.c and move it out of tmux.h.
This commit is contained in:
parent
9cbe9675ea
commit
c20eb0c0ae
7
client.c
7
client.c
@ -236,7 +236,6 @@ int
|
||||
client_main(struct event_base *base, int argc, char **argv, int flags)
|
||||
{
|
||||
struct cmd_parse_result *pr;
|
||||
struct cmd *cmd;
|
||||
struct msg_command *data;
|
||||
int fd, i;
|
||||
const char *ttynam, *cwd;
|
||||
@ -265,10 +264,8 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
||||
*/
|
||||
pr = cmd_parse_from_arguments(argc, argv, NULL);
|
||||
if (pr->status == CMD_PARSE_SUCCESS) {
|
||||
TAILQ_FOREACH(cmd, &pr->cmdlist->list, qentry) {
|
||||
if (cmd->entry->flags & CMD_STARTSERVER)
|
||||
flags |= CLIENT_STARTSERVER;
|
||||
}
|
||||
if (cmd_list_any_have(pr->cmdlist, CMD_STARTSERVER))
|
||||
flags |= CLIENT_STARTSERVER;
|
||||
cmd_list_free(pr->cmdlist);
|
||||
} else
|
||||
free(pr->error);
|
||||
|
@ -177,7 +177,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
static enum cmd_retval
|
||||
cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
|
||||
return (cmd_attach_session(item, args_get(args, 't'),
|
||||
args_has(args, 'd'), args_has(args, 'x'), args_has(args, 'r'),
|
||||
|
@ -44,7 +44,7 @@ const struct cmd_entry cmd_bind_key_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
key_code key;
|
||||
const char *tablename, *note;
|
||||
struct cmd_parse_result *pr;
|
||||
|
@ -48,7 +48,7 @@ const struct cmd_entry cmd_break_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct winlink *wl = item->source.wl;
|
||||
@ -98,7 +98,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(dst_s->options, "base-index");
|
||||
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
|
||||
if (!args_has(self->args, 'd')) {
|
||||
if (!args_has(args, 'd')) {
|
||||
session_select(dst_s, wl->idx);
|
||||
cmd_find_from_session(current, dst_s, 0);
|
||||
}
|
||||
|
@ -192,14 +192,14 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
||||
static enum cmd_retval
|
||||
cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = item->client;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
char *buf, *cause;
|
||||
const char *bufname;
|
||||
size_t len;
|
||||
|
||||
if (self->entry == &cmd_clear_history_entry) {
|
||||
if (cmd_get_entry(self) == &cmd_clear_history_entry) {
|
||||
window_pane_reset_mode_all(wp);
|
||||
grid_clear_history(wp->base.grid);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
@ -71,15 +71,15 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const struct window_mode *mode;
|
||||
|
||||
if (self->entry == &cmd_choose_buffer_entry) {
|
||||
if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
|
||||
if (paste_get_top(NULL) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
mode = &window_buffer_mode;
|
||||
} else if (self->entry == &cmd_choose_client_entry) {
|
||||
} else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
|
||||
if (server_client_how_many() == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
mode = &window_client_mode;
|
||||
|
@ -64,7 +64,7 @@ struct cmd_command_prompt_cdata {
|
||||
static enum cmd_retval
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
const char *inputs, *prompts;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
struct client *c;
|
||||
|
@ -53,7 +53,7 @@ struct cmd_confirm_before_data {
|
||||
static enum cmd_retval
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_confirm_before_data *cdata;
|
||||
struct client *c;
|
||||
char *cmd, *copy, *new_prompt, *ptr;
|
||||
|
@ -56,7 +56,7 @@ const struct cmd_entry cmd_clock_mode_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
struct client *c = item->client;
|
||||
struct session *s;
|
||||
@ -74,7 +74,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (self->entry == &cmd_clock_mode_entry) {
|
||||
if (cmd_get_entry(self) == &cmd_clock_mode_entry) {
|
||||
window_pane_set_mode(wp, NULL, &window_clock_mode, NULL, NULL);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@ -87,7 +87,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'M'))
|
||||
window_copy_start_drag(c, &shared->mouse);
|
||||
}
|
||||
if (args_has(self->args, 'u'))
|
||||
if (args_has(args, 'u'))
|
||||
window_copy_pageup(wp, 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
@ -57,7 +57,7 @@ const struct cmd_entry cmd_suspend_client_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c, *cloop;
|
||||
struct session *s;
|
||||
enum msgtype msgtype;
|
||||
@ -66,7 +66,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (self->entry == &cmd_suspend_client_entry) {
|
||||
if (cmd_get_entry(self) == &cmd_suspend_client_entry) {
|
||||
server_client_suspend(c);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
|
||||
static enum cmd_retval
|
||||
cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
@ -239,7 +239,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
static enum cmd_retval
|
||||
cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c;
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
const char *value, *cmd = NULL, **lines = NULL;
|
||||
|
@ -60,7 +60,7 @@ cmd_display_message_each(const char *key, const char *value, void *arg)
|
||||
static enum cmd_retval
|
||||
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c, *target_c;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
@ -101,7 +101,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
target_c = c;
|
||||
else
|
||||
target_c = cmd_find_best_client(s);
|
||||
if (args_has(self->args, 'v'))
|
||||
if (args_has(args, 'v'))
|
||||
flags = FORMAT_VERBOSE;
|
||||
else
|
||||
flags = 0;
|
||||
@ -114,7 +114,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
msg = format_expand_time(ft, template);
|
||||
if (args_has(self->args, 'p'))
|
||||
if (args_has(args, 'p'))
|
||||
cmdq_print(item, "%s", msg);
|
||||
else if (c != NULL)
|
||||
status_message_set(c, "%s", msg);
|
||||
|
@ -239,7 +239,7 @@ cmd_display_panes_key(struct client *c, struct key_event *event)
|
||||
static enum cmd_retval
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
u_int delay;
|
||||
|
@ -44,7 +44,7 @@ const struct cmd_entry cmd_find_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args, *new_args;
|
||||
struct args *args = cmd_get_args(self), *new_args;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const char *s = args->argv[0];
|
||||
char *filter, *argv = { NULL };
|
||||
|
@ -62,10 +62,11 @@ struct cmd_if_shell_data {
|
||||
static enum cmd_retval
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct mouse_event *m = &item->shared->mouse;
|
||||
struct cmd_if_shell_data *cdata;
|
||||
char *shellcmd, *cmd;
|
||||
const char *file;
|
||||
struct cmdq_item *new_item;
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
@ -88,9 +89,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
memset(&pi, 0, sizeof pi);
|
||||
if (self->file != NULL)
|
||||
pi.file = self->file;
|
||||
pi.line = self->line;
|
||||
cmd_get_source(self, &pi.file, &pi.line);
|
||||
pi.item = item;
|
||||
pi.c = c;
|
||||
cmd_find_copy_state(&pi.fs, fs);
|
||||
@ -134,10 +133,9 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->item = NULL;
|
||||
|
||||
memset(&cdata->input, 0, sizeof cdata->input);
|
||||
if (self->file != NULL)
|
||||
cdata->input.file = xstrdup(self->file);
|
||||
cdata->input.line = self->line;
|
||||
cdata->input.item = cdata->item;
|
||||
cmd_get_source(self, &file, &cdata->input.line);
|
||||
if (file != NULL)
|
||||
cdata->input.file = xstrdup(file);
|
||||
cdata->input.c = c;
|
||||
if (cdata->input.c != NULL)
|
||||
cdata->input.c->references++;
|
||||
|
@ -63,7 +63,7 @@ const struct cmd_entry cmd_move_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct session *dst_s;
|
||||
struct winlink *src_wl, *dst_wl;
|
||||
@ -75,7 +75,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
|
||||
if (self->entry == &cmd_join_pane_entry)
|
||||
if (cmd_get_entry(self) == &cmd_join_pane_entry)
|
||||
not_same_window = 1;
|
||||
else
|
||||
not_same_window = 0;
|
||||
|
@ -44,10 +44,11 @@ const struct cmd_entry cmd_kill_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
|
||||
|
||||
if (args_has(self->args, 'a')) {
|
||||
if (args_has(args, 'a')) {
|
||||
server_unzoom_window(wl->window);
|
||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
||||
if (loopwp == wp)
|
||||
|
@ -54,7 +54,7 @@ const struct cmd_entry cmd_start_server_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_kill_server_exec(struct cmd *self, __unused struct cmdq_item *item)
|
||||
{
|
||||
if (self->entry == &cmd_kill_server_entry)
|
||||
if (cmd_get_entry(self) == &cmd_kill_server_entry)
|
||||
kill(getpid(), SIGTERM);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
@ -45,7 +45,7 @@ const struct cmd_entry cmd_kill_session_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct session *s, *sloop, *stmp;
|
||||
struct winlink *wl;
|
||||
|
||||
|
@ -55,13 +55,13 @@ const struct cmd_entry cmd_unlink_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct winlink *wl = item->target.wl, *wl2, *wl3;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = item->target.s;
|
||||
|
||||
if (self->entry == &cmd_unlink_window_entry) {
|
||||
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
|
||||
if (cmd_get_entry(self) == &cmd_unlink_window_entry) {
|
||||
if (!args_has(args, 'k') && !session_is_linked(s, w)) {
|
||||
cmdq_error(item, "window only linked to one session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ const struct cmd_entry cmd_list_buffers_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct paste_buffer *pb;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
|
@ -51,7 +51,7 @@ const struct cmd_entry cmd_list_clients_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct format_tree *ft;
|
||||
|
@ -144,7 +144,7 @@ cmd_list_keys_get_prefix(struct args *args, key_code *prefix)
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
const char *tablename, *r;
|
||||
@ -153,7 +153,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int repeat, width, tablewidth, keywidth, found = 0;
|
||||
size_t tmpsize, tmpused, cplen;
|
||||
|
||||
if (self->entry == &cmd_list_commands_entry)
|
||||
if (cmd_get_entry(self) == &cmd_list_commands_entry)
|
||||
return (cmd_list_keys_commands(self, item));
|
||||
|
||||
if (args->argc != 0) {
|
||||
@ -313,7 +313,7 @@ out:
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
const struct cmd_entry **entryp;
|
||||
const struct cmd_entry *entry;
|
||||
struct format_tree *ft;
|
||||
|
@ -50,7 +50,7 @@ const struct cmd_entry cmd_list_panes_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
|
||||
@ -87,7 +87,7 @@ static void
|
||||
cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
struct cmdq_item *item, int type)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct window_pane *wp;
|
||||
u_int n;
|
||||
struct format_tree *ft;
|
||||
|
@ -52,7 +52,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct session *s;
|
||||
u_int n;
|
||||
struct format_tree *ft;
|
||||
|
@ -61,7 +61,7 @@ const struct cmd_entry cmd_list_windows_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_windows_server(self, item);
|
||||
@ -84,7 +84,7 @@ static void
|
||||
cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
struct cmdq_item *item, int type)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct winlink *wl;
|
||||
u_int n;
|
||||
struct format_tree *ft;
|
||||
|
@ -83,7 +83,7 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
|
||||
static enum cmd_retval
|
||||
cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_load_buffer_data *cdata;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
|
@ -64,12 +64,12 @@ const struct cmd_entry cmd_lock_client_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c;
|
||||
|
||||
if (self->entry == &cmd_lock_server_entry)
|
||||
if (cmd_get_entry(self) == &cmd_lock_server_entry)
|
||||
server_lock();
|
||||
else if (self->entry == &cmd_lock_session_entry)
|
||||
else if (cmd_get_entry(self) == &cmd_lock_session_entry)
|
||||
server_lock_session(item->target.s);
|
||||
else {
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
|
@ -59,7 +59,7 @@ const struct cmd_entry cmd_link_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
const char *tflag = args_get(args, 't');
|
||||
struct session *src;
|
||||
struct session *dst;
|
||||
@ -86,11 +86,11 @@ cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
wl = item->source.wl;
|
||||
idx = item->target.idx;
|
||||
|
||||
kflag = args_has(self->args, 'k');
|
||||
dflag = args_has(self->args, 'd');
|
||||
sflag = args_has(self->args, 's');
|
||||
kflag = args_has(args, 'k');
|
||||
dflag = args_has(args, 'd');
|
||||
sflag = args_has(args, 's');
|
||||
|
||||
if (args_has(self->args, 'a')) {
|
||||
if (args_has(args, 'a')) {
|
||||
if ((idx = winlink_shuffle_up(dst, dst->curw)) == -1)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@ -101,7 +101,7 @@ cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (self->entry == &cmd_move_window_entry)
|
||||
if (cmd_get_entry(self) == &cmd_move_window_entry)
|
||||
server_unlink_window(src, wl);
|
||||
|
||||
/*
|
||||
|
@ -66,7 +66,7 @@ const struct cmd_entry cmd_has_session_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = item->client;
|
||||
struct session *s, *as, *groupwith;
|
||||
struct environ *env;
|
||||
@ -81,7 +81,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
enum cmd_retval retval;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (self->entry == &cmd_has_session_entry) {
|
||||
if (cmd_get_entry(self) == &cmd_has_session_entry) {
|
||||
/*
|
||||
* cmd_find_target() will fail if the session cannot be found,
|
||||
* so always return success here.
|
||||
|
@ -51,7 +51,7 @@ const struct cmd_entry cmd_new_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct spawn_context sc;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
|
@ -47,7 +47,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct paste_buffer *pb;
|
||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
||||
|
@ -56,7 +56,7 @@ const struct cmd_entry cmd_pipe_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct session *s = item->target.s;
|
||||
@ -89,13 +89,13 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
*
|
||||
* bind ^p pipep -o 'cat >>~/output'
|
||||
*/
|
||||
if (args_has(self->args, 'o') && old_fd != -1)
|
||||
if (args_has(args, 'o') && old_fd != -1)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
/* What do we want to do? Neither -I or -O is -O. */
|
||||
if (args_has(self->args, 'I')) {
|
||||
if (args_has(args, 'I')) {
|
||||
in = 1;
|
||||
out = args_has(self->args, 'O');
|
||||
out = args_has(args, 'O');
|
||||
} else {
|
||||
in = 0;
|
||||
out = 1;
|
||||
|
33
cmd-queue.c
33
cmd-queue.c
@ -209,11 +209,13 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
{
|
||||
struct cmdq_item *item, *first = NULL, *last = NULL;
|
||||
struct cmd *cmd;
|
||||
const struct cmd_entry *entry;
|
||||
struct cmdq_shared *shared = NULL;
|
||||
u_int group = 0;
|
||||
u_int group, last_group = 0;
|
||||
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
if (cmd->group != group) {
|
||||
cmd = cmd_list_first(cmdlist, &group);
|
||||
while (cmd != NULL) {
|
||||
if (group != last_group) {
|
||||
shared = xcalloc(1, sizeof *shared);
|
||||
if (current != NULL)
|
||||
cmd_find_copy_state(&shared->current, current);
|
||||
@ -221,14 +223,15 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
cmd_find_clear_state(&shared->current, 0);
|
||||
if (m != NULL)
|
||||
memcpy(&shared->mouse, m, sizeof shared->mouse);
|
||||
group = cmd->group;
|
||||
last_group = group;
|
||||
}
|
||||
entry = cmd_get_entry(cmd);
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
xasprintf(&item->name, "[%s/%p]", cmd->entry->name, item);
|
||||
xasprintf(&item->name, "[%s/%p]", entry->name, item);
|
||||
item->type = CMDQ_COMMAND;
|
||||
|
||||
item->group = cmd->group;
|
||||
item->group = group;
|
||||
item->flags = flags;
|
||||
|
||||
item->shared = shared;
|
||||
@ -245,6 +248,8 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
if (last != NULL)
|
||||
last->next = item;
|
||||
last = item;
|
||||
|
||||
cmd = cmd_list_next(cmd, &group);
|
||||
}
|
||||
return (first);
|
||||
}
|
||||
@ -261,7 +266,7 @@ cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
value = args_get(item->cmd->args, flag->flag);
|
||||
value = args_get(cmd_get_args(item->cmd), flag->flag);
|
||||
if (cmd_find_target(fs, item, value, flag->type, flag->flags) != 0) {
|
||||
cmd_find_clear_state(fs, 0);
|
||||
return (CMD_RETURN_ERROR);
|
||||
@ -277,7 +282,7 @@ cmdq_fire_command(struct cmdq_item *item)
|
||||
const char *name = cmdq_name(c);
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
struct cmd *cmd = item->cmd;
|
||||
const struct cmd_entry *entry = cmd->entry;
|
||||
const struct cmd_entry *entry = cmd_get_entry(cmd);
|
||||
enum cmd_retval retval;
|
||||
struct cmd_find_state *fsp, fs;
|
||||
int flags;
|
||||
@ -528,8 +533,9 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
|
||||
struct client *c = item->client;
|
||||
struct cmd *cmd = item->cmd;
|
||||
va_list ap;
|
||||
char *msg;
|
||||
char *tmp;
|
||||
char *msg, *tmp;
|
||||
const char *file;
|
||||
u_int line;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&msg, fmt, ap);
|
||||
@ -537,9 +543,10 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
|
||||
|
||||
log_debug("%s: %s", __func__, msg);
|
||||
|
||||
if (c == NULL)
|
||||
cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
|
||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
if (c == NULL) {
|
||||
cmd_get_source(cmd, &file, &line);
|
||||
cfg_add_cause("%s:%u: %s", file, line, msg);
|
||||
} else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
if (~c->flags & CLIENT_UTF8) {
|
||||
tmp = msg;
|
||||
msg = utf8_sanitize(tmp);
|
||||
|
@ -45,7 +45,7 @@ const struct cmd_entry cmd_refresh_client_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c;
|
||||
struct tty *tty;
|
||||
struct window *w;
|
||||
|
@ -46,7 +46,7 @@ const struct cmd_entry cmd_rename_session_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
char *newname;
|
||||
|
@ -45,7 +45,7 @@ const struct cmd_entry cmd_rename_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
|
@ -49,7 +49,7 @@ const struct cmd_entry cmd_resize_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct winlink *wl = item->target.wl;
|
||||
|
@ -46,7 +46,7 @@ const struct cmd_entry cmd_resize_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = item->target.s;
|
||||
|
@ -47,7 +47,7 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct spawn_context sc;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
|
@ -47,7 +47,7 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct spawn_context sc;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
|
@ -43,6 +43,7 @@ const struct cmd_entry cmd_rotate_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
@ -50,9 +51,9 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct layout_cell *lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
|
||||
window_push_zoom(w, args_has(self->args, 'Z'));
|
||||
window_push_zoom(w, args_has(args, 'Z'));
|
||||
|
||||
if (args_has(self->args, 'D')) {
|
||||
if (args_has(args, 'D')) {
|
||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
|
@ -89,7 +89,7 @@ cmd_run_shell_print(struct job *job, const char *msg)
|
||||
static enum cmd_retval
|
||||
cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_run_shell_data *cdata;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
|
@ -73,7 +73,7 @@ cmd_save_buffer_done(__unused struct client *c, const char *path, int error,
|
||||
static enum cmd_retval
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
@ -98,11 +98,11 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
bufdata = paste_buffer_data(pb, &bufsize);
|
||||
|
||||
if (self->entry == &cmd_show_buffer_entry)
|
||||
if (cmd_get_entry(self) == &cmd_show_buffer_entry)
|
||||
path = xstrdup("-");
|
||||
else
|
||||
path = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
if (args_has(self->args, 'a'))
|
||||
if (args_has(args, 'a'))
|
||||
flags = O_APPEND;
|
||||
else
|
||||
flags = 0;
|
||||
|
@ -71,7 +71,7 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
@ -81,10 +81,10 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
server_unzoom_window(w);
|
||||
|
||||
next = self->entry == &cmd_next_layout_entry;
|
||||
next = (cmd_get_entry(self) == &cmd_next_layout_entry);
|
||||
if (args_has(args, 'n'))
|
||||
next = 1;
|
||||
previous = self->entry == &cmd_previous_layout_entry;
|
||||
previous = (cmd_get_entry(self) == &cmd_previous_layout_entry);
|
||||
if (args_has(args, 'p'))
|
||||
previous = 1;
|
||||
|
||||
|
@ -83,7 +83,8 @@ cmd_select_pane_redraw(struct window *w)
|
||||
static enum cmd_retval
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
const struct cmd_entry *entry = cmd_get_entry(self);
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct winlink *wl = item->target.wl;
|
||||
@ -95,7 +96,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct style *sy;
|
||||
struct options_entry *o;
|
||||
|
||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||
if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||
lastwp = w->last;
|
||||
if (lastwp == NULL && window_count_panes(w) == 2) {
|
||||
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
||||
@ -106,12 +107,12 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no last pane");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args_has(self->args, 'e'))
|
||||
if (args_has(args, 'e'))
|
||||
lastwp->flags &= ~PANE_INPUTOFF;
|
||||
else if (args_has(self->args, 'd'))
|
||||
else if (args_has(args, 'd'))
|
||||
lastwp->flags |= PANE_INPUTOFF;
|
||||
else {
|
||||
if (window_push_zoom(w, args_has(self->args, 'Z')))
|
||||
if (window_push_zoom(w, args_has(args, 'Z')))
|
||||
server_redraw_window(w);
|
||||
window_redraw_active_switch(w, lastwp);
|
||||
if (window_set_active_pane(w, lastwp, 1)) {
|
||||
@ -146,7 +147,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
|
||||
if (args_has(args, 'P') || args_has(args, 'g')) {
|
||||
if ((style = args_get(args, 'P')) != NULL) {
|
||||
o = options_set_style(wp->options, "window-style", 0,
|
||||
style);
|
||||
@ -158,26 +159,26 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
style);
|
||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
}
|
||||
if (args_has(self->args, 'g')) {
|
||||
if (args_has(args, 'g')) {
|
||||
sy = options_get_style(wp->options, "window-style");
|
||||
cmdq_print(item, "%s", style_tostring(sy));
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'L')) {
|
||||
if (args_has(args, 'L')) {
|
||||
window_push_zoom(w, 1);
|
||||
wp = window_pane_find_left(wp);
|
||||
window_pop_zoom(w);
|
||||
} else if (args_has(self->args, 'R')) {
|
||||
} else if (args_has(args, 'R')) {
|
||||
window_push_zoom(w, 1);
|
||||
wp = window_pane_find_right(wp);
|
||||
window_pop_zoom(w);
|
||||
} else if (args_has(self->args, 'U')) {
|
||||
} else if (args_has(args, 'U')) {
|
||||
window_push_zoom(w, 1);
|
||||
wp = window_pane_find_up(wp);
|
||||
window_pop_zoom(w);
|
||||
} else if (args_has(self->args, 'D')) {
|
||||
} else if (args_has(args, 'D')) {
|
||||
window_push_zoom(w, 1);
|
||||
wp = window_pane_find_down(wp);
|
||||
window_pop_zoom(w);
|
||||
@ -185,17 +186,17 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (wp == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (args_has(self->args, 'e')) {
|
||||
if (args_has(args, 'e')) {
|
||||
wp->flags &= ~PANE_INPUTOFF;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (args_has(self->args, 'd')) {
|
||||
if (args_has(args, 'd')) {
|
||||
wp->flags |= PANE_INPUTOFF;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'T')) {
|
||||
pane_title = format_single(item, args_get(self->args, 'T'),
|
||||
if (args_has(args, 'T')) {
|
||||
pane_title = format_single(item, args_get(args, 'T'),
|
||||
c, s, wl, wp);
|
||||
if (screen_set_title(&wp->base, pane_title))
|
||||
server_status_window(wp->window);
|
||||
@ -205,7 +206,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (wp == w->active)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (window_push_zoom(w, args_has(self->args, 'Z')))
|
||||
if (window_push_zoom(w, args_has(args, 'Z')))
|
||||
server_redraw_window(w);
|
||||
window_redraw_active_switch(w, wp);
|
||||
if (window_set_active_pane(w, wp, 1)) {
|
||||
|
@ -84,23 +84,24 @@ const struct cmd_entry cmd_last_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct session *s = item->target.s;
|
||||
int next, previous, last, activity;
|
||||
|
||||
next = self->entry == &cmd_next_window_entry;
|
||||
if (args_has(self->args, 'n'))
|
||||
next = (cmd_get_entry(self) == &cmd_next_window_entry);
|
||||
if (args_has(args, 'n'))
|
||||
next = 1;
|
||||
previous = self->entry == &cmd_previous_window_entry;
|
||||
if (args_has(self->args, 'p'))
|
||||
previous = (cmd_get_entry(self) == &cmd_previous_window_entry);
|
||||
if (args_has(args, 'p'))
|
||||
previous = 1;
|
||||
last = self->entry == &cmd_last_window_entry;
|
||||
if (args_has(self->args, 'l'))
|
||||
last = (cmd_get_entry(self) == &cmd_last_window_entry);
|
||||
if (args_has(args, 'l'))
|
||||
last = 1;
|
||||
|
||||
if (next || previous || last) {
|
||||
activity = args_has(self->args, 'a');
|
||||
activity = args_has(args, 'a');
|
||||
if (next) {
|
||||
if (session_next(s, activity) != 0) {
|
||||
cmdq_error(item, "no next window");
|
||||
@ -125,7 +126,7 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
* If -T and select-window is invoked on same window as
|
||||
* current, switch to previous window.
|
||||
*/
|
||||
if (args_has(self->args, 'T') && wl == s->curw) {
|
||||
if (args_has(args, 'T') && wl == s->curw) {
|
||||
if (session_last(s) != 0) {
|
||||
cmdq_error(item, "no last window");
|
||||
return (-1);
|
||||
|
@ -131,7 +131,7 @@ cmd_send_keys_inject_string(struct client *c, struct cmd_find_state *fs,
|
||||
static enum cmd_retval
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
@ -181,7 +181,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (self->entry == &cmd_send_prefix_entry) {
|
||||
if (cmd_get_entry(self) == &cmd_send_prefix_entry) {
|
||||
if (args_has(args, '2'))
|
||||
key = options_get_number(s->options, "prefix2");
|
||||
else
|
||||
|
@ -54,7 +54,7 @@ const struct cmd_entry cmd_delete_buffer_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct paste_buffer *pb;
|
||||
char *bufdata, *cause;
|
||||
const char *bufname, *olddata;
|
||||
@ -66,7 +66,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
pb = paste_get_name(bufname);
|
||||
|
||||
if (self->entry == &cmd_delete_buffer_entry) {
|
||||
if (cmd_get_entry(self) == &cmd_delete_buffer_entry) {
|
||||
if (pb == NULL)
|
||||
pb = paste_get_top(&bufname);
|
||||
if (pb == NULL) {
|
||||
|
@ -46,7 +46,7 @@ const struct cmd_entry cmd_set_environment_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct environ *env;
|
||||
const char *name, *value, *target;
|
||||
|
||||
@ -65,7 +65,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
value = args->argv[1];
|
||||
|
||||
if (args_has(self->args, 'g'))
|
||||
if (args_has(args, 'g'))
|
||||
env = global_environ;
|
||||
else {
|
||||
if (item->target.s == NULL) {
|
||||
@ -79,13 +79,13 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
env = item->target.s->environ;
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'u')) {
|
||||
if (args_has(args, 'u')) {
|
||||
if (value != NULL) {
|
||||
cmdq_error(item, "can't specify a value with -u");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_unset(env, name);
|
||||
} else if (args_has(self->args, 'r')) {
|
||||
} else if (args_has(args, 'r')) {
|
||||
if (value != NULL) {
|
||||
cmdq_error(item, "can't specify a value with -r");
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
@ -81,7 +81,7 @@ const struct cmd_entry cmd_set_hook_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
int append = args_has(args, 'a');
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct client *c, *loop;
|
||||
@ -96,14 +96,14 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int scope;
|
||||
struct style *sy;
|
||||
|
||||
window = (self->entry == &cmd_set_window_option_entry);
|
||||
window = (cmd_get_entry(self) == &cmd_set_window_option_entry);
|
||||
|
||||
/* Expand argument. */
|
||||
c = cmd_find_client(item, NULL, 1);
|
||||
argument = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||
|
||||
/* If set-hook -R, fire the hook straight away. */
|
||||
if (self->entry == &cmd_set_hook_entry && args_has(args, 'R')) {
|
||||
if (cmd_get_entry(self) == &cmd_set_hook_entry && args_has(args, 'R')) {
|
||||
notify_hook(item, argument);
|
||||
free(argument);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@ -288,7 +288,7 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
||||
struct options_entry *parent, const char *value)
|
||||
{
|
||||
const struct options_table_entry *oe;
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
int append = args_has(args, 'a');
|
||||
struct options_entry *o;
|
||||
long long number;
|
||||
|
@ -69,7 +69,7 @@ static void
|
||||
cmd_show_environment_print(struct cmd *self, struct cmdq_item *item,
|
||||
struct environ_entry *envent)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
char *escaped;
|
||||
|
||||
if (!args_has(args, 'h') && (envent->flags & ENVIRON_HIDDEN))
|
||||
@ -77,7 +77,7 @@ cmd_show_environment_print(struct cmd *self, struct cmdq_item *item,
|
||||
if (args_has(args, 'h') && (~envent->flags & ENVIRON_HIDDEN))
|
||||
return;
|
||||
|
||||
if (!args_has(self->args, 's')) {
|
||||
if (!args_has(args, 's')) {
|
||||
if (envent->value != NULL)
|
||||
cmdq_print(item, "%s=%s", envent->name, envent->value);
|
||||
else
|
||||
@ -97,7 +97,7 @@ cmd_show_environment_print(struct cmd *self, struct cmdq_item *item,
|
||||
static enum cmd_retval
|
||||
cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct environ *env;
|
||||
struct environ_entry *envent;
|
||||
const char *target;
|
||||
@ -109,7 +109,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'g'))
|
||||
if (args_has(args, 'g'))
|
||||
env = global_environ;
|
||||
else {
|
||||
if (item->target.s == NULL) {
|
||||
|
@ -69,7 +69,7 @@ cmd_show_messages_terminals(struct cmdq_item *item, int blank)
|
||||
static enum cmd_retval
|
||||
cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c;
|
||||
struct message_entry *msg;
|
||||
char *tim;
|
||||
|
@ -77,7 +77,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
@ -87,7 +87,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int window, idx, ambiguous, parent, scope;
|
||||
struct options_entry *o;
|
||||
|
||||
window = (self->entry == &cmd_show_window_options_entry);
|
||||
window = (cmd_get_entry(self) == &cmd_show_window_options_entry);
|
||||
|
||||
if (args->argc == 0) {
|
||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||
@ -143,6 +143,7 @@ static void
|
||||
cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
||||
struct options_entry *o, int idx, int parent)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct options_array_item *a;
|
||||
const char *name = options_name(o);
|
||||
char *value, *tmp = NULL, *escaped;
|
||||
@ -154,7 +155,7 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
||||
if (options_isarray(o)) {
|
||||
a = options_array_first(o);
|
||||
if (a == NULL) {
|
||||
if (!args_has(self->args, 'v'))
|
||||
if (!args_has(args, 'v'))
|
||||
cmdq_print(item, "%s", name);
|
||||
return;
|
||||
}
|
||||
@ -169,7 +170,7 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
||||
}
|
||||
|
||||
value = options_tostring(o, idx, 0);
|
||||
if (args_has(self->args, 'v'))
|
||||
if (args_has(args, 'v'))
|
||||
cmdq_print(item, "%s", value);
|
||||
else if (options_isstring(o)) {
|
||||
escaped = args_escape(value);
|
||||
@ -193,6 +194,7 @@ static enum cmd_retval
|
||||
cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope,
|
||||
struct options *oo)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
const struct options_table_entry *oe;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
@ -210,16 +212,16 @@ cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope,
|
||||
if (~oe->scope & scope)
|
||||
continue;
|
||||
|
||||
if ((self->entry != &cmd_show_hooks_entry &&
|
||||
!args_has(self->args, 'H') &&
|
||||
if ((cmd_get_entry(self) != &cmd_show_hooks_entry &&
|
||||
!args_has(args, 'H') &&
|
||||
(oe->flags & OPTIONS_TABLE_IS_HOOK)) ||
|
||||
(self->entry == &cmd_show_hooks_entry &&
|
||||
(cmd_get_entry(self) == &cmd_show_hooks_entry &&
|
||||
(~oe->flags & OPTIONS_TABLE_IS_HOOK)))
|
||||
continue;
|
||||
|
||||
o = options_get_only(oo, oe->name);
|
||||
if (o == NULL) {
|
||||
if (!args_has(self->args, 'A'))
|
||||
if (!args_has(args, 'A'))
|
||||
continue;
|
||||
o = options_get(oo, oe->name);
|
||||
if (o == NULL)
|
||||
@ -231,7 +233,7 @@ cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope,
|
||||
if (!options_isarray(o))
|
||||
cmd_show_options_print(self, item, o, -1, parent);
|
||||
else if ((a = options_array_first(o)) == NULL) {
|
||||
if (!args_has(self->args, 'v')) {
|
||||
if (!args_has(args, 'v')) {
|
||||
name = options_name(o);
|
||||
if (parent)
|
||||
cmdq_print(item, "%s*", name);
|
||||
|
@ -123,7 +123,7 @@ cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
|
||||
static enum cmd_retval
|
||||
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_source_file_data *cdata;
|
||||
struct client *c = item->client;
|
||||
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
||||
|
@ -53,7 +53,7 @@ const struct cmd_entry cmd_split_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct spawn_context sc;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
|
@ -45,7 +45,7 @@ const struct cmd_entry cmd_swap_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct window *src_w, *dst_w;
|
||||
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
||||
struct layout_cell *src_lc, *dst_lc;
|
||||
|
@ -45,6 +45,7 @@ const struct cmd_entry cmd_swap_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct session *src, *dst;
|
||||
struct session_group *sg_src, *sg_dst;
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
@ -77,7 +78,7 @@ cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
wl_src->window = w_dst;
|
||||
TAILQ_INSERT_TAIL(&w_dst->winlinks, wl_src, wentry);
|
||||
|
||||
if (args_has(self->args, 'd')) {
|
||||
if (args_has(args, 'd')) {
|
||||
session_select(dst, wl_dst->idx);
|
||||
if (src != dst)
|
||||
session_select(src, wl_src->idx);
|
||||
|
@ -47,7 +47,7 @@ const struct cmd_entry cmd_switch_client_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
const char *tflag = args_get(args, 't');
|
||||
enum cmd_find_type type;
|
||||
int flags;
|
||||
@ -115,7 +115,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (wl != NULL && wp != NULL) {
|
||||
w = wl->window;
|
||||
if (window_push_zoom(w, args_has(self->args, 'Z')))
|
||||
if (window_push_zoom(w, args_has(args, 'Z')))
|
||||
server_redraw_window(w);
|
||||
window_redraw_active_switch(w, wp);
|
||||
window_set_active_pane(w, wp, 1);
|
||||
|
@ -28,15 +28,12 @@
|
||||
|
||||
static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static enum cmd_retval cmd_unbind_key_mode_table(struct cmd *,
|
||||
struct cmdq_item *, key_code);
|
||||
|
||||
const struct cmd_entry cmd_unbind_key_entry = {
|
||||
.name = "unbind-key",
|
||||
.alias = "unbind",
|
||||
|
||||
.args = { "ant:T:", 0, 1 },
|
||||
.usage = "[-an] [-t mode-table] [-T key-table] key",
|
||||
.args = { "anT:", 0, 1 },
|
||||
.usage = "[-an] [-T key-table] key",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_unbind_key_exec
|
||||
@ -45,7 +42,7 @@ const struct cmd_entry cmd_unbind_key_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
key_code key;
|
||||
const char *tablename;
|
||||
|
||||
@ -67,9 +64,6 @@ cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
key = KEYC_UNKNOWN;
|
||||
}
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_unbind_key_mode_table(self, item, key));
|
||||
|
||||
if (key == KEYC_UNKNOWN) {
|
||||
tablename = args_get(args, 'T');
|
||||
if (tablename == NULL) {
|
||||
@ -98,35 +92,3 @@ cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
key_bindings_remove(tablename, key);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_unbind_key_mode_table(struct cmd *self, struct cmdq_item *item,
|
||||
key_code key)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind, mtmp;
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
cmdq_error(item, "unknown key table: %s", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (key == KEYC_UNKNOWN) {
|
||||
while (!RB_EMPTY(mtab->tree)) {
|
||||
mbind = RB_ROOT(mtab->tree);
|
||||
RB_REMOVE(mode_key_tree, mtab->tree, mbind);
|
||||
free(mbind);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
mtmp.key = key;
|
||||
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||
RB_REMOVE(mode_key_tree, mtab->tree, mbind);
|
||||
free(mbind);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ cmd_wait_for_remove(struct wait_channel *wc)
|
||||
static enum cmd_retval
|
||||
cmd_wait_for_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct args *args = cmd_get_args(self);
|
||||
const char *name = args->argv[0];
|
||||
struct wait_channel *wc, wc0;
|
||||
|
||||
|
127
cmd.c
127
cmd.c
@ -207,8 +207,27 @@ const struct cmd_entry *cmd_table[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Instance of a command. */
|
||||
struct cmd {
|
||||
const struct cmd_entry *entry;
|
||||
struct args *args;
|
||||
u_int group;
|
||||
|
||||
char *file;
|
||||
u_int line;
|
||||
|
||||
char *alias;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
TAILQ_ENTRY(cmd) qentry;
|
||||
};
|
||||
TAILQ_HEAD(cmds, cmd);
|
||||
|
||||
/* Next group number for new command list. */
|
||||
static u_int cmd_list_next_group = 1;
|
||||
|
||||
/* Log an argument vector. */
|
||||
void printflike(3, 4)
|
||||
cmd_log_argv(int argc, char **argv, const char *fmt, ...)
|
||||
{
|
||||
@ -225,6 +244,7 @@ cmd_log_argv(int argc, char **argv, const char *fmt, ...)
|
||||
free(prefix);
|
||||
}
|
||||
|
||||
/* Prepend to an argument vector. */
|
||||
void
|
||||
cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
||||
{
|
||||
@ -241,6 +261,7 @@ cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
||||
(*argc)++;
|
||||
}
|
||||
|
||||
/* Append to an argument vector. */
|
||||
void
|
||||
cmd_append_argv(int *argc, char ***argv, char *arg)
|
||||
{
|
||||
@ -248,6 +269,7 @@ cmd_append_argv(int *argc, char ***argv, char *arg)
|
||||
(*argv)[(*argc)++] = xstrdup(arg);
|
||||
}
|
||||
|
||||
/* Pack an argument vector up into a buffer. */
|
||||
int
|
||||
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
{
|
||||
@ -270,6 +292,7 @@ cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Unpack an argument vector from a packed buffer. */
|
||||
int
|
||||
cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
|
||||
{
|
||||
@ -298,6 +321,7 @@ cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Copy an argument vector, ensuring it is terminated by NULL. */
|
||||
char **
|
||||
cmd_copy_argv(int argc, char **argv)
|
||||
{
|
||||
@ -314,6 +338,7 @@ cmd_copy_argv(int argc, char **argv)
|
||||
return (new_argv);
|
||||
}
|
||||
|
||||
/* Free an argument vector. */
|
||||
void
|
||||
cmd_free_argv(int argc, char **argv)
|
||||
{
|
||||
@ -326,6 +351,7 @@ cmd_free_argv(int argc, char **argv)
|
||||
free(argv);
|
||||
}
|
||||
|
||||
/* Convert argument vector to a string. */
|
||||
char *
|
||||
cmd_stringify_argv(int argc, char **argv)
|
||||
{
|
||||
@ -352,6 +378,31 @@ cmd_stringify_argv(int argc, char **argv)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* Get entry for command. */
|
||||
const struct cmd_entry *
|
||||
cmd_get_entry(struct cmd *cmd)
|
||||
{
|
||||
return (cmd->entry);
|
||||
}
|
||||
|
||||
/* Get arguments for command. */
|
||||
struct args *
|
||||
cmd_get_args(struct cmd *cmd)
|
||||
{
|
||||
return (cmd->args);
|
||||
}
|
||||
|
||||
/* Get file and line for command. */
|
||||
void
|
||||
cmd_get_source(struct cmd *cmd, const char **file, u_int *line)
|
||||
{
|
||||
if (file != NULL)
|
||||
*file = cmd->file;
|
||||
if (line != NULL)
|
||||
*line = cmd->line;
|
||||
}
|
||||
|
||||
/* Look for an alias for a command. */
|
||||
char *
|
||||
cmd_get_alias(const char *name)
|
||||
{
|
||||
@ -382,6 +433,7 @@ cmd_get_alias(const char *name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Look up a command entry by name. */
|
||||
static const struct cmd_entry *
|
||||
cmd_find(const char *name, char **cause)
|
||||
{
|
||||
@ -431,6 +483,7 @@ ambiguous:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Parse a single command from an argument vector. */
|
||||
struct cmd *
|
||||
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
{
|
||||
@ -479,6 +532,7 @@ usage:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Free a command. */
|
||||
void
|
||||
cmd_free(struct cmd *cmd)
|
||||
{
|
||||
@ -491,6 +545,7 @@ cmd_free(struct cmd *cmd)
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
/* Get a command as a string. */
|
||||
char *
|
||||
cmd_print(struct cmd *cmd)
|
||||
{
|
||||
@ -506,6 +561,7 @@ cmd_print(struct cmd *cmd)
|
||||
return (out);
|
||||
}
|
||||
|
||||
/* Create a new command list. */
|
||||
struct cmd_list *
|
||||
cmd_list_new(void)
|
||||
{
|
||||
@ -514,29 +570,33 @@ cmd_list_new(void)
|
||||
cmdlist = xcalloc(1, sizeof *cmdlist);
|
||||
cmdlist->references = 1;
|
||||
cmdlist->group = cmd_list_next_group++;
|
||||
TAILQ_INIT(&cmdlist->list);
|
||||
cmdlist->list = xcalloc(1, sizeof *cmdlist->list);
|
||||
TAILQ_INIT(cmdlist->list);
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
/* Append a command to a command list. */
|
||||
void
|
||||
cmd_list_append(struct cmd_list *cmdlist, struct cmd *cmd)
|
||||
{
|
||||
cmd->group = cmdlist->group;
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
TAILQ_INSERT_TAIL(cmdlist->list, cmd, qentry);
|
||||
}
|
||||
|
||||
/* Move all commands from one command list to another */
|
||||
void
|
||||
cmd_list_move(struct cmd_list *cmdlist, struct cmd_list *from)
|
||||
{
|
||||
struct cmd *cmd, *cmd1;
|
||||
|
||||
TAILQ_FOREACH_SAFE(cmd, &from->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(&from->list, cmd, qentry);
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
TAILQ_FOREACH_SAFE(cmd, from->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(from->list, cmd, qentry);
|
||||
TAILQ_INSERT_TAIL(cmdlist->list, cmd, qentry);
|
||||
}
|
||||
cmdlist->group = cmd_list_next_group++;
|
||||
}
|
||||
|
||||
/* Free a command list. */
|
||||
void
|
||||
cmd_list_free(struct cmd_list *cmdlist)
|
||||
{
|
||||
@ -545,14 +605,15 @@ cmd_list_free(struct cmd_list *cmdlist)
|
||||
if (--cmdlist->references != 0)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH_SAFE(cmd, &cmdlist->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||
TAILQ_FOREACH_SAFE(cmd, cmdlist->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(cmdlist->list, cmd, qentry);
|
||||
cmd_free(cmd);
|
||||
}
|
||||
|
||||
free(cmdlist->list);
|
||||
free(cmdlist);
|
||||
}
|
||||
|
||||
/* Get a command list as a string. */
|
||||
char *
|
||||
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
{
|
||||
@ -563,7 +624,7 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
len = 1;
|
||||
buf = xcalloc(1, len);
|
||||
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||
this = cmd_print(cmd);
|
||||
|
||||
len += strlen(this) + 4;
|
||||
@ -583,6 +644,54 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* Get first command in list. */
|
||||
struct cmd *
|
||||
cmd_list_first(struct cmd_list *cmdlist, u_int *group)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
cmd = TAILQ_FIRST(cmdlist->list);
|
||||
if (cmd != NULL && group != NULL)
|
||||
*group = cmd->group;
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
/* Get next command in list. */
|
||||
struct cmd *
|
||||
cmd_list_next(struct cmd *cmd, u_int *group)
|
||||
{
|
||||
cmd = TAILQ_NEXT(cmd, qentry);
|
||||
if (cmd != NULL && group != NULL)
|
||||
*group = cmd->group;
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
/* Do all of the commands in this command list have this flag? */
|
||||
int
|
||||
cmd_list_all_have(struct cmd_list *cmdlist, int flag)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||
if (~cmd->entry->flags & flag)
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Do any of the commands in this command list have this flag? */
|
||||
int
|
||||
cmd_list_any_have(struct cmd_list *cmdlist, int flag)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||
if (cmd->entry->flags & flag)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Adjust current mouse position for a pane. */
|
||||
int
|
||||
cmd_mouse_at(struct window_pane *wp, struct mouse_event *m, u_int *xp,
|
||||
|
6
format.c
6
format.c
@ -1128,8 +1128,10 @@ format_create_add_item(struct format_tree *ft, struct cmdq_item *item)
|
||||
struct window_pane *wp;
|
||||
u_int x, y;
|
||||
|
||||
if (item->cmd != NULL)
|
||||
format_add(ft, "command", "%s", item->cmd->entry->name);
|
||||
if (item->cmd != NULL) {
|
||||
format_add(ft, "command", "%s",
|
||||
cmd_get_entry (item->cmd)->name);
|
||||
}
|
||||
|
||||
if (item->shared == NULL)
|
||||
return;
|
||||
|
@ -537,19 +537,13 @@ struct cmdq_item *
|
||||
key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
|
||||
struct client *c, struct mouse_event *m, struct cmd_find_state *fs)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct cmdq_item *new_item;
|
||||
int readonly;
|
||||
|
||||
if (c == NULL || (~c->flags & CLIENT_READONLY))
|
||||
readonly = 1;
|
||||
else {
|
||||
readonly = 1;
|
||||
TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) {
|
||||
if (~cmd->entry->flags & CMD_READONLY)
|
||||
readonly = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
readonly = cmd_list_all_have(bd->cmdlist, CMD_READONLY);
|
||||
if (!readonly)
|
||||
new_item = cmdq_get_callback(key_bindings_read_only, NULL);
|
||||
else {
|
||||
|
49
tmux.h
49
tmux.h
@ -39,9 +39,11 @@ extern char **environ;
|
||||
struct args;
|
||||
struct args_value;
|
||||
struct client;
|
||||
struct cmd;
|
||||
struct cmd_find_state;
|
||||
struct cmdq_item;
|
||||
struct cmdq_list;
|
||||
struct cmds;
|
||||
struct environ;
|
||||
struct format_job_tree;
|
||||
struct format_tree;
|
||||
@ -50,8 +52,8 @@ struct job;
|
||||
struct mode_tree_data;
|
||||
struct mouse_event;
|
||||
struct options;
|
||||
struct options_entry;
|
||||
struct options_array_item;
|
||||
struct options_entry;
|
||||
struct session;
|
||||
struct tmuxpeer;
|
||||
struct tmuxproc;
|
||||
@ -1335,27 +1337,11 @@ struct cmd_find_state {
|
||||
#define CMD_FIND_EXACT_WINDOW 0x20
|
||||
#define CMD_FIND_CANFAIL 0x40
|
||||
|
||||
/* Command and list of commands. */
|
||||
struct cmd {
|
||||
const struct cmd_entry *entry;
|
||||
struct args *args;
|
||||
u_int group;
|
||||
|
||||
char *file;
|
||||
u_int line;
|
||||
|
||||
char *alias;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
TAILQ_ENTRY(cmd) qentry;
|
||||
};
|
||||
TAILQ_HEAD(cmds, cmd);
|
||||
|
||||
/* List of commands. */
|
||||
struct cmd_list {
|
||||
int references;
|
||||
u_int group;
|
||||
struct cmds list;
|
||||
int references;
|
||||
u_int group;
|
||||
struct cmds *list;
|
||||
};
|
||||
|
||||
/* Command return values. */
|
||||
@ -2102,6 +2088,7 @@ int cmd_find_from_mouse(struct cmd_find_state *,
|
||||
int cmd_find_from_nothing(struct cmd_find_state *, int);
|
||||
|
||||
/* cmd.c */
|
||||
extern const struct cmd_entry *cmd_table[];
|
||||
void printflike(3, 4) cmd_log_argv(int, char **, const char *, ...);
|
||||
void cmd_prepend_argv(int *, char ***, char *);
|
||||
void cmd_append_argv(int *, char ***, char *);
|
||||
@ -2111,16 +2098,27 @@ char **cmd_copy_argv(int, char **);
|
||||
void cmd_free_argv(int, char **);
|
||||
char *cmd_stringify_argv(int, char **);
|
||||
char *cmd_get_alias(const char *);
|
||||
const struct cmd_entry *cmd_get_entry(struct cmd *);
|
||||
struct args *cmd_get_args(struct cmd *);
|
||||
void cmd_get_source(struct cmd *, const char **, u_int *);
|
||||
struct cmd *cmd_parse(int, char **, const char *, u_int, char **);
|
||||
void cmd_free(struct cmd *);
|
||||
char *cmd_print(struct cmd *);
|
||||
struct cmd_list *cmd_list_new(void);
|
||||
void cmd_list_append(struct cmd_list *, struct cmd *);
|
||||
void cmd_list_move(struct cmd_list *, struct cmd_list *);
|
||||
void cmd_list_free(struct cmd_list *);
|
||||
char *cmd_list_print(struct cmd_list *, int);
|
||||
struct cmd *cmd_list_first(struct cmd_list *, u_int *);
|
||||
struct cmd *cmd_list_next(struct cmd *, u_int *);
|
||||
int cmd_list_all_have(struct cmd_list *, int);
|
||||
int cmd_list_any_have(struct cmd_list *, int);
|
||||
int cmd_mouse_at(struct window_pane *, struct mouse_event *,
|
||||
u_int *, u_int *, int);
|
||||
struct winlink *cmd_mouse_window(struct mouse_event *, struct session **);
|
||||
struct window_pane *cmd_mouse_pane(struct mouse_event *, struct session **,
|
||||
struct winlink **);
|
||||
char *cmd_template_replace(const char *, const char *, int);
|
||||
extern const struct cmd_entry *cmd_table[];
|
||||
|
||||
/* cmd-attach-session.c */
|
||||
enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
|
||||
@ -2136,13 +2134,6 @@ struct cmd_parse_result *cmd_parse_from_buffer(const void *, size_t,
|
||||
struct cmd_parse_result *cmd_parse_from_arguments(int, char **,
|
||||
struct cmd_parse_input *);
|
||||
|
||||
/* cmd-list.c */
|
||||
struct cmd_list *cmd_list_new(void);
|
||||
void cmd_list_append(struct cmd_list *, struct cmd *);
|
||||
void cmd_list_move(struct cmd_list *, struct cmd_list *);
|
||||
void cmd_list_free(struct cmd_list *);
|
||||
char *cmd_list_print(struct cmd_list *, int);
|
||||
|
||||
/* cmd-queue.c */
|
||||
struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmd_find_state *,
|
||||
struct mouse_event *, int);
|
||||
|
Loading…
Reference in New Issue
Block a user