-/* $OpenBSD: cmd-find-window.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-find-window.c,v 1.42 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
}
if (match_flags & CMD_FIND_WINDOW_BY_CONTENT &&
- (sres = window_pane_search(wp, str, &line)) != NULL) {
+ (sres = window_pane_search_old(wp, str, &line)) != NULL) {
xasprintf(&find_data->list_ctx,
"pane %u line %u: \"%s\"", i - 1, line + 1, sres);
free(sres);
-/* $OpenBSD: format.c,v 1.139 2017/05/29 15:43:48 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.140 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
return (0);
}
-/*
- * Replace a key/value pair in buffer. #{blah} is expanded directly,
- * #{?blah,a,b} is replace with a if blah exists and is nonzero else b.
- */
+/* Replace a key. */
static int
format_replace(struct format_tree *ft, const char *key, size_t keylen,
char **buf, size_t *len, size_t *off)
{
- char *copy, *copy0, *endptr, *ptr, *found, *new, *value;
- char *from = NULL, *to = NULL, *left, *right;
- size_t valuelen, newlen, fromlen, tolen, used;
- long limit = 0;
- int modifiers = 0, compare = 0;
+ struct window_pane *wp = ft->wp;
+ char *copy, *copy0, *endptr, *ptr, *found, *new;
+ char *value, *from = NULL, *to = NULL, *left, *right;
+ size_t valuelen, newlen, fromlen, tolen, used;
+ long limit = 0;
+ int modifiers = 0, compare = 0, search = 0;
/* Make a copy of the key. */
copy0 = copy = xmalloc(keylen + 1);
compare = -2;
copy += 2;
break;
+ case 'C':
+ if (copy[1] != ':')
+ break;
+ search = 1;
+ copy += 2;
+ break;
+ case '|':
+ if (copy[1] != '|' || copy[2] != ':')
+ break;
+ compare = -3;
+ copy += 3;
+ break;
+ case '&':
+ if (copy[1] != '&' || copy[2] != ':')
+ break;
+ compare = -4;
+ copy += 3;
+ break;
case '!':
if (copy[1] == '=' && copy[2] == ':') {
compare = -1;
}
/* Is this a comparison or a conditional? */
- if (compare != 0) {
+ if (search) {
+ /* Search in pane. */
+ if (wp == NULL)
+ value = xstrdup("0");
+ else
+ xasprintf(&value, "%u", window_pane_search(wp, copy));
+ } else if (compare != 0) {
/* Comparison: compare comma-separated left and right. */
if (format_choose(copy, &left, &right) != 0)
goto fail;
left = format_expand(ft, left);
right = format_expand(ft, right);
- if (compare == 1 && strcmp(left, right) == 0)
+ if (compare == -3 &&
+ (format_true(left) || format_true(right)))
+ value = xstrdup("1");
+ else if (compare == -4 &&
+ (format_true(left) && format_true(right)))
+ value = xstrdup("1");
+ else if (compare == 1 && strcmp(left, right) == 0)
value = xstrdup("1");
else if (compare == -1 && strcmp(left, right) != 0)
value = xstrdup("1");
-.\" $OpenBSD: tmux.1,v 1.553 2017/05/29 15:43:48 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.554 2017/05/29 18:06:34 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
.Ql no
if not.
.Pp
-Simple comparisons may be expressed by prefixing two comma-separated
+Comparisons may be expressed by prefixing two comma-separated
alternatives by
.Ql ==
or
if running on
.Ql myhost ,
otherwise by
-.Ql 0.
+.Ql 0 .
An
.Ql m
-specifies a
+specifies an
.Xr fnmatch 3
-comparison - the first argument is the pattern and the second the string to
-compare. For example,
+comparison where the first argument is the pattern and the second the string to
+compare, for example
.Ql #{m:*foo*,#{host}} .
+.Ql ||
+and
+.Ql &&
+evaluate to true if either or both of two comma-separated alternatives are
+true, for example
+.Ql #{||,#{pane_in_mode},#{alternate_on}} .
+A
+.Ql C
+performs a search for an
+.Xr fnmatch 3
+pattern in the pane content and evaluates to zero if not found, or a line
+number if found.
.Pp
A limit may be placed on the length of the resultant string by prefixing it
by an
-/* $OpenBSD: tmux.h,v 1.770 2017/05/17 15:20:23 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.771 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
struct session *, key_code, struct mouse_event *);
int window_pane_outside(struct window_pane *);
int window_pane_visible(struct window_pane *);
-char *window_pane_search(struct window_pane *, const char *,
+u_int window_pane_search(struct window_pane *, const char *);
+char *window_pane_search_old(struct window_pane *, const char *,
u_int *);
const char *window_printable_flags(struct winlink *);
struct window_pane *window_pane_find_up(struct window_pane *);
-/* $OpenBSD: window.c,v 1.194 2017/05/12 10:45:38 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.195 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
return (!window_pane_outside(wp));
}
+u_int
+window_pane_search(struct window_pane *wp, const char *searchstr)
+{
+ struct screen *s = &wp->base;
+ char *newsearchstr, *line;
+ u_int i;
+
+ xasprintf(&newsearchstr, "*%s*", searchstr);
+
+ for (i = 0; i < screen_size_y(s); i++) {
+ line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
+ if (fnmatch(newsearchstr, line, 0) == 0) {
+ free(line);
+ break;
+ }
+ free(line);
+ }
+
+ free(newsearchstr);
+ if (i == screen_size_y(s))
+ return (0);
+ return (i + 1);
+}
+
char *
-window_pane_search(struct window_pane *wp, const char *searchstr,
+window_pane_search_old(struct window_pane *wp, const char *searchstr,
u_int *lineno)
{
struct screen *s = &wp->base;