mirror of
https://github.com/tmate-io/tmate.git
synced 2025-08-13 23:38:52 +02:00
Move -s and -c down a level so handling them is the responsibility of the command (with some helper functions), rather than the top-level. This changes the action command syntax so that -s and -c must be after the command rather than before.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-select-window.c,v 1.11 2007-12-06 09:46:22 nicm Exp $ */
|
||||
/* $Id: cmd-select-window.c,v 1.12 2008-06-02 18:08:16 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -27,19 +27,21 @@
|
||||
* Select window by index.
|
||||
*/
|
||||
|
||||
int cmd_select_window_parse(void **, int, char **, char **);
|
||||
int cmd_select_window_parse(struct cmd *, void **, int, char **, char **);
|
||||
void cmd_select_window_exec(void *, struct cmd_ctx *);
|
||||
void cmd_select_window_send(void *, struct buffer *);
|
||||
void cmd_select_window_recv(void **, struct buffer *);
|
||||
void cmd_select_window_free(void *);
|
||||
|
||||
struct cmd_select_window_data {
|
||||
char *sname;
|
||||
int idx;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_select_window_entry = {
|
||||
"select-window", "selectw", "index",
|
||||
CMD_NOCLIENT,
|
||||
"select-window", "selectw",
|
||||
"[-s session-name] index",
|
||||
0,
|
||||
cmd_select_window_parse,
|
||||
cmd_select_window_exec,
|
||||
cmd_select_window_send,
|
||||
@ -58,20 +60,26 @@ cmd_select_window_default(void **ptr, int key)
|
||||
struct cmd_select_window_data *data;
|
||||
|
||||
*ptr = data = xmalloc(sizeof *data);
|
||||
data->sname = NULL;
|
||||
data->idx = key - '0';
|
||||
}
|
||||
|
||||
int
|
||||
cmd_select_window_parse(void **ptr, int argc, char **argv, char **cause)
|
||||
cmd_select_window_parse(
|
||||
struct cmd *self, void **ptr, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_select_window_data *data;
|
||||
const char *errstr;
|
||||
int opt;
|
||||
|
||||
*ptr = data = xmalloc(sizeof *data);
|
||||
data->sname = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "")) != EOF) {
|
||||
while ((opt = getopt(argc, argv, "s:")) != EOF) {
|
||||
switch (opt) {
|
||||
case 's':
|
||||
data->sname = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
@ -90,8 +98,7 @@ cmd_select_window_parse(void **ptr, int argc, char **argv, char **cause)
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
usage(cause, "%s %s",
|
||||
cmd_select_window_entry.name, cmd_select_window_entry.usage);
|
||||
usage(cause, "%s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
error:
|
||||
cmd_select_window_free(data);
|
||||
@ -102,13 +109,17 @@ void
|
||||
cmd_select_window_exec(void *ptr, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_select_window_data *data = ptr;
|
||||
struct session *s;
|
||||
|
||||
if (data == NULL)
|
||||
return;
|
||||
|
||||
switch (session_select(ctx->session, data->idx)) {
|
||||
if ((s = cmd_find_session(ctx, data->sname)) == NULL)
|
||||
return;
|
||||
|
||||
switch (session_select(s, data->idx)) {
|
||||
case 0:
|
||||
server_redraw_session(ctx->session);
|
||||
server_redraw_session(s);
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
@ -127,6 +138,7 @@ cmd_select_window_send(void *ptr, struct buffer *b)
|
||||
struct cmd_select_window_data *data = ptr;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->sname);
|
||||
}
|
||||
|
||||
void
|
||||
@ -136,6 +148,7 @@ cmd_select_window_recv(void **ptr, struct buffer *b)
|
||||
|
||||
*ptr = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->sname = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
@ -143,5 +156,7 @@ cmd_select_window_free(void *ptr)
|
||||
{
|
||||
struct cmd_select_window_data *data = ptr;
|
||||
|
||||
if (data->sname != NULL)
|
||||
xfree(data->sname);
|
||||
xfree(data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user