aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-10-04 10:54:21 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-10-04 10:54:21 +0000
commit225e07fe38ecf4755cdcd38664d82a5611c0b5ac (patch)
tree8c79d3fab479339de88b0275a386805fee4fa166
parent19c1e1a800da9bee277f3db619262a0c2ce3fbc7 (diff)
downloadrtmux-225e07fe38ecf4755cdcd38664d82a5611c0b5ac.tar.gz
rtmux-225e07fe38ecf4755cdcd38664d82a5611c0b5ac.tar.bz2
rtmux-225e07fe38ecf4755cdcd38664d82a5611c0b5ac.zip
Select window command.
-rw-r--r--CHANGES4
-rw-r--r--Makefile4
-rw-r--r--TODO2
-rw-r--r--cmd-rename-window.c4
-rw-r--r--cmd-select-window.c149
-rw-r--r--cmd.c3
-rw-r--r--key-bindings.c53
-rw-r--r--tmux.h5
8 files changed, 190 insertions, 34 deletions
diff --git a/CHANGES b/CHANGES
index 38ed7279..507c7858 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,6 @@
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) Key binding and unbinding is back.
@@ -110,5 +110,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
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 $
diff --git a/Makefile b/Makefile
index 1b3c6dcd..31127c64 100644
--- a/Makefile
+++ b/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
.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 \
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-set-option.c cmd-rename-window.c
+ cmd-set-option.c cmd-rename-window.c cmd-select-window.c
YACC= yacc -d
diff --git a/TODO b/TODO
index b15d93c7..f987c576 100644
--- a/TODO
+++ b/TODO
@@ -43,7 +43,7 @@
-- For 0.1 --------------------------------------------------------------------
- man page
- commands:
- rename windows
+ refresh client
rename sessions
swap windows
link/copy windows
diff --git a/cmd-rename-window.c b/cmd-rename-window.c
index f0262b9c..461bcd9b 100644
--- a/cmd-rename-window.c
+++ b/cmd-rename-window.c
@@ -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>
@@ -111,7 +111,7 @@ cmd_rename_window_exec(void *ptr, struct cmd_ctx *ctx)
if (data->idx == -1)
w = s->window;
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;
}
xfree(w->name);
diff --git a/cmd-select-window.c b/cmd-select-window.c
new file mode 100644
index 00000000..9f29202b
--- /dev/null
+++ b/cmd-select-window.c
@@ -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);
+}
diff --git a/cmd.c b/cmd.c
index 4adc8eeb..8b5cb649 100644
--- a/cmd.c
+++ b/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>
@@ -34,6 +34,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_next_window_entry,
&cmd_previous_window_entry,
&cmd_rename_window_entry,
+ &cmd_select_window_entry,
&cmd_set_option_entry,
&cmd_unbind_key_entry,
NULL
diff --git a/key-bindings.c b/key-bindings.c
index 0c802a95..6103fe14 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -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>
@@ -75,36 +75,37 @@ key_bindings_init(void)
struct {
int key;
const struct cmd_entry *entry;
+ void (*fn)(void **, int);
} table[] = {
- { 'D', &cmd_detach_session_entry },
- { 'd', &cmd_detach_session_entry },
- { 'S', &cmd_list_sessions_entry },
- { 's', &cmd_list_sessions_entry },
- { '?', &cmd_list_keys_entry },
- { '/', &cmd_list_keys_entry },
- { 'C', &cmd_new_window_entry },
- { 'c', &cmd_new_window_entry },
- { 'N', &cmd_next_window_entry },
- { 'n', &cmd_next_window_entry },
- { 'P', &cmd_previous_window_entry },
- { 'p', &cmd_previous_window_entry },
- { 'L', &cmd_last_window_entry },
- { 'l', &cmd_last_window_entry },
+ { 'D', &cmd_detach_session_entry, NULL },
+ { 'd', &cmd_detach_session_entry, NULL },
+ { 'S', &cmd_list_sessions_entry, NULL },
+ { 's', &cmd_list_sessions_entry, NULL },
+ { '?', &cmd_list_keys_entry, NULL },
+ { '/', &cmd_list_keys_entry, NULL },
+ { 'C', &cmd_new_window_entry, NULL },
+ { 'c', &cmd_new_window_entry, NULL },
+ { 'N', &cmd_next_window_entry, NULL },
+ { 'n', &cmd_next_window_entry, NULL },
+ { 'P', &cmd_previous_window_entry, NULL },
+ { 'p', &cmd_previous_window_entry, NULL },
+ { 'L', &cmd_last_window_entry, NULL },
+ { '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 },
{ 'I', &cmd_windo_info_entry },
{ 'i', &cmd_window_info_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;
@@ -116,6 +117,8 @@ key_bindings_init(void)
cmd = xmalloc(sizeof *cmd);
cmd->entry = table[i].entry;
cmd->data = NULL;
+ if (table[i].fn != NULL)
+ table[i].fn(&cmd->data, table[i].key);
key_bindings_add(table[i].key, cmd);
}
}
diff --git a/tmux.h b/tmux.h
index 2d7e5262..94ad6253 100644
--- a/tmux.h
+++ b/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>
@@ -467,6 +467,7 @@ enum cmd_type {
CMD_NEXTWINDOW,
CMD_PREVIOUSWINDOW,
CMD_RENAMEWINDOW,
+ CMD_SELECTWINDOW,
CMD_SETOPTION,
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_previous_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_unbind_key_entry;