mirror of
https://github.com/tmux/tmux.git
synced 2026-06-20 17:25:57 +00:00
Merge branch 'master' into floating_panes
This commit is contained in:
85
format.c
85
format.c
@@ -118,6 +118,9 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
|
||||
#define FORMAT_REPEAT 0x200000
|
||||
#define FORMAT_QUOTE_ARGUMENTS 0x400000
|
||||
#define FORMAT_RELATIVE 0x800000
|
||||
#define FORMAT_CLIENT_TERMCAP 0x1000000
|
||||
#define FORMAT_CLIENT_TERMFEAT 0x2000000
|
||||
#define FORMAT_CLIENT_ENVIRON 0x4000000
|
||||
|
||||
/* Limit on recursion. */
|
||||
#define FORMAT_LOOP_LIMIT 100
|
||||
@@ -1162,7 +1165,7 @@ format_cb_pane_at_top(struct format_tree *ft)
|
||||
return (NULL);
|
||||
w = wp->window;
|
||||
|
||||
status = options_get_number(w->options, "pane-border-status");
|
||||
status = window_get_pane_status(w);
|
||||
if (status == PANE_STATUS_TOP)
|
||||
flag = (wp->yoff == 1);
|
||||
else
|
||||
@@ -3792,7 +3795,7 @@ format_table_compare(const void *key0, const void *entry0)
|
||||
}
|
||||
|
||||
/* Get a format callback. */
|
||||
static struct format_table_entry *
|
||||
static const struct format_table_entry *
|
||||
format_table_get(const char *key)
|
||||
{
|
||||
return (bsearch(key, format_table, nitems(format_table),
|
||||
@@ -4087,18 +4090,14 @@ format_relative_time(time_t t)
|
||||
{
|
||||
time_t now, age;
|
||||
u_int d, h, m, s;
|
||||
char out[32], sign;
|
||||
char out[32];
|
||||
|
||||
time(&now);
|
||||
if (t > now)
|
||||
return (NULL);
|
||||
if (t == now)
|
||||
return (xstrdup("0s"));
|
||||
if (t > now) {
|
||||
sign = '+';
|
||||
age = t - now;
|
||||
} else {
|
||||
sign = '-';
|
||||
age = now - t;
|
||||
}
|
||||
age = now - t;
|
||||
|
||||
d = age / 86400;
|
||||
h = (age % 86400) / 3600;
|
||||
@@ -4107,21 +4106,21 @@ format_relative_time(time_t t)
|
||||
|
||||
if (d != 0) {
|
||||
if (h != 0)
|
||||
xsnprintf(out, sizeof out, "%c%ud%uh", sign, d, h);
|
||||
xsnprintf(out, sizeof out, "%ud%uh", d, h);
|
||||
else
|
||||
xsnprintf(out, sizeof out, "%c%ud", sign, d);
|
||||
xsnprintf(out, sizeof out, "%ud", d);
|
||||
} else if (h != 0) {
|
||||
if (m != 0)
|
||||
xsnprintf(out, sizeof out, "%c%uh%um", sign, h, m);
|
||||
xsnprintf(out, sizeof out, "%uh%um", h, m);
|
||||
else
|
||||
xsnprintf(out, sizeof out, "%c%uh", sign, h);
|
||||
xsnprintf(out, sizeof out, "%uh", h);
|
||||
} else if (m != 0) {
|
||||
if (s != 0)
|
||||
xsnprintf(out, sizeof out, "%c%um%us", sign, m, s);
|
||||
xsnprintf(out, sizeof out, "%um%us", m, s);
|
||||
else
|
||||
xsnprintf(out, sizeof out, "%c%um", sign, m);
|
||||
xsnprintf(out, sizeof out, "%um", m);
|
||||
} else
|
||||
xsnprintf(out, sizeof out, "%c%us", sign, s);
|
||||
xsnprintf(out, sizeof out, "%us", s);
|
||||
return (xstrdup(out));
|
||||
}
|
||||
|
||||
@@ -4130,7 +4129,7 @@ static char *
|
||||
format_find(struct format_tree *ft, const char *key, int modifiers,
|
||||
const char *time_format)
|
||||
{
|
||||
struct format_table_entry *fte;
|
||||
const struct format_table_entry *fte;
|
||||
void *value;
|
||||
struct format_entry *fe, fe_find;
|
||||
struct environ_entry *envent;
|
||||
@@ -4443,7 +4442,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
||||
|
||||
/*
|
||||
* Modifiers are a ; separated list of the forms:
|
||||
* l,m,C,a,b,c,d,n,t,w,q,E,T,S,W,P,R,<,>
|
||||
* l,m,C,a,b,c,d,I,n,t,w,q,E,T,S,W,P,R,<,>
|
||||
* =a
|
||||
* =/a
|
||||
* =/a/
|
||||
@@ -4484,7 +4483,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
||||
}
|
||||
|
||||
/* Now try single character with arguments. */
|
||||
if (strchr("mCLNPSst=pReqW", cp[0]) == NULL)
|
||||
if (strchr("ImCLNPSst=pReqW", cp[0]) == NULL)
|
||||
break;
|
||||
c = cp[0];
|
||||
|
||||
@@ -5125,6 +5124,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
struct format_modifier *bool_op_n = NULL;
|
||||
u_int i, count, nsub = 0, nrep;
|
||||
struct format_expand_state next;
|
||||
struct environ_entry *envent;
|
||||
|
||||
/* Set sorting defaults. */
|
||||
sc->order = SORT_ORDER;
|
||||
@@ -5207,6 +5207,16 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
case 'n':
|
||||
modifiers |= FORMAT_LENGTH;
|
||||
break;
|
||||
case 'I':
|
||||
if (fm->argc < 1)
|
||||
break;
|
||||
if (strchr(fm->argv[0], 'f') != NULL)
|
||||
modifiers |= FORMAT_CLIENT_TERMFEAT;
|
||||
if (strchr(fm->argv[0], 'c') != NULL)
|
||||
modifiers |= FORMAT_CLIENT_TERMCAP;
|
||||
if (strchr(fm->argv[0], 'e') != NULL)
|
||||
modifiers |= FORMAT_CLIENT_ENVIRON;
|
||||
break;
|
||||
case 't':
|
||||
modifiers |= FORMAT_TIMESTRING;
|
||||
if (fm->argc < 1)
|
||||
@@ -5218,7 +5228,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
else if (fm->argc >= 2 &&
|
||||
strchr(fm->argv[0], 'f') != NULL) {
|
||||
free(time_format);
|
||||
time_format = format_strip(es, fm->argv[1]);
|
||||
time_format = format_strip(es,
|
||||
fm->argv[1]);
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
@@ -5333,6 +5344,38 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
}
|
||||
}
|
||||
|
||||
/* Look up client capability, feature or environment. */
|
||||
if ((modifiers & FORMAT_CLIENT_TERMCAP) ||
|
||||
(modifiers & FORMAT_CLIENT_TERMFEAT) ||
|
||||
(modifiers & FORMAT_CLIENT_ENVIRON)) {
|
||||
if (ft->c == NULL ||
|
||||
ft->c->tty.term == NULL ||
|
||||
ft->c->flags & CLIENT_UNATTACHEDFLAGS) {
|
||||
value = xstrdup("");
|
||||
goto done;
|
||||
}
|
||||
if (modifiers & FORMAT_CLIENT_TERMCAP) {
|
||||
if (tty_term_has_name(ft->c->tty.term, copy))
|
||||
value = xstrdup("1");
|
||||
else
|
||||
value = xstrdup("0");
|
||||
}
|
||||
if (modifiers & FORMAT_CLIENT_TERMFEAT) {
|
||||
if (tty_feature_present(ft->c->tty.term, copy))
|
||||
value = xstrdup("1");
|
||||
else
|
||||
value = xstrdup("0");
|
||||
}
|
||||
if (modifiers & FORMAT_CLIENT_ENVIRON) {
|
||||
envent = environ_find(ft->c->environ, copy);
|
||||
if (envent != NULL && envent->value != NULL)
|
||||
value = xstrdup(envent->value);
|
||||
else
|
||||
value = xstrdup("");
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Is this a literal string? */
|
||||
if (modifiers & FORMAT_LITERAL) {
|
||||
format_log(es, "literal string is '%s'", copy);
|
||||
|
||||
Reference in New Issue
Block a user