summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-04-22 06:57:14 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-04-22 06:57:14 +0000
commit1c6d9cb48f811bc48f63028132c388723be36cbe (patch)
tree06893614d53036dc1cb1a63a9153e1a68c8eb39f /usr.bin
parent0744f161eaf998420a541ce310b02cb5d5387e5f (diff)
Change so main-pane-width and height can be given as a percentage.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/arguments.c29
-rw-r--r--usr.bin/tmux/layout-set.c45
-rw-r--r--usr.bin/tmux/options-table.c26
-rw-r--r--usr.bin/tmux/tmux.110
-rw-r--r--usr.bin/tmux/tmux.h4
5 files changed, 72 insertions, 42 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c
index 7ae81a45180..39ebd0d4add 100644
--- a/usr.bin/tmux/arguments.c
+++ b/usr.bin/tmux/arguments.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arguments.c,v 1.30 2020/04/12 20:54:28 nicm Exp $ */
+/* $OpenBSD: arguments.c,v 1.31 2020/04/22 06:57:13 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -352,22 +352,29 @@ long long
args_percentage(struct args *args, u_char ch, long long minval,
long long maxval, long long curval, char **cause)
{
- const char *errstr;
- long long ll;
+ const char *value;
struct args_entry *entry;
- struct args_value *value;
- size_t valuelen;
- char *copy;
if ((entry = args_find(args, ch)) == NULL) {
*cause = xstrdup("missing");
return (0);
}
- value = TAILQ_LAST(&entry->values, args_values);
- valuelen = strlen(value->value);
+ value = TAILQ_LAST(&entry->values, args_values)->value;
+ return (args_string_percentage(value, minval, maxval, curval, cause));
+}
+
+/* Convert a string to a number which may be a percentage. */
+long long
+args_string_percentage(const char *value, long long minval, long long maxval,
+ long long curval, char **cause)
+{
+ const char *errstr;
+ long long ll;
+ size_t valuelen = strlen(value);
+ char *copy;
- if (value->value[valuelen - 1] == '%') {
- copy = xstrdup(value->value);
+ if (value[valuelen - 1] == '%') {
+ copy = xstrdup(value);
copy[valuelen - 1] = '\0';
ll = strtonum(copy, 0, 100, &errstr);
@@ -386,7 +393,7 @@ args_percentage(struct args *args, u_char ch, long long minval,
return (0);
}
} else {
- ll = strtonum(value->value, minval, maxval, &errstr);
+ ll = strtonum(value, minval, maxval, &errstr);
if (errstr != NULL) {
*cause = xstrdup(errstr);
return (0);
diff --git a/usr.bin/tmux/layout-set.c b/usr.bin/tmux/layout-set.c
index 8f650286721..e551447ce79 100644
--- a/usr.bin/tmux/layout-set.c
+++ b/usr.bin/tmux/layout-set.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: layout-set.c,v 1.28 2019/11/28 09:45:15 nicm Exp $ */
+/* $OpenBSD: layout-set.c,v 1.29 2020/04/22 06:57:13 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -18,6 +18,7 @@
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@@ -186,6 +187,8 @@ layout_set_main_h(struct window *w)
struct window_pane *wp;
struct layout_cell *lc, *lcmain, *lcother, *lcchild;
u_int n, mainh, otherh, sx, sy;
+ char *cause;
+ const char *s;
layout_print_cell(w->layout_root, __func__, 1);
@@ -198,8 +201,15 @@ layout_set_main_h(struct window *w)
/* Find available height - take off one line for the border. */
sy = w->sy - 1;
- /* Get the main pane height and work out the other pane height. */
- mainh = options_get_number(w->options, "main-pane-height");
+ /* Get the main pane height. */
+ s = options_get_string(w->options, "main-pane-height");
+ mainh = args_string_percentage(s, 0, sy, sy, &cause);
+ if (cause != NULL) {
+ mainh = 24;
+ free(cause);
+ }
+
+ /* Work out the other pane height. */
if (mainh + PANE_MINIMUM >= sy) {
if (sy <= PANE_MINIMUM + PANE_MINIMUM)
mainh = PANE_MINIMUM;
@@ -207,10 +217,12 @@ layout_set_main_h(struct window *w)
mainh = sy - PANE_MINIMUM;
otherh = PANE_MINIMUM;
} else {
- otherh = options_get_number(w->options, "other-pane-height");
- if (otherh == 0)
+ s = options_get_string(w->options, "other-pane-height");
+ otherh = args_string_percentage(s, 0, sy, sy, &cause);
+ if (cause != NULL || otherh == 0) {
otherh = sy - mainh;
- else if (otherh > sy || sy - otherh < mainh)
+ free(cause);
+ } else if (otherh > sy || sy - otherh < mainh)
otherh = sy - mainh;
else
mainh = sy - otherh;
@@ -273,6 +285,8 @@ layout_set_main_v(struct window *w)
struct window_pane *wp;
struct layout_cell *lc, *lcmain, *lcother, *lcchild;
u_int n, mainw, otherw, sx, sy;
+ char *cause;
+ const char *s;
layout_print_cell(w->layout_root, __func__, 1);
@@ -285,8 +299,15 @@ layout_set_main_v(struct window *w)
/* Find available width - take off one line for the border. */
sx = w->sx - 1;
- /* Get the main pane width and work out the other pane width. */
- mainw = options_get_number(w->options, "main-pane-width");
+ /* Get the main pane width. */
+ s = options_get_string(w->options, "main-pane-width");
+ mainw = args_string_percentage(s, 0, sx, sx, &cause);
+ if (cause != NULL) {
+ mainw = 80;
+ free(cause);
+ }
+
+ /* Work out the other pane width. */
if (mainw + PANE_MINIMUM >= sx) {
if (sx <= PANE_MINIMUM + PANE_MINIMUM)
mainw = PANE_MINIMUM;
@@ -294,10 +315,12 @@ layout_set_main_v(struct window *w)
mainw = sx - PANE_MINIMUM;
otherw = PANE_MINIMUM;
} else {
- otherw = options_get_number(w->options, "other-pane-width");
- if (otherw == 0)
+ s = options_get_string(w->options, "other-pane-width");
+ otherw = args_string_percentage(s, 0, sx, sx, &cause);
+ if (cause != NULL || otherw == 0) {
otherw = sx - mainw;
- else if (otherw > sx || sx - otherw < mainw)
+ free(cause);
+ } else if (otherw > sx || sx - otherw < mainw)
otherw = sx - mainw;
else
mainw = sx - otherw;
diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c
index 1d6c3e10f73..1898202532d 100644
--- a/usr.bin/tmux/options-table.c
+++ b/usr.bin/tmux/options-table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options-table.c,v 1.119 2020/04/21 05:26:13 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.120 2020/04/22 06:57:13 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -647,19 +647,15 @@ const struct options_table_entry options_table[] = {
},
{ .name = "main-pane-height",
- .type = OPTIONS_TABLE_NUMBER,
+ .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
- .minimum = 1,
- .maximum = INT_MAX,
- .default_num = 24
+ .default_str = "24"
},
{ .name = "main-pane-width",
- .type = OPTIONS_TABLE_NUMBER,
+ .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
- .minimum = 1,
- .maximum = INT_MAX,
- .default_num = 80
+ .default_str = "80"
},
{ .name = "mode-keys",
@@ -696,19 +692,15 @@ const struct options_table_entry options_table[] = {
},
{ .name = "other-pane-height",
- .type = OPTIONS_TABLE_NUMBER,
+ .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
- .minimum = 0,
- .maximum = INT_MAX,
- .default_num = 0
+ .default_str = "0"
},
{ .name = "other-pane-width",
- .type = OPTIONS_TABLE_NUMBER,
+ .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
- .minimum = 0,
- .maximum = INT_MAX,
- .default_num = 0
+ .default_str = "0"
},
{ .name = "pane-active-border-style",
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index fdd0241b803..3a9db7dd716 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.746 2020/04/20 14:59:31 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.747 2020/04/22 06:57:13 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 20 2020 $
+.Dd $Mdocdate: April 22 2020 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -3711,6 +3711,9 @@ Set the width or height of the main (left or top) pane in the
or
.Ic main-vertical
layouts.
+If suffixed by
+.Ql % ,
+this is a percentage of the window size.
.Pp
.It Xo Ic mode-keys
.Op Ic vi | emacs
@@ -3764,6 +3767,9 @@ and
.Ic other-pane-height
options are set, the main pane will grow taller to make the other panes the
specified height, but will never shrink to do so.
+If suffixed by
+.Ql % ,
+this is a percentage of the window size.
.Pp
.It Ic other-pane-width Ar width
Like
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 5f96d3ff568..2a0fab8baba 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1013 2020/04/20 15:37:32 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1014 2020/04/22 06:57:13 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2043,6 +2043,8 @@ long long args_strtonum(struct args *, u_char, long long, long long,
char **);
long long args_percentage(struct args *, u_char, long long,
long long, long long, char **);
+long long args_string_percentage(const char *, long long, long long,
+ long long, char **);
/* cmd-find.c */
int cmd_find_target(struct cmd_find_state *, struct cmdq_item *,