1
0
mirror of https://github.com/tmux/tmux.git synced 2025-03-28 09:38:50 +00:00

Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2019-10-15 10:01:28 +01:00
commit fb7ce5b5d5
6 changed files with 163 additions and 70 deletions

View File

@ -20,6 +20,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "tmux.h" #include "tmux.h"
@ -35,7 +36,7 @@ const struct cmd_entry cmd_join_pane_entry = {
.alias = "joinp", .alias = "joinp",
.args = { "bdhvp:l:s:t:", 0, 0 }, .args = { "bdhvp:l:s:t:", 0, 0 },
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE, .usage = "[-bdhv] [-l size] " CMD_SRCDST_PANE_USAGE,
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED }, .source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -67,11 +68,13 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
struct winlink *src_wl, *dst_wl; struct winlink *src_wl, *dst_wl;
struct window *src_w, *dst_w; struct window *src_w, *dst_w;
struct window_pane *src_wp, *dst_wp; struct window_pane *src_wp, *dst_wp;
char *cause; char *cause, *copy;
int size, percentage, dst_idx; const char *errstr, *p;
size_t plen;
int size, percentage, dst_idx, not_same_window;
int flags;
enum layout_type type; enum layout_type type;
struct layout_cell *lc; struct layout_cell *lc;
int not_same_window, flags;
if (self->entry == &cmd_join_pane_entry) if (self->entry == &cmd_join_pane_entry)
not_same_window = 1; not_same_window = 1;
@ -104,12 +107,28 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
type = LAYOUT_LEFTRIGHT; type = LAYOUT_LEFTRIGHT;
size = -1; size = -1;
if (args_has(args, 'l')) { if ((p = args_get(args, 'l')) != NULL) {
size = args_strtonum(args, 'l', 0, INT_MAX, &cause); plen = strlen(p);
if (cause != NULL) { if (p[plen - 1] == '%') {
cmdq_error(item, "size %s", cause); copy = xstrdup(p);
free(cause); copy[plen - 1] = '\0';
return (CMD_RETURN_ERROR); percentage = strtonum(copy, 0, INT_MAX, &errstr);
free(copy);
if (errstr != NULL) {
cmdq_error(item, "percentage %s", errstr);
return (CMD_RETURN_ERROR);
}
if (type == LAYOUT_TOPBOTTOM)
size = (dst_wp->sy * percentage) / 100;
else
size = (dst_wp->sx * percentage) / 100;
} else {
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(item, "size %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
} }
} else if (args_has(args, 'p')) { } else if (args_has(args, 'p')) {
percentage = args_strtonum(args, 'p', 0, 100, &cause); percentage = args_strtonum(args, 'p', 0, 100, &cause);

View File

@ -19,6 +19,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "tmux.h" #include "tmux.h"
@ -55,10 +56,11 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window; struct window *w = wl->window;
struct client *c = item->client; struct client *c = item->client;
struct session *s = item->target.s; struct session *s = item->target.s;
const char *errstr; const char *errstr, *p;
char *cause; char *cause, *copy;
u_int adjust; u_int adjust;
int x, y; int x, y, percentage;
size_t plen;
if (args_has(args, 'M')) { if (args_has(args, 'M')) {
if (cmd_mouse_window(&shared->mouse, &s) == NULL) if (cmd_mouse_window(&shared->mouse, &s) == NULL)
@ -91,21 +93,58 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
} }
} }
if (args_has(args, 'x')) { if ((p = args_get(args, 'x')) != NULL) {
x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX, &cause); plen = strlen(p);
if (cause != NULL) { if (p[plen - 1] == '%') {
cmdq_error(item, "width %s", cause); copy = xstrdup(p);
free(cause); copy[plen - 1] = '\0';
return (CMD_RETURN_ERROR); percentage = strtonum(copy, 0, INT_MAX, &errstr);
free(copy);
if (errstr != NULL) {
cmdq_error(item, "width %s", errstr);
return (CMD_RETURN_ERROR);
}
x = (w->sx * percentage) / 100;
if (x < PANE_MINIMUM)
x = PANE_MINIMUM;
if (x > INT_MAX)
x = INT_MAX;
} else {
x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX,
&cause);
if (cause != NULL) {
cmdq_error(item, "width %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
} }
layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x); layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
} }
if (args_has(args, 'y')) { if ((p = args_get(args, 'y')) != NULL) {
y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX, &cause); plen = strlen(p);
if (cause != NULL) { if (p[plen - 1] == '%') {
cmdq_error(item, "height %s", cause); copy = xstrdup(p);
free(cause); copy[plen - 1] = '\0';
return (CMD_RETURN_ERROR); percentage = strtonum(copy, 0, INT_MAX, &errstr);
free(copy);
if (errstr != NULL) {
cmdq_error(item, "height %s", errstr);
return (CMD_RETURN_ERROR);
}
y = (w->sy * percentage) / 100;
if (y < PANE_MINIMUM)
y = PANE_MINIMUM;
if (y > INT_MAX)
y = INT_MAX;
}
else {
y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX,
&cause);
if (cause != NULL) {
cmdq_error(item, "height %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
} }
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y); layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
} }

