Commands to resize panes; also a pane generic cmd, not used yet.

pull/1/head
Nicholas Marriott 2009-01-12 19:23:14 +00:00
parent 7cd3cf0ead
commit c35a50b21a
9 changed files with 337 additions and 6 deletions

View File

@ -1,5 +1,6 @@
12 January 2009
* Two commands, resize-pane-up and resize-pane-down to resize a pane.
* Make the window pane code handle panes of different sizes, and add a -l
and -p arguments to split-window to specify the new window size in lines
or as a percentage.
@ -882,7 +883,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.195 2009-01-12 18:22:47 nicm Exp $
$Id: CHANGES,v 1.196 2009-01-12 19:23:14 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.89 2009-01-12 00:52:37 nicm Exp $
# $Id: Makefile,v 1.90 2009-01-12 19:23:14 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html
@ -38,6 +38,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-respawn-window.c cmd-source-file.c cmd-server-info.c \
cmd-clock-mode.c cmd-lock-server.c cmd-set-password.c \
cmd-save-buffer.c cmd-switch-pane.c cmd-split-window.c \
cmd-resize-pane-up.c cmd-resize-pane-down.c \
window-clock.c window-scroll.c window-more.c window-copy.c \
options.c options-cmd.c paste.c colour.c utf8.c clock.c \
tty.c tty-term.c tty-keys.c tty-write.c

3
TODO
View File

@ -101,3 +101,6 @@
bind r command-prompt 'renamew "%%"'
which then asks for a string, substitutes %% in command and executes it
- fix rxvt cursor fg issue (text under cursor has non-white fg)
- should have a repeat-command delay - if you execute a key binding then
press another key within the delay time it is treated as if it was anoth
key binding (ie the ^A prefix is implied)

View File

@ -1,4 +1,4 @@
/* $Id: cmd-generic.c,v 1.19 2009-01-11 23:14:57 nicm Exp $ */
/* $Id: cmd-generic.c,v 1.20 2009-01-12 19:23:14 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -545,3 +545,116 @@ cmd_option_print(struct cmd *self, char *buf, size_t len)
if (off < len && data->value != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->value);
}
void
cmd_pane_init(struct cmd *self, unused int key)
{
struct cmd_pane_data *data;
self->data = data = xmalloc(sizeof *data);
data->flags = 0;
data->target = NULL;
data->arg = NULL;
data->pane = -1;
}
int
cmd_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
{
struct cmd_pane_data *data;
int opt, n;
const char *errstr;
/* Don't use the entry version since it may be dependent on key. */
cmd_pane_init(self, 0);
data = self->data;
while ((opt = getopt(argc, argv, CMD_FLAGS "p:t:")) != -1) {
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
case -1:
goto usage;
case 0:
continue;
}
switch (opt) {
case 'p':
if (data->pane == -1) {
n = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr != NULL) {
xasprintf(cause, "pane %s", errstr);
goto error;
}
data->pane = n;
}
break;
case 't':
if (data->target == NULL)
data->target = xstrdup(optarg);
break;
default:
goto usage;
}
}
argc -= optind;
argv += optind;
if (cmd_fill_argument(self->entry->flags, &data->arg, argc, argv) != 0)
goto usage;
return (0);
usage:
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
self->entry->free(self);
return (-1);
}
void
cmd_pane_send(struct cmd *self, struct buffer *b)
{
struct cmd_pane_data *data = self->data;
buffer_write(b, data, sizeof *data);
cmd_send_string(b, data->target);
cmd_send_string(b, data->arg);
}
void
cmd_pane_recv(struct cmd *self, struct buffer *b)
{
struct cmd_pane_data *data;
self->data = data = xmalloc(sizeof *data);
buffer_read(b, data, sizeof *data);
data->target = cmd_recv_string(b);
data->arg = cmd_recv_string(b);
}
void
cmd_pane_free(struct cmd *self)
{
struct cmd_pane_data *data = self->data;
if (data->target != NULL)
xfree(data->target);
if (data->arg != NULL)
xfree(data->arg);
xfree(data);
}
void
cmd_pane_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_pane_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
off += cmd_print_flags(buf, len, off, data->flags);
if (off < len && data->target != NULL)
off += xsnprintf(buf + off, len - off, " -t %s", data->target);
if (off < len && data->arg != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->arg);
}

95
cmd-resize-pane-down.c Normal file
View File

@ -0,0 +1,95 @@
/* $Id: cmd-resize-pane-down.c,v 1.1 2009-01-12 19:23:14 nicm Exp $ */
/*
* Copyright (c) 2009 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 <stdlib.h>
#include "tmux.h"
/*
* Increase pane size.
*/
void cmd_resize_pane_down_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_resize_pane_down_entry = {
"resize-pane-down", "resizep-dn",
CMD_TARGET_WINDOW_USAGE " [adjustment]",
CMD_ZEROONEARG,
cmd_target_init,
cmd_target_parse,
cmd_resize_pane_down_exec,
cmd_target_send,
cmd_target_recv,
cmd_target_free,
cmd_target_print
};
void
cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
int adjust;
const char *errstr;
u_int y0, y1;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return;
#ifdef notyet
if (data->pane == -1)
wp = wl->window->active;
else {
if (data->pane > 1 || wl->window->panes[data->pane] == NULL) {
ctx->error(ctx, "no pane: %d", data->pane);
return;
}
wp = wl->window->panes[data->pane];
}
#endif
if (data->arg == NULL)
adjust = 1;
else {
adjust = strtonum(data->arg, 0, INT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
return;
}
}
if (wl->window->panes[1] == NULL)
goto out;
y0 = wl->window->panes[0]->sy;
y1 = wl->window->panes[1]->sy;
if (adjust >= y1)
adjust = y1 - 1;
y0 += adjust;
y1 -= adjust;
window_pane_resize(wl->window->panes[0], wl->window->sx, y0);
window_pane_resize(wl->window->panes[1], wl->window->sx, y1);
wl->window->panes[1]->yoff = y0 + 1;
server_redraw_window(wl->window);
out:
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
}

