summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-11-02 08:21:31 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-11-02 08:21:31 +0000
commit11af341595bd54e6bc11bf93b0b1746edb9274a3 (patch)
treee2d88408c2b27fa8aac6747812c3c09ac945a71d /usr.bin/tmux
parent47bf7d1952bfea0c9d6b33cac9793f9ca0369fb2 (diff)
Add numeric comparisons for formats, from teo_paul1 at yahoo dot com in
GitHub issue 2442.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/format.c44
-rw-r--r--usr.bin/tmux/tmux.116
2 files changed, 54 insertions, 6 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 357b42744b3..5f0b68b6759 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.264 2020/10/06 07:36:42 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.265 2020/11/02 08:21:30 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1984,7 +1984,17 @@ format_replace_expression(struct format_modifier *mexp,
int use_fp = 0;
u_int prec = 0;
double mleft, mright, result;
- enum { ADD, SUBTRACT, MULTIPLY, DIVIDE, MODULUS } operator;
+ enum { ADD,
+ SUBTRACT,
+ MULTIPLY,
+ DIVIDE,
+ MODULUS,
+ EQUAL,
+ NOT_EQUAL,
+ GREATER_THAN,
+ GREATER_THAN_EQUAL,
+ LESS_THAN,
+ LESS_THAN_EQUAL } operator;
if (strcmp(mexp->argv[0], "+") == 0)
operator = ADD;
@@ -1997,6 +2007,18 @@ format_replace_expression(struct format_modifier *mexp,
else if (strcmp(mexp->argv[0], "%") == 0 ||
strcmp(mexp->argv[0], "m") == 0)
operator = MODULUS;
+ else if (strcmp(mexp->argv[0], "==") == 0)
+ operator = EQUAL;
+ else if (strcmp(mexp->argv[0], "!=") == 0)
+ operator = NOT_EQUAL;
+ else if (strcmp(mexp->argv[0], ">") == 0)
+ operator = GREATER_THAN;
+ else if (strcmp(mexp->argv[0], "<") == 0)
+ operator = LESS_THAN;
+ else if (strcmp(mexp->argv[0], ">=") == 0)
+ operator = GREATER_THAN_EQUAL;
+ else if (strcmp(mexp->argv[0], "<=") == 0)
+ operator = LESS_THAN_EQUAL;
else {
format_log(es, "expression has no valid operator: '%s'",
mexp->argv[0]);
@@ -2059,6 +2081,24 @@ format_replace_expression(struct format_modifier *mexp,
case MODULUS:
result = fmod(mleft, mright);
break;
+ case EQUAL:
+ result = fabs(mleft - mright) < 1e-9;
+ break;
+ case NOT_EQUAL:
+ result = fabs(mleft - mright) > 1e-9;
+ break;
+ case GREATER_THAN:
+ result = (mleft > mright);
+ break;
+ case GREATER_THAN_EQUAL:
+ result = (mleft >= mright);
+ break;
+ case LESS_THAN:
+ result = (mleft < mright);
+ break;
+ case LESS_THAN_EQUAL:
+ result = (mleft > mright);
+ break;
}
if (use_fp)
xasprintf(&value, "%.*f", prec, result);
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index ad87a0b6102..fb10833598b 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.800 2020/10/30 08:55:56 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.801 2020/11/02 08:21:30 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: October 30 2020 $
+.Dd $Mdocdate: November 2 2020 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -4544,7 +4544,7 @@ multiplication
.Ql * ,
division
.Ql / ,
-and modulus
+modulus
.Ql m
or
.Ql %
@@ -4553,7 +4553,15 @@ or
must be escaped as
.Ql %%
in formats which are also expanded by
-.Xr strftime 3 ) .
+.Xr strftime 3 )
+and numeric comparison operators
+.Ql == ,
+.Ql != ,
+.Ql < ,
+.Ql <= ,
+.Ql >
+and
+.Ql >= .
For example,
.Ql #{e|*|f|4:5.5,3}
multiplies 5.5 by 3 for a result with four decimal places and