View File

@ -41,8 +41,7 @@ const struct cmd_entry cmd_split_window_entry = {
.args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 }, .args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 },
.usage = "[-bdefhIPv] [-c start-directory] [-e environment] " .usage = "[-bdefhIPv] [-c start-directory] [-e environment] "
"[-F format] [-p percentage|-l size] " CMD_TARGET_PANE_USAGE "[-F format] [-l size] " CMD_TARGET_PANE_USAGE " [command]",
" [command]",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -64,20 +63,37 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
struct layout_cell *lc; struct layout_cell *lc;
struct cmd_find_state fs; struct cmd_find_state fs;
int size, percentage, flags, input; int size, percentage, flags, input;
const char *template, *add; const char *template, *add, *errstr, *p;
char *cause, *cp; char *cause, *cp, *copy;
size_t plen;
struct args_value *value; struct args_value *value;
if (args_has(args, 'h')) if (args_has(args, 'h'))
type = LAYOUT_LEFTRIGHT; type = LAYOUT_LEFTRIGHT;
else else
type = LAYOUT_TOPBOTTOM; type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'l')) { if ((p = args_get(args, 'l')) != NULL) {
size = args_strtonum(args, 'l', 0, INT_MAX, &cause); plen = strlen(p);
if (cause != NULL) { if (p[plen - 1] == '%') {
cmdq_error(item, "create pane failed: -l %s", cause); copy = xstrdup(p);
free(cause); copy[plen - 1] = '\0';
return (CMD_RETURN_ERROR); percentage = strtonum(copy, 0, INT_MAX, &errstr);
free(copy);
if (errstr != NULL) {
cmdq_error(item, "percentage %s", errstr);
return (CMD_RETURN_ERROR);
}
if (type == LAYOUT_TOPBOTTOM)
size = (wp->sy * percentage) / 100;
else
size = (wp->sx * percentage) / 100;
} else {
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(item, "lines %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
} }
} else if (args_has(args, 'p')) { } else if (args_has(args, 'p')) {
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause); percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);

View File

@ -321,6 +321,17 @@ options_array_item(struct options_entry *o, u_int idx)
return (RB_FIND(options_array, &o->value.array, &a)); return (RB_FIND(options_array, &o->value.array, &a));
} }
static struct options_array_item *
options_array_new(struct options_entry *o, u_int idx)
{
struct options_array_item *a;
a = xcalloc(1, sizeof *a);
a->index = idx;
RB_INSERT(options_array, &o->value.array, a);
return (a);
}
static void static void
options_array_free(struct options_entry *o, struct options_array_item *a) options_array_free(struct options_entry *o, struct options_array_item *a)
{ {
@ -368,7 +379,14 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
return (-1); return (-1);
} }
if (OPTIONS_IS_COMMAND(o) && value != NULL) { if (value == NULL) {
a = options_array_item(o, idx);
if (a != NULL)
options_array_free(o, a);
return (0);
}
if (OPTIONS_IS_COMMAND(o)) {
pr = cmd_parse_from_string(value, NULL); pr = cmd_parse_from_string(value, NULL);
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY: case CMD_PARSE_EMPTY:
@ -384,34 +402,33 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
case CMD_PARSE_SUCCESS: case CMD_PARSE_SUCCESS:
break; break;
} }
}
a = options_array_item(o, idx); a = options_array_item(o, idx);
if (value == NULL) { if (a == NULL)
if (a != NULL) a = options_array_new(o, idx);
options_array_free(o, a); else
options_value_free(o, &a->value);
a->value.cmdlist = pr->cmdlist;
return (0); return (0);
} }
if (OPTIONS_IS_STRING(o)) { if (OPTIONS_IS_STRING(o)) {
a = options_array_item(o, idx);
if (a != NULL && append) if (a != NULL && append)
xasprintf(&new, "%s%s", a->value.string, value); xasprintf(&new, "%s%s", a->value.string, value);
else else
new = xstrdup(value); new = xstrdup(value);
if (a == NULL)
a = options_array_new(o, idx);
else
options_value_free(o, &a->value);
a->value.string = new;
return (0);
} }
if (a == NULL) { if (cause != NULL)
a = xcalloc(1, sizeof *a); *cause = xstrdup("wrong array type");
a->index = idx; return (-1);
RB_INSERT(options_array, &o->value.array, a);
} else
options_value_free(o, &a->value);
if (OPTIONS_IS_STRING(o))
a->value.string = new;
else if (OPTIONS_IS_COMMAND(o))
a->value.cmdlist = pr->cmdlist;
return (0);
} }
int int

