mirror of
https://github.com/tmate-io/tmate.git
synced 2025-01-11 16:38:47 +01:00
Kill window command. Nuke some backspace stuff.
This commit is contained in:
parent
de24fbb35c
commit
1b9647669a
4
CHANGES
4
CHANGES
@ -1,5 +1,7 @@
|
||||
19 October 2007
|
||||
|
||||
* (nicm) kill-window command, bound to & by default (because it should be hard
|
||||
to hit accidently).
|
||||
* (nicm) bell-style option with three choices: "none" completely ignore bell;
|
||||
"any" pass through a bell in any window to current; "current" ignore bells
|
||||
except in current window. This applies only to the bell terminal signal,
|
||||
@ -135,5 +137,5 @@
|
||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||
customisation.
|
||||
|
||||
$Id: CHANGES,v 1.43 2007-10-19 10:21:24 nicm Exp $
|
||||
$Id: CHANGES,v 1.44 2007-10-19 11:10:34 nicm Exp $
|
||||
|
||||
|
4
Makefile
4
Makefile
@ -1,4 +1,4 @@
|
||||
# $Id: Makefile,v 1.27 2007-10-19 09:21:25 nicm Exp $
|
||||
# $Id: Makefile,v 1.28 2007-10-19 11:10:34 nicm Exp $
|
||||
|
||||
.SUFFIXES: .c .o .y .h
|
||||
.PHONY: clean
|
||||
@ -23,7 +23,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.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-refresh-session.c
|
||||
cmd-refresh-session.c cmd-kill-window.c
|
||||
|
||||
YACC= yacc -d
|
||||
|
||||
|
1
TODO
1
TODO
@ -51,7 +51,6 @@
|
||||
swap windows
|
||||
link/copy windows
|
||||
unlink window (error if window only linked to one session)
|
||||
kill window (C-b backsp)
|
||||
kill session (no not bind by default)
|
||||
set shell
|
||||
- check for some reqd terminfo caps on startup
|
||||
|
148
cmd-kill-window.c
Normal file
148
cmd-kill-window.c
Normal file
@ -0,0 +1,148 @@
|
||||
/* $Id: cmd-kill-window.c,v 1.1 2007-10-19 11:10:35 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"
|
||||
|
||||
/*
|
||||
* Destroy window.
|
||||
*/
|
||||
|
||||
int cmd_kill_window_parse(void **, int, char **, char **);
|
||||
void cmd_kill_window_exec(void *, struct cmd_ctx *);
|
||||
void cmd_kill_window_send(void *, struct buffer *);
|
||||
void cmd_kill_window_recv(void **, struct buffer *);
|
||||
void cmd_kill_window_free(void *);
|
||||
|
||||
struct cmd_kill_window_data {
|
||||
int idx;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_kill_window_entry = {
|
||||
"kill-window", "killw", "[-i index]",
|
||||
0,
|
||||
cmd_kill_window_parse,
|
||||
cmd_kill_window_exec,
|
||||
cmd_kill_window_send,
|
||||
cmd_kill_window_recv,
|
||||
cmd_kill_window_free
|
||||
};
|
||||
|
||||
int
|
||||
cmd_kill_window_parse(void **ptr, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_kill_window_data *data;
|
||||
const char *errstr;
|
||||
int opt;
|
||||
|
||||
*ptr = data = xmalloc(sizeof *data);
|
||||
data->idx = -1;
|
||||
|
||||
while ((opt = getopt(argc, argv, "i:")) != EOF) {
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
data->idx = strtonum(optarg, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "index %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 0)
|
||||
goto usage;
|
||||
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
usage(cause, "%s %s",
|
||||
cmd_kill_window_entry.name, cmd_kill_window_entry.usage);
|
||||
|
||||
error:
|
||||
cmd_kill_window_free(data);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_kill_window_data *data = ptr, std = { -1 };
|
||||
struct client *c = ctx->client;
|
||||
struct session *s = ctx->session;
|
||||
struct window *w;
|
||||
u_int i;
|
||||
int destroyed;
|
||||
|
||||
if (data == NULL)
|
||||
data = &std;
|
||||
|
||||
if (data->idx == -1)
|
||||
w = s->window;
|
||||
else if ((w = window_at(&s->windows, data->idx)) == NULL) {
|
||||
ctx->error(ctx, "no window %u", data->idx);
|
||||
return;
|
||||
}
|
||||
|
||||
destroyed = session_detach(s, w);
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != s)
|
||||
continue;
|
||||
if (destroyed) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else
|
||||
server_redraw_client(c);
|
||||
}
|
||||
|
||||
if (!(ctx->flags & CMD_KEY))
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_kill_window_send(void *ptr, struct buffer *b)
|
||||
{
|
||||
struct cmd_kill_window_data *data = ptr;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_kill_window_recv(void **ptr, struct buffer *b)
|
||||
{
|
||||
struct cmd_kill_window_data *data;
|
||||
|
||||
*ptr = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_kill_window_free(void *ptr)
|
||||
{
|
||||
struct cmd_kill_window_data *data = ptr;
|
||||
|
||||
xfree(data);
|
||||
}
|
3
cmd.c
3
cmd.c
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd.c,v 1.17 2007-10-19 09:21:26 nicm Exp $ */
|
||||
/* $Id: cmd.c,v 1.18 2007-10-19 11:10:35 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -27,6 +27,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_attach_session_entry,
|
||||
&cmd_bind_key_entry,
|
||||
&cmd_detach_session_entry,
|
||||
&cmd_kill_window_entry,
|
||||
&cmd_last_window_entry,
|
||||
&cmd_list_keys_entry,
|
||||
&cmd_list_sessions_entry,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: input-keys.c,v 1.1 2007-09-28 22:47:21 nicm Exp $ */
|
||||
/* $Id: input-keys.c,v 1.2 2007-10-19 11:10:35 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -28,7 +28,6 @@ struct {
|
||||
int key;
|
||||
const char *data;
|
||||
} input_keys[] = {
|
||||
/* { KEYC_BACKSPACE, "\010" }, */
|
||||
{ KEYC_DC, "\e[3~" },
|
||||
{ KEYC_DOWN, "\eOB" },
|
||||
{ KEYC_F1, "\eOP" },
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: key-bindings.c,v 1.9 2007-10-19 09:21:26 nicm Exp $ */
|
||||
/* $Id: key-bindings.c,v 1.10 2007-10-19 11:10:35 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -105,6 +105,7 @@ key_bindings_init(void)
|
||||
{ '9', &cmd_select_window_entry, cmd_select_window_default },
|
||||
{ 'R', &cmd_refresh_session_entry, NULL },
|
||||
{ 'r', &cmd_refresh_session_entry, NULL },
|
||||
{ '&', &cmd_kill_window_entry, NULL },
|
||||
{ META, &cmd_send_prefix_entry, NULL },
|
||||
/*
|
||||
{ 'I', &cmd_windo_info_entry },
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: key-string.c,v 1.2 2007-10-04 00:18:59 nicm Exp $ */
|
||||
/* $Id: key-string.c,v 1.3 2007-10-19 11:10:35 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -29,7 +29,6 @@ struct {
|
||||
{ "A1", KEYC_A1 },
|
||||
{ "A3", KEYC_A3 },
|
||||
{ "B2", KEYC_B2 },
|
||||
{ "BACKSPACE", KEYC_BACKSPACE },
|
||||
{ "BEG", KEYC_BEG },
|
||||
{ "BTAB", KEYC_BTAB },
|
||||
{ "C1", KEYC_C1 },
|
||||
|
3
local.c
3
local.c
@ -1,4 +1,4 @@
|
||||
/* $Id: local.c,v 1.14 2007-10-03 10:18:32 nicm Exp $ */
|
||||
/* $Id: local.c,v 1.15 2007-10-19 11:10:35 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -51,7 +51,6 @@ struct local_key local_keys[] = {
|
||||
{ "ka1", NULL, 0, KEYC_A1 },
|
||||
{ "ka3", NULL, 0, KEYC_A3 },
|
||||
{ "kb2", NULL, 0, KEYC_B2 },
|
||||
/* { "kbs", NULL, 0, KEYC_BACKSPACE }, */
|
||||
{ "kbeg", NULL, 0, KEYC_BEG },
|
||||
{ "kcbt", NULL, 0, KEYC_BTAB },
|
||||
{ "kc1", NULL, 0, KEYC_C1 },
|
||||
|
5
tmux.h
5
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.60 2007-10-19 10:21:36 nicm Exp $ */
|
||||
/* $Id: tmux.h,v 1.61 2007-10-19 11:10:35 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -80,7 +80,7 @@ struct buffer {
|
||||
#define KEYC_A1 -1
|
||||
#define KEYC_A3 -2
|
||||
#define KEYC_B2 -3
|
||||
#define KEYC_BACKSPACE -4
|
||||
/* XXX #define KEYC_BACKSPACE -4 */
|
||||
#define KEYC_BEG -5
|
||||
#define KEYC_BTAB -6
|
||||
#define KEYC_C1 -7
|
||||
@ -520,6 +520,7 @@ char *cmd_recv_string(struct buffer *);
|
||||
extern const struct cmd_entry cmd_attach_session_entry;
|
||||
extern const struct cmd_entry cmd_bind_key_entry;
|
||||
extern const struct cmd_entry cmd_detach_session_entry;
|
||||
extern const struct cmd_entry cmd_kill_window_entry;
|
||||
extern const struct cmd_entry cmd_last_window_entry;
|
||||
extern const struct cmd_entry cmd_list_keys_entry;
|
||||
extern const struct cmd_entry cmd_list_sessions_entry;
|
||||
|
Loading…
Reference in New Issue
Block a user