mirror of
https://github.com/tmux/tmux.git
synced 2025-01-26 16:13:34 +00:00
Merge branch 'obsd-master'
This commit is contained in:
commit
5bc5fe5e7e
@ -122,7 +122,7 @@ cmd_find_window_match(struct cmd_find_window_list *find_list,
|
||||
}
|
||||
|
||||
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);
|
||||
|
50
format.c
50
format.c
@ -865,19 +865,17 @@ format_true(const char *s)
|
||||
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);
|
||||
@ -892,6 +890,24 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
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;
|
||||
@ -957,13 +973,25 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
}
|
||||
|
||||
/* 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");
|
||||
|
22
tmux.1
22
tmux.1
@ -3434,7 +3434,7 @@ is enabled, or
|
||||
.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
|
||||
@ -3447,14 +3447,26 @@ will be replaced by
|
||||
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
|
||||
|
3
tmux.h
3
tmux.h
@ -2125,7 +2125,8 @@ void window_pane_key(struct window_pane *, struct client *,
|
||||
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 *);
|
||||
|
26
window.c
26
window.c
@ -1282,8 +1282,32 @@ window_pane_visible(struct window_pane *wp)
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user