Refresh session command.

This commit is contained in:
Nicholas Marriott 2007-10-19 09:21:26 +00:00
parent 840b74f6d0
commit 94f003bbec
16 changed files with 201 additions and 66 deletions

View File

@ -1,3 +1,7 @@
19 October 2007
* (nicm) Refresh session command.
12 October 2007
* (nicm) Add a warning if $TMUX exists on new/attach.
@ -127,5 +131,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.41 2007-10-12 14:46:48 nicm Exp $
$Id: CHANGES,v 1.42 2007-10-19 09:21:24 nicm Exp $

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.26 2007-10-12 13:03:58 nicm Exp $
# $Id: Makefile,v 1.27 2007-10-19 09:21:25 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean
@ -22,7 +22,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.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-select-window.c \
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
cmd-refresh-session.c
YACC= yacc -d

2
TODO
View File

@ -48,8 +48,6 @@
- man page
- sort out bell: passing through should be optional
- commands:
refresh session (similar to detach: -a for all, else if key redraw cur,
else do nothing)
rename sessions
swap windows
link/copy windows

View File

@ -1,4 +1,4 @@
/* $Id: cmd-attach-session.c,v 1.6 2007-10-12 14:46:48 nicm Exp $ */
/* $Id: cmd-attach-session.c,v 1.7 2007-10-19 09:21:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,11 +26,11 @@
* Attach existing session to the current terminal.
*/
int cmd_attach_session_parse(void **, int, char **, char **);
void cmd_attach_session_exec(void *, struct cmd_ctx *);
void cmd_attach_session_send(void *, struct buffer *);
void cmd_attach_session_recv(void **, struct buffer *);
void cmd_attach_session_free(void *);
int cmd_attach_session_parse(void **, int, char **, char **);
void cmd_attach_session_exec(void *, struct cmd_ctx *);
void cmd_attach_session_send(void *, struct buffer *);
void cmd_attach_session_recv(void **, struct buffer *);
void cmd_attach_session_free(void *);
struct cmd_attach_session_data {
int flag_detach;

View File

@ -1,4 +1,4 @@
/* $Id: cmd-bind-key.c,v 1.4 2007-10-04 22:04:01 nicm Exp $ */
/* $Id: cmd-bind-key.c,v 1.5 2007-10-19 09:21:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,11 +26,11 @@
* Bind a key to a command, this recurses through cmd_*.
*/
int cmd_bind_key_parse(void **, int, char **, char **);
void cmd_bind_key_exec(void *, struct cmd_ctx *);
void cmd_bind_key_send(void *, struct buffer *);
void cmd_bind_key_recv(void **, struct buffer *);
void cmd_bind_key_free(void *);
int cmd_bind_key_parse(void **, int, char **, char **);
void cmd_bind_key_exec(void *, struct cmd_ctx *);
void cmd_bind_key_send(void *, struct buffer *);
void cmd_bind_key_recv(void **, struct buffer *);
void cmd_bind_key_free(void *);
struct cmd_bind_key_data {
int key;

View File

@ -1,4 +1,4 @@
/* $Id: cmd-detach-session.c,v 1.5 2007-10-04 22:04:01 nicm Exp $ */
/* $Id: cmd-detach-session.c,v 1.6 2007-10-19 09:21:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,11 +27,11 @@
* session, otherwise detach current session on key press only.
*/
int cmd_detach_session_parse(void **, int, char **, char **);
void cmd_detach_session_exec(void *, struct cmd_ctx *);
void cmd_detach_session_send(void *, struct buffer *);
void cmd_detach_session_recv(void **, struct buffer *);
void cmd_detach_session_free(void *);
int cmd_detach_session_parse(void **, int, char **, char **);
void cmd_detach_session_exec(void *, struct cmd_ctx *);
void cmd_detach_session_send(void *, struct buffer *);
void cmd_detach_session_recv(void **, struct buffer *);
void cmd_detach_session_free(void *);
struct cmd_detach_session_data {
int flag_all;

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-session.c,v 1.11 2007-10-12 14:46:48 nicm Exp $ */
/* $Id: cmd-new-session.c,v 1.12 2007-10-19 09:21:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,11 +26,11 @@
* Create a new session and attach to the current terminal unless -d is given.
*/
int cmd_new_session_parse(void **, int, char **, char **);
void cmd_new_session_exec(void *, struct cmd_ctx *);
void cmd_new_session_send(void *, struct buffer *);
void cmd_new_session_recv(void **, struct buffer *);
void cmd_new_session_free(void *);
int cmd_new_session_parse(void **, int, char **, char **);
void cmd_new_session_exec(void *, struct cmd_ctx *);
void cmd_new_session_send(void *, struct buffer *);
void cmd_new_session_recv(void **, struct buffer *);
void cmd_new_session_free(void *);
struct cmd_new_session_data {
char *name;

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-window.c,v 1.8 2007-10-12 11:24:15 nicm Exp $ */
/* $Id: cmd-new-window.c,v 1.9 2007-10-19 09:21:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,11 +26,11 @@
* Create a new window.
*/
int cmd_new_window_parse(void **, int, char **, char **);
void cmd_new_window_exec(void *, struct cmd_ctx *);
void cmd_new_window_send(void *, struct buffer *);
void cmd_new_window_recv(void **, struct buffer *);
void cmd_new_window_free(void *);
int cmd_new_window_parse(void **, int, char **, char **);
void cmd_new_window_exec(void *, struct cmd_ctx *);
void cmd_new_window_send(void *, struct buffer *);
void cmd_new_window_recv(void **, struct buffer *);
void cmd_new_window_free(void *);
struct cmd_new_window_data {
char *name;

131
cmd-refresh-session.c Normal file
View File

@ -0,0 +1,131 @@
/* $Id: cmd-refresh-session.c,v 1.1 2007-10-19 09:21:25 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 "tmux.h"
/*
* Refresh session. If called with -a refresh all clients attached to specified
* session, otherwise refresh current session on key press only.
*/
int cmd_refresh_session_parse(void **, int, char **, char **);
void cmd_refresh_session_exec(void *, struct cmd_ctx *);
void cmd_refresh_session_send(void *, struct buffer *);
void cmd_refresh_session_recv(void **, struct buffer *);
void cmd_refresh_session_free(void *);
struct cmd_refresh_session_data {
int flag_all;
};
const struct cmd_entry cmd_refresh_session_entry = {
"refresh-session", "refresh", "[-a]",
0,
cmd_refresh_session_parse,
cmd_refresh_session_exec,
cmd_refresh_session_send,
cmd_refresh_session_recv,
cmd_refresh_session_free
};
int
cmd_refresh_session_parse(void **ptr, int argc, char **argv, char **cause)
{
struct cmd_refresh_session_data *data;
int opt;
*ptr = data = xmalloc(sizeof *data);
data->flag_all = 0;
while ((opt = getopt(argc, argv, "a")) != EOF) {
switch (opt) {
case 'a':
data->flag_all = 1;
break;
default:
goto usage;
}
}
argc -= optind;
argv += optind;
if (argc != 0)
goto usage;
return (0);
usage:
usage(cause, "%s %s",
cmd_refresh_session_entry.name, cmd_refresh_session_entry.usage);
cmd_refresh_session_free(data);
return (-1);
}
void
cmd_refresh_session_exec(void *ptr, struct cmd_ctx *ctx)
{
struct cmd_refresh_session_data *data = ptr, std = { 0 };
struct client *c = ctx->client, *cp;
struct session *s = ctx->session;
u_int i;
if (data == NULL)
data = &std;
if (data->flag_all) {
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
cp = ARRAY_ITEM(&clients, i);
if (cp == NULL || cp->session != s)
continue;
server_redraw_client(cp);
}
} else if (ctx->flags & CMD_KEY)
server_redraw_client(c);
if (!(ctx->flags & CMD_KEY))
server_write_client(c, MSG_EXIT, NULL, 0);
}
void
cmd_refresh_session_send(void *ptr, struct buffer *b)
{
struct cmd_refresh_session_data *data = ptr;
buffer_write(b, data, sizeof *data);
}
void
cmd_refresh_session_recv(void **ptr, struct buffer *b)
{
struct cmd_refresh_session_data *data;
*ptr = data = xmalloc(sizeof *data);
buffer_read(b, data, sizeof *data);
}
void
cmd_refresh_session_free(void *ptr)
{
struct cmd_refresh_session_data *data = ptr;
xfree(data);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-rename-window.c,v 1.5 2007-10-12 11:24:15 nicm Exp $ */
/* $Id: cmd-rename-window.c,v 1.6 2007-10-19 09:21:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,11 +27,11 @@
* Rename window by index.
*/
int cmd_rename_window_parse(void **, int, char **, char **);
void cmd_rename_window_exec(void *, struct cmd_ctx *);
void cmd_rename_window_send(void *, struct buffer *);
void cmd_rename_window_recv(void **, struct buffer *);
void cmd_rename_window_free(void *);
int cmd_rename_window_parse(void **, int, char **, char **);
void cmd_rename_window_exec(void *, struct cmd_ctx *);
void cmd_rename_window_send(void *, struct buffer *);
void cmd_rename_window_recv(void **, struct buffer *);
void cmd_rename_window_free(void *);
struct cmd_rename_window_data {
int idx;

View File

@ -1,4 +1,4 @@
/* $Id: cmd-select-window.c,v 1.3 2007-10-04 22:04:01 nicm Exp $ */
/* $Id: cmd-select-window.c,v 1.4 2007-10-19 09:21:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,11 +27,11 @@
* Select window by index.
*/
int cmd_select_window_parse(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 *);
int cmd_select_window_parse(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 {
u_int idx;

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-option.c,v 1.7 2007-10-12 13:51:44 nicm Exp $ */
/* $Id: cmd-set-option.c,v 1.8 2007-10-19 09:21:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,12 +28,11 @@
* Set an option.
*/
int cmd_set_option_parse(void **, int, char **, char **);
const char *cmd_set_option_usage(void);
void cmd_set_option_exec(void *, struct cmd_ctx *);
void cmd_set_option_send(void *, struct buffer *);
void cmd_set_option_recv(void **, struct buffer *);
void cmd_set_option_free(void *);
int cmd_set_option_parse(void **, int, char **, char **);
void cmd_set_option_exec(void *, struct cmd_ctx *);
void cmd_set_option_send(void *, struct buffer *);
void cmd_set_option_recv(void **, struct buffer *);
void cmd_set_option_free(void *);
struct cmd_set_option_data {
char *option;

View File

@ -1,4 +1,4 @@
/* $Id: cmd-unbind-key.c,v 1.4 2007-10-04 22:04:01 nicm Exp $ */
/* $Id: cmd-unbind-key.c,v 1.5 2007-10-19 09:21:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,12 +26,11 @@
* Unbind key from command.
*/
int cmd_unbind_key_parse(void **, int, char **, char **);
const char *cmd_unbind_key_usage(void);
void cmd_unbind_key_exec(void *, struct cmd_ctx *);
void cmd_unbind_key_send(void *, struct buffer *);
void cmd_unbind_key_recv(void **, struct buffer *);
void cmd_unbind_key_free(void *);
int cmd_unbind_key_parse(void **, int, char **, char **);
void cmd_unbind_key_exec(void *, struct cmd_ctx *);
void cmd_unbind_key_send(void *, struct buffer *);
void cmd_unbind_key_recv(void **, struct buffer *);
void cmd_unbind_key_free(void *);
struct cmd_unbind_key_data {
int key;

3
cmd.c
View File

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.16 2007-10-12 13:51:44 nicm Exp $ */
/* $Id: cmd.c,v 1.17 2007-10-19 09:21:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -35,6 +35,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_new_window_entry,
&cmd_next_window_entry,
&cmd_previous_window_entry,
&cmd_refresh_session_entry,
&cmd_rename_window_entry,
&cmd_select_window_entry,
&cmd_send_prefix_entry,

View File

@ -1,4 +1,4 @@
/* $Id: key-bindings.c,v 1.8 2007-10-12 13:03:58 nicm Exp $ */
/* $Id: key-bindings.c,v 1.9 2007-10-19 09:21:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -103,9 +103,10 @@ key_bindings_init(void)
{ '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_session_entry, NULL },
{ 'r', &cmd_refresh_session_entry, NULL },
{ META, &cmd_send_prefix_entry, NULL },
/* { '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 },

3
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.58 2007-10-12 14:46:48 nicm Exp $ */
/* $Id: tmux.h,v 1.59 2007-10-19 09:21:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -524,6 +524,7 @@ extern const struct cmd_entry cmd_new_session_entry;
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_refresh_session_entry;
extern const struct cmd_entry cmd_rename_window_entry;
extern const struct cmd_entry cmd_select_window_entry;
extern const struct cmd_entry cmd_send_prefix_entry;