32
tmux.1
View File

@ -1896,9 +1896,7 @@ zooms the pane.
This command works only if at least one client is attached. This command works only if at least one client is attached.
.It Xo Ic join-pane .It Xo Ic join-pane
.Op Fl bdhv .Op Fl bdhv
.Oo Fl l .Op Fl l Ar size
.Ar size |
.Fl p Ar percentage Oc
.Op Fl s Ar src-pane .Op Fl s Ar src-pane
.Op Fl t Ar dst-pane .Op Fl t Ar dst-pane
.Xc .Xc
@ -2035,9 +2033,7 @@ flag, see the
section. section.
.It Xo Ic move-pane .It Xo Ic move-pane
.Op Fl bdhv .Op Fl bdhv
.Oo Fl l .Op Fl l Ar size
.Ar size |
.Fl p Ar percentage Oc
.Op Fl s Ar src-pane .Op Fl s Ar src-pane
.Op Fl t Ar dst-pane .Op Fl t Ar dst-pane
.Xc .Xc
@ -2246,8 +2242,14 @@ or
.Fl y . .Fl y .
The The
.Ar adjustment .Ar adjustment
is given in lines or cells (the default is 1). is given in lines or columns (the default is 1);
.Pp .Fl x
and
.Fl y
may be a given as a number of lines or columns or followed by
.Ql %
for a percentage of the window size (for example
.Ql -x 10% ) .
With With
.Fl Z , .Fl Z ,
the active pane is toggled between zoomed (occupying the whole of the window) the active pane is toggled between zoomed (occupying the whole of the window)
@ -2439,9 +2441,7 @@ the command behaves like
.Op Fl bdfhIvP .Op Fl bdfhIvP
.Op Fl c Ar start-directory .Op Fl c Ar start-directory
.Op Fl e Ar environment .Op Fl e Ar environment
.Oo Fl l .Op Fl l Ar size
.Ar size |
.Fl p Ar percentage Oc
.Op Fl t Ar target-pane .Op Fl t Ar target-pane
.Op Ar shell-command .Op Ar shell-command
.Op Fl F Ar format .Op Fl F Ar format
@ -2457,10 +2457,12 @@ a vertical split; if neither is specified,
is assumed. is assumed.
The The
.Fl l .Fl l
and option specifies the size of the new pane in lines (for vertical split) or in
.Fl p columns (for horizontal split);
options specify the size of the new pane in lines (for vertical split) or in .Ar size
cells (for horizontal split), or as a percentage, respectively. may be followed by
.Ql %
to specify a percentage of the available space.
The The
.Fl b .Fl b
option causes the new pane to be created to the left of or above option causes the new pane to be created to the left of or above

View File

@ -191,7 +191,7 @@ window_tree_cmp_session(const void *a0, const void *b0)
const struct session *const *b = b0; const struct session *const *b = b0;
const struct session *sa = *a; const struct session *sa = *a;
const struct session *sb = *b; const struct session *sb = *b;
int result; int result = 0;
switch (window_tree_sort->field) { switch (window_tree_sort->field) {
case WINDOW_TREE_BY_INDEX: case WINDOW_TREE_BY_INDEX:
@ -226,7 +226,7 @@ window_tree_cmp_window(const void *a0, const void *b0)
const struct winlink *wlb = *b; const struct winlink *wlb = *b;
struct window *wa = wla->window; struct window *wa = wla->window;
struct window *wb = wlb->window; struct window *wb = wlb->window;
int result; int result = 0;
switch (window_tree_sort->field) { switch (window_tree_sort->field) {
case WINDOW_TREE_BY_INDEX: case WINDOW_TREE_BY_INDEX: