summaryrefslogtreecommitdiffstats
path: root/cmd-split-window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-01-12 18:22:47 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-01-12 18:22:47 +0000
commit7cd3cf0eada8513907cd1cc78d7669752235f419 (patch)
tree387f8f8c1a2976775cd6718812010130d9e27676 /cmd-split-window.c
parent440a84b2aa0457f9d94903f04055c1b662d41fbc (diff)
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.
Diffstat (limited to 'cmd-split-window.c')
-rw-r--r--cmd-split-window.c70
1 files changed, 54 insertions, 16 deletions
diff --git a/cmd-split-window.c b/cmd-split-window.c
index a2879f41..37b220e2 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-split-window.c,v 1.2 2009-01-11 23:41:29 nicm Exp $ */
+/* $Id: cmd-split-window.c,v 1.3 2009-01-12 18:22:47 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,11 +39,14 @@ struct cmd_split_window_data {
char *target;
char *cmd;
int flag_detached;
+
+ int lines;
+ int percentage;
};
const struct cmd_entry cmd_split_window_entry = {
"split-window", "splitw",
- "[-d] [-t target-window] [command]",
+ "[-d] [-t target-window] [-l lines|-p percentage] [command]",
0,
cmd_split_window_init,
cmd_split_window_parse,
@@ -63,22 +66,49 @@ cmd_split_window_init(struct cmd *self, unused int arg)
data->target = NULL;
data->cmd = NULL;
data->flag_detached = 0;
+ data->lines = -1;
+ data->percentage = -1;
}
int
cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
{
struct cmd_split_window_data *data;
- int opt;
+ int opt, n;
+ const char *errstr;
self->entry->init(self, 0);
data = self->data;
- while ((opt = getopt(argc, argv, "dt:")) != -1) {
+ while ((opt = getopt(argc, argv, "dl:p:t:")) != -1) {
switch (opt) {
case 'd':
data->flag_detached = 1;
break;
+ case 'l':
+ if (data->percentage != -1)
+ goto usage;
+ if (data->lines == -1) {
+ n = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL) {
+ xasprintf(cause, "number %s", errstr);
+ goto error;
+ }
+ data->lines = n;
+ }
+ break;
+ case 'p':
+ if (data->lines != -1)
+ goto usage;
+ if (data->percentage == -1) {
+ n = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL) {
+ xasprintf(cause, "number %s", errstr);
+ goto error;
+ }
+ data->percentage = n;
+ }
+ break;
case 't':
if (data->target == NULL)
data->target = xstrdup(optarg);
@@ -100,6 +130,7 @@ cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
usage:
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
+error:
self->entry->free(self);
return (-1);
}
@@ -110,17 +141,17 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct cmd_split_window_data *data = self->data;
struct session *s;
struct winlink *wl;
- const char *env[] = {
- NULL /* TMUX= */, "TERM=screen", NULL
- };
+ struct window *w;
+ const char *env[] = CHILD_ENVIRON;
char buf[256];
char *cmd, *cwd;
- u_int i, sx, sy, hlimit;
+ u_int i, hlimit, size;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return;
+ w = wl->window;
- if (wl->window->panes[1] != NULL) {
+ if (w->panes[1] != NULL) {
ctx->error(ctx, "window is already split");
return;
}
@@ -138,19 +169,26 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
else
cwd = ctx->cmdclient->cwd;
+ size = w->sy / 2;
+ if (data->lines != -1)
+ size = data->lines;
+ if (data->percentage != -1) {
+ if (data->percentage > 100)
+ data->percentage = 100;
+ size = (w->sy * data->percentage) / 100;
+ }
+ if (size > w->sy)
+ size = w->sy; /* let window_add_pane sort it out */
+
hlimit = options_get_number(&s->options, "history-limit");
- sx = wl->window->sx;
- sy = wl->window->sy - (wl->window->sy / 2);
- wl->window->panes[1] = window_pane_create(wl->window, sx, sy, hlimit);
- if (window_pane_spawn(wl->window->panes[1], cmd, cwd, env) != 0) {
+ if (window_add_pane(w, size, cmd, cwd, env, hlimit) < 0) {
ctx->error(ctx, "command failed: %s", cmd);
return;
}
- window_resize(wl->window, wl->window->sx, wl->window->sy);
- server_redraw_window(wl->window);
+ server_redraw_window(w);
if (!data->flag_detached) {
- wl->window->active = wl->window->panes[1];
+ w->active = w->panes[1];
session_select(s, wl->idx);
server_redraw_session(s);
} else