95
cmd-resize-pane-up.c Normal file
View File

@ -0,0 +1,95 @@
/* $Id: cmd-resize-pane-up.c,v 1.1 2009-01-12 19:23:14 nicm Exp $ */
/*
* Copyright (c) 2009 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 <stdlib.h>
#include "tmux.h"
/*
* Increase pane size.
*/
void cmd_resize_pane_up_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_resize_pane_up_entry = {
"resize-pane-up", "resizep-up",
CMD_TARGET_WINDOW_USAGE " [adjustment]",
CMD_ZEROONEARG,
cmd_target_init,
cmd_target_parse,
cmd_resize_pane_up_exec,
cmd_target_send,
cmd_target_recv,
cmd_target_free,
cmd_target_print
};
void
cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
int adjust;
const char *errstr;
u_int y0, y1;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return;
#ifdef notyet
if (data->pane == -1)
wp = wl->window->active;
else {
if (data->pane > 1 || wl->window->panes[data->pane] == NULL) {
ctx->error(ctx, "no pane: %d", data->pane);
return;
}
wp = wl->window->panes[data->pane];
}
#endif
if (data->arg == NULL)
adjust = 1;
else {
adjust = strtonum(data->arg, 0, INT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
return;
}
}
if (wl->window->panes[1] == NULL)
goto out;
y0 = wl->window->panes[0]->sy;
y1 = wl->window->panes[1]->sy;
if (adjust >= y0)
adjust = y0 - 1;
y0 -= adjust;
y1 += adjust;
window_pane_resize(wl->window->panes[0], wl->window->sx, y0);
window_pane_resize(wl->window->panes[1], wl->window->sx, y1);
wl->window->panes[1]->yoff = y0 + 1;
server_redraw_window(wl->window);
out:
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
}

4
cmd.c
View File

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.74 2009-01-11 23:31:46 nicm Exp $ */
/* $Id: cmd.c,v 1.75 2009-01-12 19:23:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -55,6 +55,8 @@ const struct cmd_entry *cmd_table[] = {
&cmd_refresh_client_entry,
&cmd_rename_session_entry,
&cmd_rename_window_entry,
&cmd_resize_pane_down_entry,
&cmd_resize_pane_up_entry,
&cmd_respawn_window_entry,
&cmd_save_buffer_entry,
&cmd_scroll_mode_entry,

View File

@ -1,4 +1,4 @@
/* $Id: key-bindings.c,v 1.43 2009-01-11 23:31:46 nicm Exp $ */
/* $Id: key-bindings.c,v 1.44 2009-01-12 19:23:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -107,6 +107,8 @@ key_bindings_init(void)
{ 's', &cmd_list_sessions_entry },
{ 't', &cmd_clock_mode_entry },
{ 'w', &cmd_list_windows_entry },
{ KEYC_ADDCTL(KEYC_UP), &cmd_resize_pane_up_entry },
{ KEYC_ADDCTL(KEYC_DOWN), &cmd_resize_pane_down_entry },
{ META, &cmd_send_prefix_entry },
};
u_int i;

21
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.225 2009-01-12 18:22:47 nicm Exp $ */
/* $Id: tmux.h,v 1.226 2009-01-12 19:23:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -852,6 +852,13 @@ struct cmd_option_data {
char *value;
};
struct cmd_pane_data {
int flags;
char *target;
char *arg;
int pane;
};
/* Key binding. */
struct key_binding {
int key;
@ -1094,6 +1101,8 @@ extern const struct cmd_entry cmd_previous_window_entry;
extern const struct cmd_entry cmd_refresh_client_entry;
extern const struct cmd_entry cmd_rename_session_entry;
extern const struct cmd_entry cmd_rename_window_entry;
extern const struct cmd_entry cmd_resize_pane_down_entry;
extern const struct cmd_entry cmd_resize_pane_up_entry;
extern const struct cmd_entry cmd_respawn_window_entry;
extern const struct cmd_entry cmd_save_buffer_entry;
extern const struct cmd_entry cmd_scroll_mode_entry;
@ -1162,6 +1171,16 @@ void cmd_option_send(struct cmd *, struct buffer *);
void cmd_option_recv(struct cmd *, struct buffer *);
void cmd_option_free(struct cmd *);
void cmd_option_print(struct cmd *, char *, size_t);
#define CMD_PANE_WINDOW_USAGE "[-t target-window] [-p pane-index]"
#define CMD_PANE_SESSION_USAGE "[-t target-session] [-p pane-index]"
#define CMD_PANE_CLIENT_USAGE "[-t target-client] [-p pane-index]"
void cmd_pane_init(struct cmd *, int);
int cmd_pane_parse(struct cmd *, int, char **, char **);
void cmd_pane_exec(struct cmd *, struct cmd_ctx *);
void cmd_pane_send(struct cmd *, struct buffer *);
void cmd_pane_recv(struct cmd *, struct buffer *);
void cmd_pane_free(struct cmd *);
void cmd_pane_print(struct cmd *, char *, size_t);
/* client.c */
int client_init(const char *, struct client_ctx *, int, int);