Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2019-03-18 15:07:51 +00:00
commit acb2413852
20 changed files with 692 additions and 454 deletions

View File

@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
.name = "display-message",
.alias = "display",
.args = { "c:pt:F:", 0, 1 },
.usage = "[-p] [-c target-client] [-F format] "
.args = { "c:pt:F:v", 0, 1 },
.usage = "[-pv] [-c target-client] [-F format] "
CMD_TARGET_PANE_USAGE " [message]",
.target = { 't', CMD_FIND_PANE, 0 },
@ -60,6 +60,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
const char *template;
char *msg;
struct format_tree *ft;
int flags;
if (args_has(args, 'F') && args->argc != 0) {
cmdq_error(item, "only one of -F or argument must be given");
@ -83,10 +84,14 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
target_c = c;
else
target_c = cmd_find_best_client(s);
ft = format_create(item->client, item, FORMAT_NONE, 0);
if (args_has(self->args, 'v'))
flags = FORMAT_VERBOSE;
else
flags = 0;
ft = format_create(item->client, item, FORMAT_NONE, flags);
format_defaults(ft, target_c, s, wl, wp);
msg = format_expand_time(ft, template, 0);
msg = format_expand_time(ft, template);
if (args_has(self->args, 'p'))
cmdq_print(item, "%s", msg);
else if (c != NULL)

View File

@ -1263,17 +1263,17 @@ found:
no_session:
if (~flags & CMD_FIND_QUIET)
cmdq_error(item, "can't find session %s", session);
cmdq_error(item, "can't find session: %s", session);
goto error;
no_window:
if (~flags & CMD_FIND_QUIET)
cmdq_error(item, "can't find window %s", window);
cmdq_error(item, "can't find window: %s", window);
goto error;
no_pane:
if (~flags & CMD_FIND_QUIET)
cmdq_error(item, "can't find pane %s", pane);
cmdq_error(item, "can't find pane: %s", pane);
goto error;
}
@ -1343,7 +1343,7 @@ cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
/* If no client found, report an error. */
if (c == NULL && !quiet)
cmdq_error(item, "can't find client %s", copy);
cmdq_error(item, "can't find client: %s", copy);
free(copy);
log_debug("%s: target %s, return %p", __func__, target, c);

View File

@ -109,7 +109,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
/* Expand the command. */
ft = format_create(item->client, item, FORMAT_NONE, 0);
format_defaults(ft, c, s, wl, wp);
cmd = format_expand_time(ft, args->argv[0], 0);
cmd = format_expand_time(ft, args->argv[0]);
format_free(ft);
/* Fork the child. */

View File

