mirror of
https://github.com/tmate-io/tmate.git
synced 2025-01-12 08:58:12 +01:00
Select window command.
This commit is contained in:
parent
19c1e1a800
commit
225e07fe38
4
CHANGES
4
CHANGES
@ -1,6 +1,6 @@
|
|||||||
04 October 2007
|
04 October 2007
|
||||||
|
|
||||||
* (nicm) rename-window command.
|
* (nicm) rename-window and select-window commands.
|
||||||
* (nicm) set-option command (alias set): "tmux set-option prefix ^A".
|
* (nicm) set-option command (alias set): "tmux set-option prefix ^A".
|
||||||
* (nicm) Key binding and unbinding is back.
|
* (nicm) Key binding and unbinding is back.
|
||||||
|
|
||||||
@ -110,5 +110,5 @@
|
|||||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||||
customisation.
|
customisation.
|
||||||
|
|
||||||
$Id: CHANGES,v 1.29 2007-10-04 10:39:06 nicm Exp $
|
$Id: CHANGES,v 1.30 2007-10-04 10:54:20 nicm Exp $
|
||||||
|
|
||||||
|
4
Makefile
4
Makefile
@ -1,4 +1,4 @@
|
|||||||
# $Id: Makefile,v 1.19 2007-10-04 10:39:06 nicm Exp $
|
# $Id: Makefile,v 1.20 2007-10-04 10:54:20 nicm Exp $
|
||||||
|
|
||||||
.SUFFIXES: .c .o .y .h
|
.SUFFIXES: .c .o .y .h
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
@ -22,7 +22,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
|
|||||||
key-bindings.c cmd.c cmd-new-session.c cmd-detach-session.c \
|
key-bindings.c cmd.c cmd-new-session.c cmd-detach-session.c \
|
||||||
cmd-list-sessions.c cmd-new-window.c cmd-next-window.c cmd-bind-key.c \
|
cmd-list-sessions.c cmd-new-window.c cmd-next-window.c cmd-bind-key.c \
|
||||||
cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.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-set-option.c cmd-rename-window.c cmd-select-window.c
|
||||||
|
|
||||||
YACC= yacc -d
|
YACC= yacc -d
|
||||||
|
|
||||||
|
2
TODO
2
TODO
@ -43,7 +43,7 @@
|
|||||||
-- For 0.1 --------------------------------------------------------------------
|
-- For 0.1 --------------------------------------------------------------------
|
||||||
- man page
|
- man page
|
||||||
- commands:
|
- commands:
|
||||||
rename windows
|
refresh client
|
||||||
rename sessions
|
rename sessions
|
||||||
swap windows
|
swap windows
|
||||||
link/copy windows
|
link/copy windows
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-rename-window.c,v 1.1 2007-10-04 10:39:06 nicm Exp $ */
|
/* $Id: cmd-rename-window.c,v 1.2 2007-10-04 10:54:20 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -111,7 +111,7 @@ cmd_rename_window_exec(void *ptr, struct cmd_ctx *ctx)
|
|||||||
if (data->idx == -1)
|
if (data->idx == -1)
|
||||||
w = s->window;
|
w = s->window;
|
||||||
else if ((w = window_at(&s->windows, data->idx)) == NULL) {
|
else if ((w = window_at(&s->windows, data->idx)) == NULL) {
|
||||||
ctx->error(ctx, "no window at index %u", data->idx);
|
ctx->error(ctx, "no window %u", data->idx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xfree(w->name);
|
xfree(w->name);
|
||||||
|
149
cmd-select-window.c
Normal file
149
cmd-select-window.c
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/* $Id: cmd-select-window.c,v 1.1 2007-10-04 10:54:20 nicm Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <getopt.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Select window by index.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_select_window_parse(void **, int, char **, char **);
|
||||||
|
const char *cmd_select_window_usage(void);
|
||||||
|
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 {
|
||||||
|
u_int idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_select_window_entry = {
|
||||||
|
CMD_SELECTWINDOW, "select-window", "selectw", 0,
|
||||||
|
cmd_select_window_parse,
|
||||||
|
cmd_select_window_usage,
|
||||||
|
cmd_select_window_exec,
|
||||||
|
cmd_select_window_send,
|
||||||
|
cmd_select_window_recv,
|
||||||
|
cmd_select_window_free
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* select-window requires different defaults depending on the key, so this
|
||||||
|
* fills in the right data. XXX should this be extended to them all and get
|
||||||
|
* rid of std/NULL rubbish?
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
cmd_select_window_default(void **ptr, int key)
|
||||||
|
{
|
||||||
|
struct cmd_select_window_data *data;
|
||||||
|
|
||||||
|
*ptr = data = xmalloc(sizeof *data);
|
||||||
|
data->idx = key - '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_select_window_parse(void **ptr, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_select_window_data *data;
|
||||||
|
const char *errstr;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
*ptr = data = xmalloc(sizeof *data);
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "")) != EOF) {
|
||||||
|
switch (opt) {
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
data->idx = strtonum(argv[0], 0, UINT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "index %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
usage(cause, "%s", cmd_select_window_usage());
|
||||||
|
|
||||||
|
error:
|
||||||
|
cmd_select_window_free(data);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
cmd_select_window_usage(void)
|
||||||
|
{
|
||||||
|
return ("select-window [command]");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_select_window_exec(void *ptr, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_select_window_data *data = ptr;
|
||||||
|
struct client *c = ctx->client;
|
||||||
|
struct session *s = ctx->session;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (session_select(s, data->idx) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
else
|
||||||
|
ctx->error(ctx, "no window %u", data->idx);
|
||||||
|
|
||||||
|
if (!(ctx->flags & CMD_KEY))
|
||||||
|
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_select_window_send(void *ptr, struct buffer *b)
|
||||||
|
{
|
||||||
|
struct cmd_select_window_data *data = ptr;
|
||||||
|
|
||||||
|
buffer_write(b, data, sizeof *data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_select_window_recv(void **ptr, struct buffer *b)
|
||||||
|
{
|
||||||
|
struct cmd_select_window_data *data;
|
||||||
|
|
||||||
|
*ptr = data = xmalloc(sizeof *data);
|
||||||
|
buffer_read(b, data, sizeof *data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_select_window_free(void *ptr)
|
||||||
|
{
|
||||||
|
struct cmd_select_window_data *data = ptr;
|
||||||
|
|
||||||
|
xfree(data);
|
||||||
|
}
|
3
cmd.c
3
cmd.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd.c,v 1.9 2007-10-04 10:39:07 nicm Exp $ */
|
/* $Id: cmd.c,v 1.10 2007-10-04 10:54:21 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -34,6 +34,7 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
&cmd_next_window_entry,
|
&cmd_next_window_entry,
|
||||||
&cmd_previous_window_entry,
|
&cmd_previous_window_entry,
|
||||||
&cmd_rename_window_entry,
|
&cmd_rename_window_entry,
|
||||||
|
&cmd_select_window_entry,
|
||||||
&cmd_set_option_entry,
|
&cmd_set_option_entry,
|
||||||
&cmd_unbind_key_entry,
|
&cmd_unbind_key_entry,
|
||||||
NULL
|
NULL
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: key-bindings.c,v 1.4 2007-10-04 00:18:59 nicm Exp $ */
|
/* $Id: key-bindings.c,v 1.5 2007-10-04 10:54:21 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -75,36 +75,37 @@ key_bindings_init(void)
|
|||||||
struct {
|
struct {
|
||||||
int key;
|
int key;
|
||||||
const struct cmd_entry *entry;
|
const struct cmd_entry *entry;
|
||||||
|
void (*fn)(void **, int);
|
||||||
} table[] = {
|
} table[] = {
|
||||||
{ 'D', &cmd_detach_session_entry },
|
{ 'D', &cmd_detach_session_entry, NULL },
|
||||||
{ 'd', &cmd_detach_session_entry },
|
{ 'd', &cmd_detach_session_entry, NULL },
|
||||||
{ 'S', &cmd_list_sessions_entry },
|
{ 'S', &cmd_list_sessions_entry, NULL },
|
||||||
{ 's', &cmd_list_sessions_entry },
|
{ 's', &cmd_list_sessions_entry, NULL },
|
||||||
{ '?', &cmd_list_keys_entry },
|
{ '?', &cmd_list_keys_entry, NULL },
|
||||||
{ '/', &cmd_list_keys_entry },
|
{ '/', &cmd_list_keys_entry, NULL },
|
||||||
{ 'C', &cmd_new_window_entry },
|
{ 'C', &cmd_new_window_entry, NULL },
|
||||||
{ 'c', &cmd_new_window_entry },
|
{ 'c', &cmd_new_window_entry, NULL },
|
||||||
{ 'N', &cmd_next_window_entry },
|
{ 'N', &cmd_next_window_entry, NULL },
|
||||||
{ 'n', &cmd_next_window_entry },
|
{ 'n', &cmd_next_window_entry, NULL },
|
||||||
{ 'P', &cmd_previous_window_entry },
|
{ 'P', &cmd_previous_window_entry, NULL },
|
||||||
{ 'p', &cmd_previous_window_entry },
|
{ 'p', &cmd_previous_window_entry, NULL },
|
||||||
{ 'L', &cmd_last_window_entry },
|
{ 'L', &cmd_last_window_entry, NULL },
|
||||||
{ 'l', &cmd_last_window_entry },
|
{ 'l', &cmd_last_window_entry, NULL },
|
||||||
|
{ '0', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '1', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '2', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '3', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '4', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '5', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '6', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '7', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '8', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
|
{ '9', &cmd_select_window_entry, cmd_select_window_default },
|
||||||
/* { 'R', &cmd_refresh_client_entry },
|
/* { 'R', &cmd_refresh_client_entry },
|
||||||
{ 'r', &cmd_refresh_client_entry },
|
{ 'r', &cmd_refresh_client_entry },
|
||||||
{ 'I', &cmd_windo_info_entry },
|
{ 'I', &cmd_windo_info_entry },
|
||||||
{ 'i', &cmd_window_info_entry },
|
{ 'i', &cmd_window_info_entry },
|
||||||
{ META, &cmd_meta_entry_entry },
|
{ META, &cmd_meta_entry_entry },
|
||||||
*//* { '0', cmdx_fn_select, 0, NULL },
|
|
||||||
{ '1', cmdx_fn_select, 1, NULL },
|
|
||||||
{ '2', cmdx_fn_select, 2, NULL },
|
|
||||||
{ '3', cmdx_fn_select, 3, NULL },
|
|
||||||
{ '4', cmdx_fn_select, 4, NULL },
|
|
||||||
{ '5', cmdx_fn_select, 5, NULL },
|
|
||||||
{ '6', cmdx_fn_select, 6, NULL },
|
|
||||||
{ '7', cmdx_fn_select, 7, NULL },
|
|
||||||
{ '8', cmdx_fn_select, 8, NULL },
|
|
||||||
{ '9', cmdx_fn_select, 9, NULL },
|
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
u_int i;
|
u_int i;
|
||||||
@ -116,6 +117,8 @@ key_bindings_init(void)
|
|||||||
cmd = xmalloc(sizeof *cmd);
|
cmd = xmalloc(sizeof *cmd);
|
||||||
cmd->entry = table[i].entry;
|
cmd->entry = table[i].entry;
|
||||||
cmd->data = NULL;
|
cmd->data = NULL;
|
||||||
|
if (table[i].fn != NULL)
|
||||||
|
table[i].fn(&cmd->data, table[i].key);
|
||||||
key_bindings_add(table[i].key, cmd);
|
key_bindings_add(table[i].key, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
tmux.h
5
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.44 2007-10-04 10:39:07 nicm Exp $ */
|
/* $Id: tmux.h,v 1.45 2007-10-04 10:54:21 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -467,6 +467,7 @@ enum cmd_type {
|
|||||||
CMD_NEXTWINDOW,
|
CMD_NEXTWINDOW,
|
||||||
CMD_PREVIOUSWINDOW,
|
CMD_PREVIOUSWINDOW,
|
||||||
CMD_RENAMEWINDOW,
|
CMD_RENAMEWINDOW,
|
||||||
|
CMD_SELECTWINDOW,
|
||||||
CMD_SETOPTION,
|
CMD_SETOPTION,
|
||||||
CMD_UNBINDKEY,
|
CMD_UNBINDKEY,
|
||||||
};
|
};
|
||||||
@ -541,6 +542,8 @@ extern const struct cmd_entry cmd_new_window_entry;
|
|||||||
extern const struct cmd_entry cmd_next_window_entry;
|
extern const struct cmd_entry cmd_next_window_entry;
|
||||||
extern const struct cmd_entry cmd_previous_window_entry;
|
extern const struct cmd_entry cmd_previous_window_entry;
|
||||||
extern const struct cmd_entry cmd_rename_window_entry;
|
extern const struct cmd_entry cmd_rename_window_entry;
|
||||||
|
extern const struct cmd_entry cmd_select_window_entry;
|
||||||
|
void cmd_select_window_default(void **, int);
|
||||||
extern const struct cmd_entry cmd_set_option_entry;
|
extern const struct cmd_entry cmd_set_option_entry;
|
||||||
extern const struct cmd_entry cmd_unbind_key_entry;
|
extern const struct cmd_entry cmd_unbind_key_entry;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user