diff options
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | cmd-split-window.c | 43 | ||||
-rw-r--r-- | tmux.h | 4 | ||||
-rw-r--r-- | window.c | 23 |
5 files changed, 60 insertions, 16 deletions
@@ -1,5 +1,7 @@ 21 January 2009 +* Bring back split-window -p and -l options to specify the height a percentage + or as a number of lines. * Make window and session choice modes allow you to choose items in vi keys mode (doh!). As a side-effect, this makes enter copy selection (as well as C-w/M-w) when using emacs keys in copy mode. Reported by merdely. @@ -992,7 +994,7 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.227 2009-01-21 18:19:32 nicm Exp $ +$Id: CHANGES,v 1.228 2009-01-21 19:38:51 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 ms @@ -84,6 +84,6 @@ - document suspend-client - document command sequences - document find-window -- bring back -l/-p on splitw so i can do "splitw -p 75 elinks" +- document split-window -p and -l - UTF-8 combining characters don't work (probably should be width 1 but are listed as 2) diff --git a/cmd-split-window.c b/cmd-split-window.c index a61efd1b..bf725377 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-split-window.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */ +/* $Id: cmd-split-window.c,v 1.7 2009-01-21 19:38:51 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -39,11 +39,13 @@ struct cmd_split_window_data { char *target; char *cmd; int flag_detached; + int percentage; + int lines; }; const struct cmd_entry cmd_split_window_entry = { "split-window", "splitw", - "[-d] [-t target-window] [command]", + "[-d] [-p percentage|-l lines] [-t target-window] [command]", 0, cmd_split_window_init, cmd_split_window_parse, @@ -63,13 +65,16 @@ cmd_split_window_init(struct cmd *self, unused int arg) data->target = NULL; data->cmd = NULL; data->flag_detached = 0; + data->percentage = -1; + data->lines = -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; @@ -83,6 +88,27 @@ cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause) if (data->target == NULL) data->target = xstrdup(optarg); break; + case 'l': + if (data->percentage == -1 && data->lines == -1) { + n = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr != NULL) { + xasprintf(cause, "lines %s", errstr); + goto error; + } + data->lines = n; + } + break; + case 'p': + if (data->lines == -1 && data->percentage == -1) { + n = strtonum(optarg, 1, 100, &errstr); + if (errstr != NULL) { + xasprintf( + cause, "percentage %s", errstr); + goto error; + } + data->percentage = n; + } + break; default: goto usage; } @@ -100,6 +126,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); } @@ -115,7 +142,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) const char *env[] = CHILD_ENVIRON; char buf[256]; char *cmd, *cwd; - u_int i, hlimit; + u_int i, hlimit, lines; if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) return (-1); @@ -134,8 +161,14 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) else cwd = ctx->cmdclient->cwd; + lines = -1; + if (data->lines != -1) + lines = data->lines; + else if (data->percentage != -1) + lines = (w->active->sy * data->percentage) / 100; + hlimit = options_get_number(&s->options, "history-limit"); - if ((wp = window_add_pane(w, cmd, cwd, env, hlimit)) == NULL) { + if ((wp = window_add_pane(w, lines, cmd, cwd, env, hlimit)) == NULL) { ctx->error(ctx, "command failed: %s", cmd); return (-1); } @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.245 2009-01-20 19:35:03 nicm Exp $ */ +/* $Id: tmux.h,v 1.246 2009-01-21 19:38:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1421,7 +1421,7 @@ struct window *window_create(const char *, const char *, void window_destroy(struct window *); int window_resize(struct window *, u_int, u_int); void window_set_active_pane(struct window *, struct window_pane *); -struct window_pane *window_add_pane(struct window *, +struct window_pane *window_add_pane(struct window *, int, const char *, const char *, const char **, u_int); void window_remove_pane(struct window *, struct window_pane *); u_int window_index_of_pane(struct window *, struct window_pane *); @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.60 2009-01-20 19:35:03 nicm Exp $ */ +/* $Id: window.c,v 1.61 2009-01-21 19:38:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -228,7 +228,7 @@ window_create(const char *name, const char *cmd, ARRAY_ADD(&windows, w); w->references = 0; - if (window_add_pane(w, cmd, cwd, envp, hlimit) == NULL) { + if (window_add_pane(w, -1, cmd, cwd, envp, hlimit) == NULL) { window_destroy(w); return (NULL); } @@ -378,19 +378,28 @@ window_set_active_pane(struct window *w, struct window_pane *wp) } struct window_pane * -window_add_pane(struct window *w, +window_add_pane(struct window *w, int wanty, const char *cmd, const char *cwd, const char **envp, u_int hlimit) { struct window_pane *wp; - u_int wanty; + u_int sizey; if (TAILQ_EMPTY(&w->panes)) wanty = w->sy; else { - if (w->active->sy < PANE_MINIMUM * 2) + sizey = w->active->sy - 1; /* for separator */ + if (sizey < PANE_MINIMUM * 2) return (NULL); - wanty = (w->active->sy / 2 + w->active->sy % 2) - 1; - window_pane_resize(w->active, w->sx, w->active->sy / 2); + + if (wanty == -1) + wanty = sizey / 2; + + if (wanty < PANE_MINIMUM) + wanty = PANE_MINIMUM; + if ((u_int) wanty > sizey - PANE_MINIMUM) + wanty = sizey - PANE_MINIMUM; + + window_pane_resize(w->active, w->sx, sizey - wanty); } wp = window_pane_create(w, w->sx, wanty, hlimit); |