@ -163,11 +163,9 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
parent = options_get(oo, name);
/* Check that array options and indexes match up. */
if (idx != -1) {
if (*name == '@' || options_array_size(parent, NULL) == -1) {
cmdq_error(item, "not an array: %s", argument);
goto fail;
}
if (idx != -1 && (*name == '@' || !options_isarray(parent))) {
cmdq_error(item, "not an array: %s", argument);
goto fail;
}
/* With -o, check this option is not already set. */
@ -209,7 +207,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
goto fail;
}
options_set_string(oo, name, append, "%s", value);
} else if (idx == -1 && options_array_size(parent, NULL) == -1) {
} else if (idx == -1 && !options_isarray(parent)) {
error = cmd_set_option_set(self, item, oo, parent, value);
if (error != 0)
goto fail;
@ -264,7 +262,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
layout_fix_panes(w);
}
RB_FOREACH(s, sessions, &sessions)
status_update_saved(s);
status_update_cache(s);
/*
* Update sizes and redraw. May not always be necessary but do it

View File

@ -88,20 +88,20 @@ static void
cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
struct options_entry *o, int idx)
{
const char *name;
const char *value;
char *tmp, *escaped;
u_int size, i;
struct options_array_item *a;
const char *name, *value;
char *tmp, *escaped;
if (idx != -1) {
xasprintf(&tmp, "%s[%d]", options_name(o), idx);
name = tmp;
} else {
if (options_array_size(o, &size) != -1) {
for (i = 0; i < size; i++) {
if (options_array_get(o, i) == NULL)
continue;
cmd_show_options_print(self, item, o, i);
if (options_isarray(o)) {
a = options_array_first(o);
while (a != NULL) {
idx = options_array_item_index(a);
cmd_show_options_print(self, item, o, idx);
a = options_array_next(a);
}
return;
}
@ -164,9 +164,10 @@ static enum cmd_retval
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
struct options *oo)
{
struct options_entry *o;
struct options_entry *o;
const struct options_table_entry *oe;
u_int size, idx;
struct options_array_item *a;
u_int idx;
o = options_first(oo);
while (o != NULL) {
@ -175,13 +176,14 @@ cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
o = options_next(o);
continue;
}
if (options_array_size(o, &size) == -1)
if (!options_isarray(o))
cmd_show_options_print(self, item, o, -1);
else {
for (idx = 0; idx < size; idx++) {
if (options_array_get(o, idx) == NULL)
continue;
a = options_array_first(o);
while (a != NULL) {
idx = options_array_item_index(a);
cmd_show_options_print(self, item, o, idx);
a = options_array_next(a);
}
}
o = options_next(o);

38
cmd.c
View File

@ -318,31 +318,31 @@ cmd_stringify_argv(int argc, char **argv)
static int
cmd_try_alias(int *argc, char ***argv)
{
struct options_entry *o;
int old_argc = *argc, new_argc;
char **old_argv = *argv, **new_argv;
u_int size, idx;
int i;
size_t wanted;
const char *s, *cp = NULL;
struct options_entry *o;
struct options_array_item *a;
int old_argc = *argc, new_argc, i;
char **old_argv = *argv, **new_argv;
size_t wanted;
const char *s, *cp = NULL;
o = options_get_only(global_options, "command-alias");
if (o == NULL || options_array_size(o, &size) == -1 || size == 0)
if (o == NULL)
return (-1);
wanted = strlen(old_argv[0]);
for (idx = 0; idx < size; idx++) {
s = options_array_get(o, idx);
if (s == NULL)
continue;
cp = strchr(s, '=');
if (cp == NULL || (size_t)(cp - s) != wanted)
continue;
if (strncmp(old_argv[0], s, wanted) == 0)
break;
a = options_array_first(o);
while (a != NULL) {
s = options_array_item_value(a);
if (s != NULL) {
cp = strchr(s, '=');
if (cp != NULL &&
(size_t)(cp - s) == wanted &&
strncmp(old_argv[0], s, wanted) == 0)
break;
}
a = options_array_next(a);
}
if (idx == size)
if (a == NULL)
return (-1);
if (cmd_string_split(cp + 1, &new_argc, &new_argv) != 0)

View File

@ -174,22 +174,26 @@ environ_unset(struct environ *env, const char *name)
void
environ_update(struct options *oo, struct environ *src, struct environ *dst)
{
struct environ_entry *envent;
struct options_entry *o;
u_int size, idx;
const char *value;
struct environ_entry *envent;
struct options_entry *o;
struct options_array_item *a;
const char *value;
o = options_get(oo, "update-environment");
if (o == NULL || options_array_size(o, &size) == -1)
if (o == NULL)
return;
for (idx = 0; idx < size; idx++) {
value = options_array_get(o, idx);
if (value == NULL)
a = options_array_first(o);
while (a != NULL) {
value = options_array_item_value(a);
if (value == NULL) {
a = options_array_next(a);
continue;
}
if ((envent = environ_find(src, value)) == NULL)
environ_clear(dst, value);
else
environ_set(dst, envent->name, "%s", envent->value);
a = options_array_next(a);
}
}

238
format.c
View File

@ -100,6 +100,9 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_WINDOWS 0x100
#define FORMAT_PANES 0x200
/* Limit on recursion. */
#define FORMAT_LOOP_LIMIT 10
/* Entry in format tree. */
struct format_entry {
char *key;
@ -121,13 +124,15 @@ struct format_tree {
struct client *client;
u_int tag;
int flags;
time_t time;
u_int loop;
RB_HEAD(format_entry_tree, format_entry) tree;
};
static int format_entry_cmp(struct format_entry *, struct format_entry *);
RB_GENERATE_STATIC(format_entry_tree, format_entry, entry, format_entry_cmp);
/* Format modifiers. */
/* Format modifier. */
struct format_modifier {
char modifier[3];
u_int size;
@ -203,6 +208,36 @@ static const char *format_lower[] = {
NULL /* z */
};
/* Is logging enabled? */
static inline int
format_logging(struct format_tree *ft)
{
return (log_get_level() != 0 || (ft->flags & FORMAT_VERBOSE));
}
/* Log a message if verbose. */
static void printflike(3, 4)
format_log1(struct format_tree *ft, const char *from, const char *fmt, ...)
{
va_list ap;
char *s;
static const char spaces[] = " ";
if (!format_logging(ft))
return;
va_start(ap, fmt);
vasprintf(&s, fmt, ap);
va_end(ap);
log_debug("%s: %s", from, s);
if (ft->item != NULL && (ft->flags & FORMAT_VERBOSE))
cmdq_print(ft->item, "#%.*s%s", ft->loop, spaces, s);
free(s);
}
#define format_log(ft, fmt, ...) format_log1(ft, __func__, fmt, ##__VA_ARGS__)
/* Format job update callback. */
static void
format_job_update(struct job *job)
@ -311,7 +346,9 @@ format_job_get(struct format_tree *ft, const char *cmd)
force = (ft->flags & FORMAT_FORCE);
t = time(NULL);
if (fj->job == NULL && (force || fj->last != t)) {
if (force && fj->job != NULL)
job_free(fj->job);
if (force || (fj->job == NULL && fj->last != t)) {
fj->job = job_run(expanded, NULL,
server_client_get_cwd(ft->client, NULL), format_job_update,
format_job_complete, NULL, fj, JOB_NOWAIT);
@ -697,6 +734,7 @@ format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
ft->tag = tag;
ft->flags = flags;
ft->time = time(NULL);
format_add(ft, "version", "%s", VERSION);
format_add_cb(ft, "host", format_cb_host);
@ -1154,7 +1192,9 @@ format_substitute(const char *source, const char *from, const char *to)
static char *
format_loop_sessions(struct format_tree *ft, const char *fmt)
{
struct client *c = ft->client;
struct cmdq_item *item = ft->item;
struct format_tree *nft;
char *expanded, *value;
size_t valuelen;
struct session *s;
@ -1163,7 +1203,12 @@ format_loop_sessions(struct format_tree *ft, const char *fmt)
valuelen = 1;
RB_FOREACH(s, sessions, &sessions) {
expanded = format_single(item, fmt, ft->c, ft->s, NULL, NULL);
format_log(ft, "session loop: $%u", s->id);
nft = format_create(c, item, FORMAT_NONE, ft->flags);
nft->loop = ft->loop;
format_defaults(nft, ft->c, s, NULL, NULL);
expanded = format_expand(nft, fmt);
format_free(nft);
valuelen += strlen(expanded);
value = xrealloc(value, valuelen);
@ -1179,13 +1224,18 @@ format_loop_sessions(struct format_tree *ft, const char *fmt)
static char *
format_loop_windows(struct format_tree *ft, const char *fmt)
{
struct client *c = ft->client;
struct cmdq_item *item = ft->item;
struct format_tree *nft;
char *all, *active, *use, *expanded, *value;
size_t valuelen;
struct winlink *wl;
struct window *w;
if (ft->s == NULL)
if (ft->s == NULL) {
format_log(ft, "window loop but no session");
return (NULL);
}
if (format_choose(ft, fmt, &all, &active, 0) != 0) {
all = xstrdup(fmt);
@ -1196,11 +1246,17 @@ format_loop_windows(struct format_tree *ft, const char *fmt)
valuelen = 1;
RB_FOREACH(wl, winlinks, &ft->s->windows) {
w = wl->window;
format_log(ft, "window loop: %u @%u", wl->idx, w->id);
if (active != NULL && wl == ft->s->curw)
use = active;
else
use = all;
expanded = format_single(item, use, ft->c, ft->s, wl, NULL);
nft = format_create(c, item, FORMAT_WINDOW|w->id, ft->flags);
nft->loop = ft->loop;
format_defaults(nft, ft->c, ft->s, wl, NULL);
expanded = format_expand(nft, use);
format_free(nft);
valuelen += strlen(expanded);
value = xrealloc(value, valuelen);
@ -1219,13 +1275,17 @@ format_loop_windows(struct format_tree *ft, const char *fmt)
static char *
format_loop_panes(struct format_tree *ft, const char *fmt)
{
struct client *c = ft->client;
struct cmdq_item *item = ft->item;
struct format_tree *nft;
char *all, *active, *use, *expanded, *value;
size_t valuelen;
struct window_pane *wp;
if (ft->w == NULL)
if (ft->w == NULL) {
format_log(ft, "pane loop but no window");
return (NULL);
}
if (format_choose(ft, fmt, &all, &active, 0) != 0) {
all = xstrdup(fmt);
@ -1236,11 +1296,16 @@ format_loop_panes(struct format_tree *ft, const char *fmt)
valuelen = 1;
TAILQ_FOREACH(wp, &ft->w->panes, entry) {
format_log(ft, "pane loop: %%%u", wp->id);
if (active != NULL && wp == ft->w->active)
use = active;
else
use = all;
expanded = format_single(item, use, ft->c, ft->s, ft->wl, wp);
nft = format_create(c, item, FORMAT_PANE|wp->id, ft->flags);
nft->loop = ft->loop;
format_defaults(nft, ft->c, ft->s, ft->wl, wp);
expanded = format_expand(nft, use);
format_free(nft);
valuelen += strlen(expanded);
value = xrealloc(value, valuelen);
@ -1264,25 +1329,27 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
const char *errptr, *copy, *cp;
char *copy0, *condition, *found, *new;
char *value, *left, *right;
char tmp[64];
size_t valuelen;
int modifiers = 0, limit = 0;
struct format_modifier *list, *fm, *cmp = NULL, *search = NULL;
struct format_modifier *sub = NULL;
u_int i, count;
int j;
/* Make a copy of the key. */
copy = copy0 = xstrndup(key, keylen);
log_debug("%s: format = '%s'", __func__, copy);
/* Process modifier list. */
list = format_build_modifiers(ft, &copy, &count);
for (i = 0; i < count; i++) {
xsnprintf(tmp, sizeof tmp, "%s: modifier %u", __func__, i);
log_debug("%s = %s", tmp, list[i].modifier);
cmd_log_argv(list[i].argc, list[i].argv, tmp);
fm = &list[i];
if (format_logging(ft)) {
format_log(ft, "modifier %u is %s", i, fm->modifier);
for (j = 0; j < fm->argc; j++) {
format_log(ft, "modifier %u argument %d: %s", i,
j, fm->argv[j]);
}
}
if (fm->size == 1) {
switch (fm->modifier[0]) {
case 'm':
@ -1365,14 +1432,22 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
goto fail;
} else if (search != NULL) {
/* Search in pane. */
if (wp == NULL)
if (wp == NULL) {
format_log(ft, "search '%s' but no pane", copy);
value = xstrdup("0");
else
} else {
format_log(ft, "search '%s' pane %%%u", copy, wp->id);
xasprintf(&value, "%u", window_pane_search(wp, copy));
}
} else if (cmp != NULL) {
/* Comparison of left and right. */
if (format_choose(ft, copy, &left, &right, 1) != 0)
if (format_choose(ft, copy, &left, &right, 1) != 0) {
format_log(ft, "compare %s syntax error: %s",
cmp->modifier, copy);
goto fail;
}
format_log(ft, "compare %s left is: %s", cmp->modifier, left);
format_log(ft, "compare %s right is: %s", cmp->modifier, right);
if (strcmp(cmp->modifier, "||") == 0) {
if (format_true(left) || format_true(right))
@ -1407,9 +1482,12 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
} else if (*copy == '?') {
/* Conditional: check first and choose second or third. */
cp = format_skip(copy + 1, ",");
if (cp == NULL)
if (cp == NULL) {
format_log(ft, "condition syntax error: %s", copy + 1);
goto fail;
}
condition = xstrndup(copy + 1, cp - (copy + 1));
format_log(ft, "condition is: %s", condition);
found = format_find(ft, condition, modifiers);
if (found == NULL) {
@ -1422,27 +1500,42 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
if (strcmp(found, condition) == 0) {
free(found);
found = xstrdup("");
format_log(ft, "condition '%s' found: %s",
condition, found);
} else {
format_log(ft,
"condition '%s' not found; assuming false",
condition);
}
}
free(condition);
} else
format_log(ft, "condition '%s' found", condition);
if (format_choose(ft, cp + 1, &left, &right, 0) != 0) {
format_log(ft, "condition '%s' syntax error: %s",
condition, cp + 1);
free(found);
goto fail;
}
if (format_true(found))
if (format_true(found)) {
format_log(ft, "condition '%s' is true", condition);
value = format_expand(ft, left);
else
} else {
format_log(ft, "condition '%s' is false", condition);
value = format_expand(ft, right);
}
free(right);
free(left);
free(condition);
free(found);
} else {
/* Neither: look up directly. */
value = format_find(ft, copy, modifiers);
if (value == NULL)
if (value == NULL) {
format_log(ft, "format '%s' not found", copy);
value = xstrdup("");
} else
format_log(ft, "format '%s' found: %s", copy, value);
}
done:
@ -1453,7 +1546,7 @@ done:
value = new;
}
else if (modifiers & FORMAT_EXPANDTIME) {
new = format_expand_time(ft, value, 0);
new = format_expand_time(ft, value);
free(value);
value = new;
}
@ -1461,6 +1554,8 @@ done:
/* Perform substitution if any. */
if (sub != NULL) {
new = format_substitute(value, sub->argv[0], sub->argv[1]);
format_log(ft, "substituted '%s' to '%s: %s", sub->argv[0],
sub->argv[1], new);
free(value);
value = new;
}
@ -1468,16 +1563,17 @@ done:
/* Truncate the value if needed. */
if (limit > 0) {
new = utf8_trimcstr(value, limit);
format_log(ft, "applied length limit %d: %s", limit, new);
free(value);
value = new;
} else if (limit < 0) {
new = utf8_rtrimcstr(value, -limit);
format_log(ft, "applied length limit %d: %s", limit, new);
free(value);
value = new;
}
/* Expand the buffer and copy in the value. */
log_debug("%s: '%s' -> '%s'", __func__, copy0, value);
valuelen = strlen(value);
while (*len - *off < valuelen + 1) {
*buf = xreallocarray(*buf, 2, *len);
@ -1486,48 +1582,50 @@ done:
memcpy(*buf + *off, value, valuelen);
*off += valuelen;
format_log(ft, "replaced '%s' with '%s'", copy0, value);
free(value);
format_free_modifiers(list, count);
free(copy0);
return (0);
fail:
format_log(ft, "failed %s", copy0);
format_free_modifiers(list, count);
free(copy0);
return (-1);
}
/* Expand keys in a template, passing through strftime first. */
char *
format_expand_time(struct format_tree *ft, const char *fmt, time_t t)
/* Expand keys in a template. */
static char *
format_expand1(struct format_tree *ft, const char *fmt, int time)
{
char *buf, *out, *name;
const char *ptr, *s;
size_t off, len, n, outlen;
int ch, brackets;
struct tm *tm;
char s[2048];
char expanded[8192];
if (fmt == NULL || *fmt == '\0')
return (xstrdup(""));
if (t == 0)
t = time(NULL);
tm = localtime(&t);
if (strftime(s, sizeof s, fmt, tm) == 0)
if (ft->loop == FORMAT_LOOP_LIMIT)
return (xstrdup(""));
ft->loop++;
return (format_expand(ft, s));
}
format_log(ft, "expanding format: %s", fmt);
/* Expand keys in a template. */
char *
format_expand(struct format_tree *ft, const char *fmt)
{
char *buf, *out, *name;
const char *ptr, *s, *saved = fmt;
size_t off, len, n, outlen;
int ch, brackets;
if (fmt == NULL)
return (xstrdup(""));
if (time) {
tm = localtime(&ft->time);
if (strftime(expanded, sizeof expanded, fmt, tm) == 0) {
format_log(ft, "format is too long");
return (xstrdup(""));
}
if (format_logging(ft) && strcmp(expanded, fmt) != 0)
format_log(ft, "after time expanded: %s", expanded);
fmt = expanded;
}
len = 64;
buf = xmalloc(len);
@ -1544,7 +1642,7 @@ format_expand(struct format_tree *ft, const char *fmt)
}
fmt++;
ch = (u_char) *fmt++;
ch = (u_char)*fmt++;
switch (ch) {
case '(':
brackets = 1;
@ -1558,15 +1656,19 @@ format_expand(struct format_tree *ft, const char *fmt)
break;
n = ptr - fmt;
if (ft->flags & FORMAT_NOJOBS)
out = xstrdup("");
else {
name = xstrndup(fmt, n);
out = format_job_get(ft, name);
free(name);
}
outlen = strlen(out);
name = xstrndup(fmt, n);
format_log(ft, "found #(): %s", name);
if (ft->flags & FORMAT_NOJOBS) {
out = xstrdup("");
format_log(ft, "#() is disabled");
} else {
out = format_job_get(ft, name);
format_log(ft, "#() result: %s", out);
}
free(name);
outlen = strlen(out);
while (len - off < outlen + 1) {
buf = xreallocarray(buf, 2, len);
len *= 2;
@ -1584,6 +1686,7 @@ format_expand(struct format_tree *ft, const char *fmt)
break;
n = ptr - fmt;
format_log(ft, "found #{}: %.*s", (int)n, fmt);
if (format_replace(ft, fmt, n, &buf, &len, &off) != 0)
break;
fmt += n + 1;
@ -1591,6 +1694,7 @@ format_expand(struct format_tree *ft, const char *fmt)
case '}':
case '#':
case ',':
format_log(ft, "found #%c", ch);
while (len - off < 2) {
buf = xreallocarray(buf, 2, len);
len *= 2;
@ -1613,6 +1717,7 @@ format_expand(struct format_tree *ft, const char *fmt)
continue;
}
n = strlen(s);
format_log(ft, "found #%c: %s", ch, s);
if (format_replace(ft, s, n, &buf, &len, &off) != 0)
break;
continue;
@ -1622,10 +1727,26 @@ format_expand(struct format_tree *ft, const char *fmt)
}
buf[off] = '\0';
log_debug("%s: '%s' -> '%s'", __func__, saved, buf);
format_log(ft, "result is: %s", buf);
ft->loop--;
return (buf);
}
/* Expand keys in a template, passing through strftime first. */
char *
format_expand_time(struct format_tree *ft, const char *fmt)
{
return (format_expand1(ft, fmt, 1));
}
/* Expand keys in a template. */
char *
format_expand(struct format_tree *ft, const char *fmt)
{
return (format_expand1(ft, fmt, 0));
}
/* Expand a single string. */
char *
format_single(struct cmdq_item *item, const char *fmt, struct client *c,
@ -1813,6 +1934,11 @@ format_defaults_winlink(struct format_tree *ft, struct winlink *wl)
format_add(ft, "window_flags", "%s", window_printable_flags(wl));
format_add(ft, "window_active", "%d", wl == s->curw);
format_add(ft, "window_start_flag", "%d",
!!(wl == RB_MIN(winlinks, &s->windows)));
format_add(ft, "window_end_flag", "%d",
!!(wl == RB_MAX(winlinks, &s->windows)));
format_add(ft, "window_bell_flag", "%d",
!!(wl->flags & WINLINK_BELL));
format_add(ft, "window_activity_flag", "%d",

175
options.c
View File

@ -30,6 +30,23 @@
* a red-black tree.
*/
struct options_array_item {
u_int index;
char *value;
RB_ENTRY(options_array_item) entry;
};
RB_HEAD(options_array, options_array_item);
static int
options_array_cmp(struct options_array_item *a1, struct options_array_item *a2)
{
if (a1->index < a2->index)
return (-1);
if (a1->index > a2->index)
return (1);
return (0);
}
RB_GENERATE_STATIC(options_array, options_array_item, entry, options_array_cmp);
struct options_entry {
struct options *owner;
@ -40,10 +57,7 @@ struct options_entry {
char *string;
long long number;
struct style style;
struct {
const char **array;
u_int arraysize;
};
struct options_array array;
};
RB_ENTRY(options_entry) entry;
@ -56,8 +70,6 @@ struct options {
static struct options_entry *options_add(struct options *, const char *);
#define OPTIONS_ARRAY_LIMIT 1000
#define OPTIONS_IS_STRING(o) \
((o)->tableentry == NULL || \
(o)->tableentry->type == OPTIONS_TABLE_STRING)
@ -163,18 +175,26 @@ options_empty(struct options *oo, const struct options_table_entry *oe)
o = options_add(oo, oe->name);
o->tableentry = oe;
if (oe->type == OPTIONS_TABLE_ARRAY)
RB_INIT(&o->array);
return (o);
}
struct options_entry *
options_default(struct options *oo, const struct options_table_entry *oe)
{
struct options_entry *o;
struct options_entry *o;
u_int i;
o = options_empty(oo, oe);
if (oe->type == OPTIONS_TABLE_ARRAY)
options_array_assign(o, oe->default_str);
else if (oe->type == OPTIONS_TABLE_STRING)
if (oe->type == OPTIONS_TABLE_ARRAY) {
if (oe->default_arr != NULL) {
for (i = 0; oe->default_arr[i] != NULL; i++)
options_array_set(o, i, oe->default_arr[i], 0);
} else
options_array_assign(o, oe->default_str);
} else if (oe->type == OPTIONS_TABLE_STRING)
o->string = xstrdup(oe->default_str);
else if (oe->type == OPTIONS_TABLE_STYLE) {
style_set(&o->style, &grid_default_cell);
@ -205,15 +225,11 @@ void
options_remove(struct options_entry *o)
{
struct options *oo = o->owner;
u_int i;
if (OPTIONS_IS_STRING(o))
free((void *)o->string);
else if (OPTIONS_IS_ARRAY(o)) {
for (i = 0; i < o->arraysize; i++)
free((void *)o->array[i]);
free(o->array);
}
free(o->string);
else if (OPTIONS_IS_ARRAY(o))
options_array_clear(o);
RB_REMOVE(options_tree, &oo->tree, o);
free(o);
@ -231,62 +247,79 @@ options_table_entry(struct options_entry *o)
return (o->tableentry);
}
static struct options_array_item *
options_array_item(struct options_entry *o, u_int idx)
{
struct options_array_item a;
a.index = idx;
return (RB_FIND(options_array, &o->array, &a));
}
static void
options_array_free(struct options_entry *o, struct options_array_item *a)
{
free(a->value);
RB_REMOVE(options_array, &o->array, a);
free(a);
}
void
options_array_clear(struct options_entry *o)
{
if (OPTIONS_IS_ARRAY(o))
o->arraysize = 0;
struct options_array_item *a, *a1;
if (!OPTIONS_IS_ARRAY(o))
return;
RB_FOREACH_SAFE(a, options_array, &o->array, a1)
options_array_free(o, a);
}
const char *
options_array_get(struct options_entry *o, u_int idx)
{
struct options_array_item *a;
if (!OPTIONS_IS_ARRAY(o))
return (NULL);
if (idx >= o->arraysize)
a = options_array_item(o, idx);
if (a == NULL)
return (NULL);
return (o->array[idx]);
return (a->value);
}
int
options_array_set(struct options_entry *o, u_int idx, const char *value,
int append)
{
char *new;
u_int i;
struct options_array_item *a;
char *new;
if (!OPTIONS_IS_ARRAY(o))
return (-1);
if (idx >= OPTIONS_ARRAY_LIMIT)
return (-1);
if (idx >= o->arraysize) {
o->array = xreallocarray(o->array, idx + 1, sizeof *o->array);
for (i = o->arraysize; i < idx + 1; i++)
o->array[i] = NULL;
o->arraysize = idx + 1;
a = options_array_item(o, idx);
if (value == NULL) {
if (a != NULL)
options_array_free(o, a);
return (0);
}
new = NULL;
if (value != NULL) {
if (o->array[idx] != NULL && append)
xasprintf(&new, "%s%s", o->array[idx], value);
if (a == NULL) {
a = xcalloc(1, sizeof *a);
a->index = idx;
a->value = xstrdup(value);
RB_INSERT(options_array, &o->array, a);
} else {
free(a->value);
if (a != NULL && append)
xasprintf(&new, "%s%s", a->value, value);
else
new = xstrdup(value);
a->value = new;
}
free((void *)o->array[idx]);
o->array[idx] = new;
return (0);
}
int
options_array_size(struct options_entry *o, u_int *size)
{
if (!OPTIONS_IS_ARRAY(o))
return (-1);
if (size != NULL)
*size = o->arraysize;
return (0);
}
@ -305,37 +338,69 @@ options_array_assign(struct options_entry *o, const char *s)
while ((next = strsep(&string, separator)) != NULL) {
if (*next == '\0')
continue;
for (i = 0; i < OPTIONS_ARRAY_LIMIT; i++) {
if (i >= o->arraysize || o->array[i] == NULL)
for (i = 0; i < UINT_MAX; i++) {
if (options_array_item(o, i) == NULL)
break;
}
if (i == OPTIONS_ARRAY_LIMIT)
if (i == UINT_MAX)
break;
options_array_set(o, i, next, 0);
}
free(copy);
}
struct options_array_item *
options_array_first(struct options_entry *o)
{
if (!OPTIONS_IS_ARRAY(o))
return (NULL);
return (RB_MIN(options_array, &o->array));
}
struct options_array_item *
options_array_next(struct options_array_item *a)
{
return (RB_NEXT(options_array, &o->array, a));
}
u_int
options_array_item_index(struct options_array_item *a)
{
return (a->index);
}
const char *
options_array_item_value(struct options_array_item *a)
{
return (a->value);
}
int
options_isarray(struct options_entry *o)
{
return (OPTIONS_IS_ARRAY(o));
}
int
options_isstring(struct options_entry *o)
{
if (o->tableentry == NULL)
return (1);
return (OPTIONS_IS_STRING(o) || OPTIONS_IS_ARRAY(o));
}
const char *
options_tostring(struct options_entry *o, int idx, int numeric)
{
static char s[1024];
const char *tmp;
static char s[1024];
const char *tmp;
struct options_array_item *a;
if (OPTIONS_IS_ARRAY(o)) {
if (idx == -1)
return (NULL);
if ((u_int)idx >= o->arraysize || o->array[idx] == NULL)
a = options_array_item(o, idx);
if (a == NULL)
return ("");
return (o->array[idx]);
return (a->value);
}
if (OPTIONS_IS_STYLE(o))
return (style_tostring(&o->style));

View File

@ -162,7 +162,7 @@ recalculate_sizes(void)
*/
RB_FOREACH(s, sessions, &sessions) {
s->attached = 0;
status_update_saved(s);
status_update_cache(s);
}
/*

View File

@ -569,7 +569,7 @@ screen_redraw_draw_status(struct screen_redraw_ctx *ctx)
struct client *c = ctx->c;
struct window *w = c->session->curw->window;
struct tty *tty = &c->tty;
struct screen *s = &c->status.status;
struct screen *s = c->status.active;
u_int i, y;
log_debug("%s: %s @%u", __func__, c->name, w->id);

View File

@ -202,7 +202,7 @@ server_client_create(int fd)
c->tty.sx = 80;
c->tty.sy = 24;
screen_init(&c->status.status, c->tty.sx, 1, 0);
status_init(c);
c->message_string = NULL;
TAILQ_INIT(&c->message_log);
@ -279,13 +279,7 @@ server_client_lost(struct client *c)
if (c->stderr_data != c->stdout_data)
evbuffer_free(c->stderr_data);
if (event_initialized(&c->status.timer))
evtimer_del(&c->status.timer);
screen_free(&c->status.status);
if (c->status.old_status != NULL) {
screen_free(c->status.old_status);
free(c->status.old_status);
}
status_free(c);
free(c->title);
free((void *)c->cwd);
@ -1547,7 +1541,7 @@ server_client_set_title(struct client *c)
ft = format_create(c, NULL, FORMAT_NONE, 0);
format_defaults(ft, c, NULL, NULL, NULL);
title = format_expand_time(ft, template, 0);
title = format_expand_time(ft, template);
if (c->title == NULL || strcmp(title, c->title) != 0) {
free(c->title);
c->title = xstrdup(title);

View File

@ -135,7 +135,7 @@ session_create(const char *prefix, const char *name, int argc, char **argv,
s->options = oo;
s->hooks = hooks_create(global_hooks);
status_update_saved(s);
status_update_cache(s);
s->tio = NULL;
if (tio != NULL) {

237
status.c
View File

@ -29,14 +29,14 @@
#include "tmux.h"
static char *status_redraw_get_left(struct client *, time_t,
struct grid_cell *, size_t *);
static char *status_redraw_get_right(struct client *, time_t,
struct grid_cell *, size_t *);
static char *status_print(struct client *, struct winlink *, time_t,
static char *status_redraw_get_left(struct client *, struct grid_cell *,
size_t *);
static char *status_redraw_get_right(struct client *, struct grid_cell *,
size_t *);
static char *status_print(struct client *, struct winlink *,
struct grid_cell *);
static char *status_replace(struct client *, struct winlink *, const char *,
time_t);
static char *status_replace(struct client *, struct winlink *,
const char *);
static void status_message_callback(int, short, void *);
static void status_timer_callback(int, short, void *);
@ -194,7 +194,7 @@ status_timer_start_all(void)
/* Update status cache. */
void
status_update_saved(struct session *s)
status_update_cache(struct session *s)
{
if (!options_get_number(s->options, "status"))
s->statusat = -1;
@ -232,8 +232,7 @@ status_line_size(struct client *c)
/* Retrieve options for left string. */
static char *
status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc,
size_t *size)
status_redraw_get_left(struct client *c, struct grid_cell *gc, size_t *size)
{
struct session *s = c->session;
const char *template;
@ -243,7 +242,7 @@ status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc,
style_apply_update(gc, s->options, "status-left-style");
template = options_get_string(s->options, "status-left");
left = status_replace(c, NULL, template, t);
left = status_replace(c, NULL, template);
*size = options_get_number(s->options, "status-left-length");
leftlen = screen_write_cstrlen("%s", left);
@ -254,8 +253,7 @@ status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc,
/* Retrieve options for right string. */
static char *
status_redraw_get_right(struct client *c, time_t t, struct grid_cell *gc,
size_t *size)
status_redraw_get_right(struct client *c, struct grid_cell *gc, size_t *size)
{
struct session *s = c->session;
const char *template;
@ -265,7 +263,7 @@ status_redraw_get_right(struct client *c, time_t t, struct grid_cell *gc,
style_apply_update(gc, s->options, "status-right-style");
template = options_get_string(s->options, "status-right");
right = status_replace(c, NULL, template, t);
right = status_replace(c, NULL, template);
*size = options_get_number(s->options, "status-right-length");
rightlen = screen_write_cstrlen("%s", right);
@ -298,17 +296,69 @@ status_get_window_at(struct client *c, u_int x)
return (NULL);
}
/* Draw status for client on the last lines of given context. */
/* Save old status line. */
static void
status_push_screen(struct client *c)
{
struct status_line *sl = &c->status;
if (sl->active == &sl->screen) {
sl->active = xmalloc(sizeof *sl->active);
screen_init(sl->active, c->tty.sx, status_line_size(c), 0);
}
sl->references++;
}
/* Restore old status line. */
static void
status_pop_screen(struct client *c)
{
struct status_line *sl = &c->status;
if (--sl->references == 0) {
screen_free(sl->active);
free(sl->active);
sl->active = &sl->screen;
}
}
/* Initialize status line. */
void
status_init(struct client *c)
{
struct status_line *sl = &c->status;
screen_init(&sl->screen, c->tty.sx, 1, 0);
sl->active = &sl->screen;
}
/* Free status line. */
void
status_free(struct client *c)
{
struct status_line *sl = &c->status;
if (event_initialized(&sl->timer))
evtimer_del(&sl->timer);
if (sl->active != &sl->screen) {
screen_free(sl->active);
free(sl->active);
}
screen_free(&sl->screen);
}
/* Draw status line for client. */
int
status_redraw(struct client *c)
{
struct status_line *sl = &c->status;
struct screen_write_ctx ctx;
struct session *s = c->session;
struct winlink *wl;
struct screen old_status, window_list;
struct screen old_screen, window_list;
struct grid_cell stdgc, lgc, rgc, gc;
struct options *oo;
time_t t;
char *left, *right;
const char *sep;
u_int offset, needed, lines;
@ -316,12 +366,9 @@ status_redraw(struct client *c)
size_t llen, rlen, seplen;
int larrow, rarrow;
/* Delete the saved status line, if any. */
if (c->status.old_status != NULL) {
screen_free(c->status.old_status);
free(c->status.old_status);
c->status.old_status = NULL;
}
/* Shouldn't get here if not the active screen. */
if (sl->active != &sl->screen)
fatalx("not the active screen");
/* No status line? */
lines = status_line_size(c);
@ -330,16 +377,13 @@ status_redraw(struct client *c)
left = right = NULL;
larrow = rarrow = 0;
/* Store current time. */
t = time(NULL);
/* Set up default colour. */
style_apply(&stdgc, s->options, "status-style");
/* Create the target screen. */
memcpy(&old_status, &c->status.status, sizeof old_status);
screen_init(&c->status.status, c->tty.sx, lines, 0);
screen_write_start(&ctx, NULL, &c->status.status);
memcpy(&old_screen, sl->active, sizeof old_screen);
screen_init(sl->active, c->tty.sx, lines, 0);
screen_write_start(&ctx, NULL, sl->active);
for (offset = 0; offset < lines * c->tty.sx; offset++)
screen_write_putc(&ctx, &stdgc, ' ');
screen_write_stop(&ctx);
@ -350,9 +394,9 @@ status_redraw(struct client *c)
/* Work out left and right strings. */
memcpy(&lgc, &stdgc, sizeof lgc);
left = status_redraw_get_left(c, t, &lgc, &llen);
left = status_redraw_get_left(c, &lgc, &llen);
memcpy(&rgc, &stdgc, sizeof rgc);
right = status_redraw_get_right(c, t, &rgc, &rlen);
right = status_redraw_get_right(c, &rgc, &rlen);
/*
* Figure out how much space we have for the window list. If there
@ -372,7 +416,7 @@ status_redraw(struct client *c)
RB_FOREACH(wl, winlinks, &s->windows) {
free(wl->status_text);
memcpy(&wl->status_cell, &stdgc, sizeof wl->status_cell);
wl->status_text = status_print(c, wl, t, &wl->status_cell);
wl->status_text = status_print(c, wl, &wl->status_cell);
wl->status_width = screen_write_cstrlen("%s", wl->status_text);
if (wl == s->curw)
@ -462,7 +506,7 @@ status_redraw(struct client *c)
draw:
/* Begin drawing. */
screen_write_start(&ctx, NULL, &c->status.status);
screen_write_start(&ctx, NULL, sl->active);
/* Draw the left string and arrow. */
screen_write_cursormove(&ctx, 0, 0, 0);
@ -506,14 +550,14 @@ draw:
wloffset++;
/* Copy the window list. */
c->status.window_list_offset = -wloffset + wlstart;
sl->window_list_offset = -wloffset + wlstart;
screen_write_cursormove(&ctx, wloffset, 0, 0);
screen_write_fast_copy(&ctx, &window_list, wlstart, 0, wlwidth, 1);
screen_free(&window_list);
/* Save left and right size. */
c->status.left_size = llen;
c->status.right_size = rlen;
sl->left_size = llen;
sl->right_size = rlen;
screen_write_stop(&ctx);
@ -521,17 +565,17 @@ out:
free(left);
free(right);
if (grid_compare(c->status.status.grid, old_status.grid) == 0) {
screen_free(&old_status);
if (grid_compare(sl->active->grid, old_screen.grid) == 0) {
screen_free(&old_screen);
return (0);
}
screen_free(&old_status);
screen_free(&old_screen);
return (1);
}
/* Replace special sequences in fmt. */
static char *
status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t)
status_replace(struct client *c, struct winlink *wl, const char *fmt)
{
struct format_tree *ft;
char *expanded;
@ -550,7 +594,7 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t)
ft = format_create(c, NULL, tag, FORMAT_STATUS);
format_defaults(ft, c, NULL, wl, NULL);
expanded = format_expand_time(ft, fmt, t);
expanded = format_expand_time(ft, fmt);
format_free(ft);
return (expanded);
@ -558,8 +602,7 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t)
/* Return winlink status line entry and adjust gc as necessary. */
static char *
status_print(struct client *c, struct winlink *wl, time_t t,
struct grid_cell *gc)
status_print(struct client *c, struct winlink *wl, struct grid_cell *gc)
{
struct options *oo = wl->window->options;
struct session *s = c->session;
@ -580,7 +623,7 @@ status_print(struct client *c, struct winlink *wl, time_t t,
else if (wl->flags & (WINLINK_ACTIVITY|WINLINK_SILENCE))
style_apply_update(gc, oo, "window-status-activity-style");
text = status_replace(c, wl, fmt, t);
text = status_replace(c, wl, fmt);
return (text);
}
@ -593,13 +636,7 @@ status_message_set(struct client *c, const char *fmt, ...)
int delay;
status_message_clear(c);
if (c->status.old_status == NULL) {
c->status.old_status = xmalloc(sizeof *c->status.old_status);
memcpy(c->status.old_status, &c->status.status,
sizeof *c->status.old_status);
screen_init(&c->status.status, c->tty.sx, 1, 0);
}
status_push_screen(c);
va_start(ap, fmt);
xvasprintf(&c->message_string, fmt, ap);
@ -636,7 +673,7 @@ status_message_clear(struct client *c)
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
c->flags |= CLIENT_ALLREDRAWFLAGS; /* was frozen and may have changed */
screen_reinit(&c->status.status);
status_pop_screen(c);
}
/* Clear status line message after timer expires. */
@ -652,23 +689,22 @@ status_message_callback(__unused int fd, __unused short event, void *data)
int
status_message_redraw(struct client *c)
{
struct screen_write_ctx ctx;
struct session *s = c->session;
struct screen old_status;
size_t len;
struct grid_cell gc;
u_int lines, offset;
struct status_line *sl = &c->status;
struct screen_write_ctx ctx;
struct session *s = c->session;
struct screen old_screen;
size_t len;
u_int lines, offset;
struct grid_cell gc;
if (c->tty.sx == 0 || c->tty.sy == 0)
return (0);
memcpy(&old_status, &c->status.status, sizeof old_status);
memcpy(&old_screen, sl->active, sizeof old_screen);
lines = status_line_size(c);
if (lines <= 1) {
if (lines <= 1)
lines = 1;
screen_init(&c->status.status, c->tty.sx, 1, 0);
} else
screen_init(&c->status.status, c->tty.sx, lines, 0);
screen_init(sl->active, c->tty.sx, lines, 0);
len = screen_write_strlen("%s", c->message_string);
if (len > c->tty.sx)
@ -676,7 +712,7 @@ status_message_redraw(struct client *c)
style_apply(&gc, s->options, "message-style");
screen_write_start(&ctx, NULL, &c->status.status);
screen_write_start(&ctx, NULL, sl->active);
screen_write_cursormove(&ctx, 0, 0, 0);
for (offset = 0; offset < lines * c->tty.sx; offset++)
screen_write_putc(&ctx, &gc, ' ');
@ -684,11 +720,11 @@ status_message_redraw(struct client *c)
screen_write_nputs(&ctx, len, &gc, "%s", c->message_string);
screen_write_stop(&ctx);
if (grid_compare(c->status.status.grid, old_status.grid) == 0) {
screen_free(&old_status);
if (grid_compare(sl->active->grid, old_screen.grid) == 0) {
screen_free(&old_screen);
return (0);
}
screen_free(&old_status);
screen_free(&old_screen);
return (1);
}
@ -698,31 +734,23 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
prompt_input_cb inputcb, prompt_free_cb freecb, void *data, int flags)
{
struct format_tree *ft;
time_t t;
char *tmp, *cp;
ft = format_create(c, NULL, FORMAT_NONE, 0);
format_defaults(ft, c, NULL, NULL, NULL);
t = time(NULL);
if (input == NULL)
input = "";
if (flags & PROMPT_NOFORMAT)
tmp = xstrdup(input);
else
tmp = format_expand_time(ft, input, t);
tmp = format_expand_time(ft, input);
status_message_clear(c);
status_prompt_clear(c);
status_push_screen(c);
if (c->status.old_status == NULL) {
c->status.old_status = xmalloc(sizeof *c->status.old_status);
memcpy(c->status.old_status, &c->status.status,
sizeof *c->status.old_status);
screen_init(&c->status.status, c->tty.sx, 1, 0);
}
c->prompt_string = format_expand_time(ft, msg, t);
c->prompt_string = format_expand_time(ft, msg);
c->prompt_buffer = utf8_fromcstr(tmp);
c->prompt_index = utf8_strlen(c->prompt_buffer);
@ -772,7 +800,7 @@ status_prompt_clear(struct client *c)
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
c->flags |= CLIENT_ALLREDRAWFLAGS; /* was frozen and may have changed */
screen_reinit(&c->status.status);
status_pop_screen(c);
}
/* Update status line prompt with a new prompt string. */
@ -780,17 +808,15 @@ void
status_prompt_update(struct client *c, const char *msg, const char *input)
{
struct format_tree *ft;
time_t t;
char *tmp;
ft = format_create(c, NULL, FORMAT_NONE, 0);
format_defaults(ft, c, NULL, NULL, NULL);
t = time(NULL);
tmp = format_expand_time(ft, input, t);
tmp = format_expand_time(ft, input);
free(c->prompt_string);
c->prompt_string = format_expand_time(ft, msg, t);
c->prompt_string = format_expand_time(ft, msg);
free(c->prompt_buffer);
c->prompt_buffer = utf8_fromcstr(tmp);
@ -808,23 +834,22 @@ status_prompt_update(struct client *c, const char *msg, const char *input)
int
status_prompt_redraw(struct client *c)
{
struct status_line *sl = &c->status;
struct screen_write_ctx ctx;
struct session *s = c->session;
struct screen old_status;
u_int i, offset, left, start, pcursor, pwidth, width;
u_int lines;
struct screen old_screen;
u_int i, lines, offset, left, start, width;
u_int pcursor, pwidth;
struct grid_cell gc, cursorgc;
if (c->tty.sx == 0 || c->tty.sy == 0)
return (0);
memcpy(&old_status, &c->status.status, sizeof old_status);
memcpy(&old_screen, sl->active, sizeof old_screen);
lines = status_line_size(c);
if (lines <= 1) {
if (lines <= 1)
lines = 1;
screen_init(&c->status.status, c->tty.sx, 1, 0);
} else
screen_init(&c->status.status, c->tty.sx, lines, 0);
screen_init(sl->active, c->tty.sx, lines, 0);
if (c->prompt_mode == PROMPT_COMMAND)
style_apply(&gc, s->options, "message-command-style");
@ -838,7 +863,7 @@ status_prompt_redraw(struct client *c)
if (start > c->tty.sx)
start = c->tty.sx;
screen_write_start(&ctx, NULL, &c->status.status);
screen_write_start(&ctx, NULL, sl->active);
screen_write_cursormove(&ctx, 0, 0, 0);
for (offset = 0; offset < lines * c->tty.sx; offset++)
screen_write_putc(&ctx, &gc, ' ');
@ -884,18 +909,17 @@ status_prompt_redraw(struct client *c)
screen_write_cell(&ctx, &cursorgc);
}
}
if (c->status.status.cx < screen_size_x(&c->status.status) &&
c->prompt_index >= i)
if (sl->active->cx < screen_size_x(sl->active) && c->prompt_index >= i)
screen_write_putc(&ctx, &cursorgc, ' ');
finished:
screen_write_stop(&ctx);
if (grid_compare(c->status.status.grid, old_status.grid) == 0) {
screen_free(&old_status);
if (grid_compare(sl->active->grid, old_screen.grid) == 0) {
screen_free(&old_screen);
return (0);
}
screen_free(&old_status);
screen_free(&old_screen);
return (1);
}
@ -1486,9 +1510,10 @@ status_prompt_complete_list(u_int *size, const char *s)
const char **layout, *value, *cp;
const struct cmd_entry **cmdent;
const struct options_table_entry *oe;
u_int items, idx;
u_int idx;
size_t slen = strlen(s), valuelen;
struct options_entry *o;
struct options_array_item *a;
const char *layouts[] = {
"even-horizontal", "even-vertical", "main-horizontal",
"main-vertical", "tiled", NULL
@ -1514,16 +1539,22 @@ status_prompt_complete_list(u_int *size, const char *s)
}
}
o = options_get_only(global_options, "command-alias");
if (o != NULL && options_array_size(o, &items) != -1) {
for (idx = 0; idx < items; idx++) {
value = options_array_get(o, idx);
if (o != NULL) {
a = options_array_first(o);
while (a != NULL) {
value = options_array_item_value(a);;
if (value == NULL || (cp = strchr(value, '=')) == NULL)
continue;
goto next;
valuelen = cp - value;
if (slen > valuelen || strncmp(value, s, slen) != 0)
continue;
goto next;
list = xreallocarray(list, (*size) + 1, sizeof *list);
list[(*size)++] = xstrndup(value, valuelen);
next:
a = options_array_next(a);
}
}
for (idx = 0; idx < (*size); idx++)

65
style.c
View File

@ -39,24 +39,24 @@ static struct style style_default = {
int
style_parse(struct style *sy, const struct grid_cell *base, const char *in)
{
struct style saved;
const char delimiters[] = " ,";
char tmp[32];
int value, fg, bg, attr, flags;
size_t end;
struct style saved;
const char delimiters[] = " ,";
char tmp[32];
int value;
size_t end;
if (*in == '\0')
return (0);
if (strchr(delimiters, in[strlen(in) - 1]) != NULL)
return (-1);
style_copy(&saved, sy);
fg = sy->gc.fg;
bg = sy->gc.bg;
attr = sy->gc.attr;
flags = sy->gc.flags;
do {
while (*in != '\0' && strchr(delimiters, *in) != NULL) {
in++;
end--;
}
if (*in == '\0')
break;
end = strcspn(in, delimiters);
if (end > (sizeof tmp) - 1)
goto error;
@ -64,45 +64,40 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in)
tmp[end] = '\0';
if (strcasecmp(tmp, "default") == 0) {
fg = base->fg;
bg = base->bg;
attr = base->attr;
flags = base->flags;
sy->gc.fg = base->fg;
sy->gc.bg = base->bg;
sy->gc.attr = base->attr;
sy->gc.flags = base->flags;
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
if ((value = colour_fromstring(tmp + 3)) == -1)
goto error;
if (*in == 'f' || *in == 'F') {
if (value != 8)
fg = value;
sy->gc.fg = value;
else
fg = base->fg;
sy->gc.fg = base->fg;
} else if (*in == 'b' || *in == 'B') {
if (value != 8)
bg = value;
sy->gc.bg = value;
else
bg = base->bg;
sy->gc.bg = base->bg;
} else
goto error;
} else if (strcasecmp(tmp, "none") == 0)
attr = 0;
sy->gc.attr = 0;
else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
if ((value = attributes_fromstring(tmp + 2)) == -1)
goto error;
attr &= ~value;
sy->gc.attr &= ~value;
} else {
if ((value = attributes_fromstring(tmp)) == -1)
goto error;
attr |= value;
sy->gc.attr |= value;
}
in += end + strspn(in + end, delimiters);
} while (*in != '\0');
sy->gc.fg = fg;
sy->gc.bg = bg;
sy->gc.attr = attr;
sy->gc.flags = flags;
return (0);
error:
@ -122,18 +117,18 @@ style_tostring(struct style *sy)
*s = '\0';
if (gc->fg != 8) {
off += xsnprintf(s + off, sizeof s - off, "%sfg=%s",
comma, colour_tostring(gc->fg));
off += xsnprintf(s + off, sizeof s - off, "%sfg=%s", comma,
colour_tostring(gc->fg));
comma = ",";
}
if (gc->bg != 8) {
off += xsnprintf(s + off, sizeof s - off, "%sbg=%s",
comma, colour_tostring(gc->bg));
off += xsnprintf(s + off, sizeof s - off, "%sbg=%s", comma,
colour_tostring(gc->bg));
comma = ",";
}
if (gc->attr != 0 && gc->attr != GRID_ATTR_CHARSET) {
xsnprintf(s + off, sizeof s - off, "%s%s",
comma, attributes_tostring(gc->attr));
xsnprintf(s + off, sizeof s - off, "%s%s", comma,
attributes_tostring(gc->attr));
comma = ",";
}
@ -174,7 +169,7 @@ style_apply_update(struct grid_cell *gc, struct options *oo, const char *name)
void
style_set(struct style *sy, const struct grid_cell *gc)
{
memset(sy, 0, sizeof *sy);
memcpy(sy, &style_default, sizeof *sy);
memcpy(&sy->gc, gc, sizeof sy->gc);
}

235
tmux.1
View File

@ -2837,82 +2837,19 @@ The default is to run
with
.Fl np .
.It Ic message-command-style Ar style
Set status line message command style, where
.Ar style
is a comma-separated list of characteristics to be specified.
.Pp
The style format is shared by many options and may be:
.Ql bg=colour
to set the background colour,
.Ql fg=colour
to set the foreground colour, and a list of attributes as specified below.
.Pp
The colour is one of:
.Ic black ,
.Ic red ,
.Ic green ,
.Ic yellow ,
.Ic blue ,
.Ic magenta ,
.Ic cyan ,
.Ic white ,
aixterm bright variants (if supported:
.Ic brightred ,
.Ic brightgreen ,
and so on),
.Ic colour0
to
.Ic colour255
from the 256-colour set,
.Ic default
for the default colour (inherited from another option in the case of some options, for example
.Ic window-status-style
inherits from
.Ic status-style ) ,
.Ic terminal
for the terminal default colour, or a hexadecimal RGB string such as
.Ql #ffffff .
.Pp
The attributes is either
.Ic none
or a comma-delimited list of one or more of:
.Ic bright
(or
.Ic bold ) ,
.Ic dim ,
.Ic underscore ,
.Ic blink ,
.Ic reverse ,
.Ic hidden ,
.Ic italics ,
.Ic strikethrough ,
.Ic double-underscore
.Ic curly-underscore
.Ic dotted-underscore
or
.Ic dashed-underscore
to turn an attribute on, or an attribute prefixed with
.Ql no
to turn one off.
.Pp
Examples are:
.Bd -literal -offset indent
fg=yellow,bold,underscore,blink
bg=black,fg=default,noreverse
.Ed
.Pp
With the
.Fl a
flag to the
.Ic set-option
command the new style is added otherwise the existing style is replaced.
Set status line message command style.
For how to specify
.Ar style ,
see the
.Sx STYLES
section.
.It Ic message-style Ar style
Set status line message style.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.It Xo Ic mouse
.Op Ic on | off
.Xc
@ -3019,17 +2956,12 @@ Display
(by default the session name) to the left of the status line.
.Ar string
will be passed through
.Xr strftime 3
and formats (see
.Sx FORMATS )
will be expanded.
It may also contain the special character sequence #[] to change the colour
or attributes, for example
.Ql #[fg=red,bright]
to set a bright red foreground.
See the
.Ic message-command-style
option for a description of colours and attributes.
.Xr strftime 3 .
Also see the
.Sx FORMATS
and
.Sx STYLES
sections.
.Pp
For details on how the names and titles can be set see the
.Sx "NAMES AND TITLES"
@ -3053,8 +2985,8 @@ Set the style of the left part of the status line.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.It Xo Ic status-position
.Op Ic top | bottom
.Xc
@ -3081,15 +3013,15 @@ Set the style of the right part of the status line.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.It Ic status-style Ar style
Set status line style.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.It Ic update-environment[] Ar variable
Set list of environment variables to be copied into the session environment
when a new session is created or an existing session is attached.
@ -3266,8 +3198,8 @@ Set window modes style.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Xo Ic monitor-activity
.Op Ic on | off
@ -3315,8 +3247,8 @@ Set the pane border style for the currently active pane.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
Attributes are ignored.
.Pp
.It Ic pane-base-index Ar index
@ -3337,8 +3269,8 @@ Set the pane border style for panes aside from the active pane.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
Attributes are ignored.
.Pp
.It Xo Ic remain-on-exit
@ -3361,24 +3293,24 @@ Set the style for the window's active pane.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Ic window-status-activity-style Ar style
Set status line style for windows with an activity alert.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Ic window-status-bell-style Ar style
Set status line style for windows with a bell alert.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Ic window-status-current-format Ar string
Like
@ -3390,24 +3322,24 @@ Set status line style for the currently active window.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Ic window-status-format Ar string
Set the format in which the window is displayed in the status line window list.
See the
.Ar status-left
option for details of special character sequences available.
The default is
.Ql #I:#W#F .
.Sx FORMATS
and
.Sx STYLES
sections.
.Pp
.It Ic window-status-last-style Ar style
Set status line style for the last active window.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Ic window-status-separator Ar string
Sets the separator drawn between windows in the status line.
@ -3418,8 +3350,8 @@ Set status line style for a single window.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Xo Ic Ic window-size
.Ar largest | Ar smallest | Ar manual
@ -3448,8 +3380,8 @@ Set the default window style.
For how to specify
.Ar style ,
see the
.Ic message-command-style
option.
.Sx STYLES
section.
.Pp
.It Xo Ic wrap-search
.Op Ic on | off
@ -3978,6 +3910,7 @@ The following variables are available, where appropriate:
.It Li "window_active" Ta "" Ta "1 if window active"
.It Li "window_bell_flag" Ta "" Ta "1 if window has bell"
.It Li "window_bigger" Ta "" Ta "1 if window is larger than client"
.It Li "window_end_flag" Ta "" Ta "1 if window has the highest index"
.It Li "window_flags" Ta "#F" Ta "Window flags"
.It Li "window_format" Ta "" Ta "1 if format is for a window (not assuming the current)"
.It Li "window_height" Ta "" Ta "Height of window"
@ -3992,11 +3925,83 @@ The following variables are available, where appropriate:
.It Li "window_panes" Ta "" Ta "Number of panes in window"
.It Li "window_silence_flag" Ta "" Ta "1 if window has silence alert"
.It Li "window_stack_index" Ta "" Ta "Index in session most recent stack"
.It Li "window_start_flag" Ta "" Ta "1 if window has the lowest index"
.It Li "window_visible_layout" Ta "" Ta "Window layout description, respecting zoomed window panes"
.It Li "window_width" Ta "" Ta "Width of window"
.It Li "window_zoomed_flag" Ta "" Ta "1 if window is zoomed"
.It Li "wrap_flag" Ta "" Ta "Pane wrap flag"
.El
.Sh STYLES
.Nm
offers various options to specify the colour and attributes of aspects of the
interface, for example
.Ic status-style
for the status line.
In addition, embedded styles may be specified in format options, such as
.Ic status-left-format ,
by enclosing them in
.Ql #[
and
.Ql ] .
.Pp
A style may be the single term
.Ql default
to specify the default style (which may inherit from another option) or a space
separated list of the following:
.Bl -tag -width Ds
.It Ic fg=colour
Set the foreground colour.
The colour is one of:
.Ic black ,
.Ic red ,
.Ic green ,
.Ic yellow ,
.Ic blue ,
.Ic magenta ,
.Ic cyan ,
.Ic white ;
if supported the bright variants
.Ic brightred ,
.Ic brightgreen ,
.Ic brightyellow ;
.Ic colour0
to
.Ic colour255
from the 256-colour set;
.Ic default
for the default colour;
.Ic terminal
for the terminal default colour; or a hexadecimal RGB string such as
.Ql #ffffff .
.It Ic bg=colour
Set the background colour.
.It Ic none
Set no attributes (turn off any active attributes).
.It Xo Ic bright (or
.Ic bold )
.Ic dim ,
.Ic underscore ,
.Ic blink ,
.Ic reverse ,
.Ic hidden ,
.Ic italics ,
.Ic strikethrough ,
.Ic double-underscore ,
.Ic curly-underscore ,
.Ic dotted-underscore ,
.Ic dashed-underscore
.Xc
Set an attribute.
Any of the attributes may be prefixed with
.Ql no
to unset.
.El
.Pp
Examples are:
.Bd -literal -offset indent
fg=yellow,bold,underscore,blink
bg=black,fg=default,noreverse
.Ed
.Sh NAMES AND TITLES
.Nm
distinguishes between names and titles.
@ -4277,7 +4282,7 @@ option.
This command works only from inside
.Nm .
.It Xo Ic display-message
.Op Fl p
.Op Fl pv
.Op Fl c Ar target-client
.Op Fl t Ar target-pane
.Op Ar message
@ -4299,6 +4304,10 @@ if
.Fl t
is given, otherwise the active pane for the session attached to
.Ar target-client .
.Pp
With
.Fl v ,
verbose logging is printed as the format is parsed.
.El
.Sh BUFFERS
.Nm

22
tmux.h
View File

@ -52,6 +52,7 @@ struct mode_tree_data;
struct mouse_event;
struct options;
struct options_entry;
struct options_array_item;
struct session;
struct tmuxpeer;
struct tmuxproc;
@ -1316,8 +1317,9 @@ struct cmd_entry {
struct status_line {
struct event timer;
struct screen status;
struct screen *old_status;
struct screen screen;
struct screen *active;
int references;
int window_list_offset;
@ -1436,8 +1438,6 @@ struct client {
struct session *session;
struct session *last_session;
int wlmouse;
int references;
void *pan_window;
@ -1501,6 +1501,7 @@ struct options_table_entry {
const char *default_str;
long long default_num;
const char **default_arr;
const char *separator;
const char *style;
@ -1577,6 +1578,7 @@ char *paste_make_sample(struct paste_buffer *);
#define FORMAT_STATUS 0x1
#define FORMAT_FORCE 0x2
#define FORMAT_NOJOBS 0x4
#define FORMAT_VERBOSE 0x8
#define FORMAT_NONE 0
#define FORMAT_PANE 0x80000000U
#define FORMAT_WINDOW 0x40000000U
@ -1587,7 +1589,7 @@ struct format_tree *format_create(struct client *, struct cmdq_item *, int,
void format_free(struct format_tree *);
void printflike(3, 4) format_add(struct format_tree *, const char *,
const char *, ...);
char *format_expand_time(struct format_tree *, const char *, time_t);
char *format_expand_time(struct format_tree *, const char *);
char *format_expand(struct format_tree *, const char *);
char *format_single(struct cmdq_item *, const char *,
struct client *, struct session *, struct winlink *,
@ -1643,8 +1645,12 @@ void options_array_clear(struct options_entry *);
const char *options_array_get(struct options_entry *, u_int);
int options_array_set(struct options_entry *, u_int, const char *,
int);
int options_array_size(struct options_entry *, u_int *);
void options_array_assign(struct options_entry *, const char *);
struct options_array_item *options_array_first(struct options_entry *);
struct options_array_item *options_array_next(struct options_array_item *);
u_int options_array_item_index(struct options_array_item *);
const char *options_array_item_value(struct options_array_item *);
int options_isarray(struct options_entry *);
int options_isstring(struct options_entry *);
const char *options_tostring(struct options_entry *, int, int);
char *options_parse(const char *, int *);
@ -1969,10 +1975,12 @@ void server_unzoom_window(struct window *);
/* status.c */
void status_timer_start(struct client *);
void status_timer_start_all(void);
void status_update_saved(struct session *);
void status_update_cache(struct session *);
int status_at_line(struct client *);
u_int status_line_size(struct client *);
struct window *status_get_window_at(struct client *, u_int);
void status_init(struct client *);
void status_free(struct client *);
int status_redraw(struct client *);
void printflike(2, 3) status_message_set(struct client *, const char *, ...);
void status_message_clear(struct client *);

View File

@ -398,9 +398,10 @@ tty_keys_build(struct tty *tty)
{
const struct tty_default_key_raw *tdkr;
const struct tty_default_key_code *tdkc;
u_int i, size;
u_int i;
const char *s, *value;
struct options_entry *o;
struct options_array_item *a;
if (tty->key_tree != NULL)
tty_keys_free(tty);
@ -423,11 +424,13 @@ tty_keys_build(struct tty *tty)
}
o = options_get(global_options, "user-keys");
if (o != NULL && options_array_size(o, &size) != -1) {
for (i = 0; i < size; i++) {
value = options_array_get(o, i);
if (o != NULL) {
a = options_array_first(o);
while (a != NULL) {
value = options_array_item_value(a);
if (value != NULL)
tty_keys_add(tty, value, KEYC_USER + i);
a = options_array_next(a);
}
}
}

View File

@ -419,7 +419,8 @@ tty_term_find(char *name, int fd, char **cause)
const struct tty_term_code_entry *ent;
struct tty_code *code;
struct options_entry *o;
u_int size, i;
struct options_array_item *a;
u_int i;
int n, error;
const char *s, *acs;
@ -494,12 +495,12 @@ tty_term_find(char *name, int fd, char **cause)
/* Apply terminal overrides. */
o = options_get_only(global_options, "terminal-overrides");
if (options_array_size(o, &size) != -1) {
for (i = 0; i < size; i++) {
s = options_array_get(o, i);
if (s != NULL)
tty_term_override(term, s);
}
a = options_array_first(o);
while (a != NULL) {
s = options_array_item_value(a);
if (s != NULL)
tty_term_override(term, s);
a = options_array_next(a);
}
/* Delete curses data. */

View File

@ -229,10 +229,7 @@ window_client_draw(__unused void *modedata, void *itemdata,
screen_write_hline(ctx, sx, 0, 0);
screen_write_cursormove(ctx, cx, cy + sy - 1, 0);
if (c->status.old_status != NULL)
screen_write_fast_copy(ctx, c->status.old_status, 0, 0, sx, 1);
else
screen_write_fast_copy(ctx, &c->status.status, 0, 0, sx, 1);
screen_write_fast_copy(ctx, &c->status.screen, 0, 0, sx, 1);
}
static struct screen *