Drop having a separate type for style options and make them all strings, which

allows formats to be expanded. Any styles without a '#{' are still validated
when they are set but any with a '#{' are not. Formats are not expanded
usefully in many cases yet, that will be changed later.

To make this work, a few other changes:

- set-option -a with a style option automatically appends a ",".

- OSC 10 and 11 don't set the window-style option anymore, instead the fg and
  bg are stored in the pane struct and act as the defaults that can be
  overridden by window-style.

- status-fg and -bg now override status-style instead of trying to keep them in
  sync.
This commit is contained in:
Nicholas Marriott 2020-04-28 13:50:07 +01:00
parent a43a156846
commit 1f8256fc50
14 changed files with 226 additions and 174 deletions

View File

@ -91,9 +91,9 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window;
struct session *s = target->s;
struct window_pane *wp = target->wp, *lastwp, *markedwp;
struct options *oo = wp->options;
char *title;
const char *style;
struct style *sy;
struct options_entry *o;
if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
@ -147,22 +147,18 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
if (args_has(args, 'P') || args_has(args, 'g')) {
if ((style = args_get(args, 'P')) != NULL) {
o = options_set_style(wp->options, "window-style", 0,
style);
if (o == NULL) {
cmdq_error(item, "bad style: %s", style);
return (CMD_RETURN_ERROR);
}
options_set_style(wp->options, "window-active-style", 0,
style);
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
}
if (args_has(args, 'g')) {
sy = options_get_style(wp->options, "window-style");
cmdq_print(item, "%s", style_tostring(sy));
style = args_get(args, 'P');
if (style != NULL) {
o = options_set_string(oo, "window-style", 0, "%s", style);
if (o == NULL) {
cmdq_error(item, "bad style: %s", style);
return (CMD_RETURN_ERROR);
}
options_set_string(oo, "window-active-style", 0, "%s", style);
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
}
if (args_has(args, 'g')) {
cmdq_print(item, "%s", options_get_string(oo, "window-style"));
return (CMD_RETURN_NORMAL);
}

View File

@ -93,7 +93,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
char *name, *argument, *value = NULL, *cause;
int window, idx, already, error, ambiguous;
int scope;
struct style *sy;
window = (cmd_get_entry(self) == &cmd_set_window_option_entry);
@ -232,16 +231,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
tty_keys_build(&loop->tty);
}
}
if (strcmp(name, "status-fg") == 0 || strcmp(name, "status-bg") == 0) {
sy = options_get_style(oo, "status-style");
sy->gc.fg = options_get_number(oo, "status-fg");
sy->gc.bg = options_get_number(oo, "status-bg");
}
if (strcmp(name, "status-style") == 0) {
sy = options_get_style(oo, "status-style");
options_set_number(oo, "status-fg", sy->gc.fg);
options_set_number(oo, "status-bg", sy->gc.bg);
}
if (strcmp(name, "status") == 0 ||
strcmp(name, "status-interval") == 0)
status_timer_start_all();
@ -282,6 +271,29 @@ fail:
return (CMD_RETURN_ERROR);
}
static int
cmd_set_option_check_string(const struct options_table_entry *oe,
const char *value, char **cause)
{
struct style sy;
if (strcmp(oe->name, "default-shell") == 0 && !checkshell(value)) {
xasprintf(cause, "not a suitable shell: %s", value);
return (-1);
}
if (oe->pattern != NULL && fnmatch(oe->pattern, value, 0) != 0) {
xasprintf(cause, "value is invalid: %s", value);
return (-1);
}
if ((oe->flags & OPTIONS_TABLE_IS_STYLE) &&
strstr(value, "#{") == NULL &&
style_parse(&sy, &grid_default_cell, value) != 0) {
xasprintf(cause, "invalid style: %s", value);
return (-1);
}
return (0);
}
static int
cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
struct options_entry *parent, const char *value)
@ -289,10 +301,9 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
const struct options_table_entry *oe;
struct args *args = cmd_get_args(self);
int append = args_has(args, 'a');
struct options_entry *o;
long long number;
const char *errstr, *new;
char *old;
char *old, *cause;
key_code key;
oe = options_table_entry(parent);
@ -308,17 +319,12 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
old = xstrdup(options_get_string(oo, oe->name));
options_set_string(oo, oe->name, append, "%s", value);
new = options_get_string(oo, oe->name);
if (strcmp(oe->name, "default-shell") == 0 &&
!checkshell(new)) {
if (cmd_set_option_check_string(oe, new, &cause) != 0) {
cmdq_error(item, "%s", cause);
free(cause);
options_set_string(oo, oe->name, 0, "%s", old);
free(old);
cmdq_error(item, "not a suitable shell: %s", value);
return (-1);
}
if (oe->pattern != NULL && fnmatch(oe->pattern, new, 0) != 0) {
options_set_string(oo, oe->name, 0, "%s", old);
free(old);
cmdq_error(item, "value is invalid: %s", value);
return (-1);
}
free(old);
@ -350,13 +356,6 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
return (cmd_set_option_flag(item, oe, oo, value));
case OPTIONS_TABLE_CHOICE:
return (cmd_set_option_choice(item, oe, oo, value));
case OPTIONS_TABLE_STYLE:
o = options_set_style(oo, oe->name, append, value);
if (o == NULL) {
cmdq_error(item, "bad style: %s", value);
return (-1);
}
return (0);
case OPTIONS_TABLE_COMMAND:
break;
}

10
input.c
View File

@ -2484,7 +2484,6 @@ input_osc_10(struct input_ctx *ictx, const char *p)
{
struct window_pane *wp = ictx->wp;
u_int r, g, b;
char tmp[16];
if (wp == NULL)
return;
@ -2493,9 +2492,7 @@ input_osc_10(struct input_ctx *ictx, const char *p)
if (!input_osc_parse_colour(p, &r, &g, &b))
goto bad;
xsnprintf(tmp, sizeof tmp, "fg=#%02x%02x%02x", r, g, b);
options_set_style(wp->options, "window-style", 1, tmp);
options_set_style(wp->options, "window-active-style", 1, tmp);
wp->fg = colour_join_rgb(r, g, b);
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
return;
@ -2510,7 +2507,6 @@ input_osc_11(struct input_ctx *ictx, const char *p)
{
struct window_pane *wp = ictx->wp;
u_int r, g, b;
char tmp[16];
if (wp == NULL)
return;
@ -2519,9 +2515,7 @@ input_osc_11(struct input_ctx *ictx, const char *p)
if (!input_osc_parse_colour(p, &r, &g, &b))
goto bad;
xsnprintf(tmp, sizeof tmp, "bg=#%02x%02x%02x", r, g, b);
options_set_style(wp->options, "window-style", 1, tmp);
options_set_style(wp->options, "window-active-style", 1, tmp);
wp->bg = colour_join_rgb(r, g, b);
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
return;

3
menu.c
View File

@ -151,8 +151,7 @@ menu_draw_cb(struct client *c, __unused struct screen_redraw_ctx *ctx0)
u_int i, px = md->px, py = md->py;
struct grid_cell gc;
memcpy(&gc, &grid_default_cell, sizeof gc);
style_apply(&gc, c->session->curw->window->options, "mode-style");
style_apply(&gc, c->session->curw->window->options, "mode-style", NULL);
screen_write_start(&ctx, NULL, s);
screen_write_clearscreen(&ctx, 8);

View File

@ -557,7 +557,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
memcpy(&gc0, &grid_default_cell, sizeof gc0);
memcpy(&gc, &grid_default_cell, sizeof gc);
style_apply(&gc, oo, "mode-style");
style_apply(&gc, oo, "mode-style", NULL);
w = mtd->width;
h = mtd->height;

View File

@ -400,15 +400,19 @@ const struct options_table_entry options_table[] = {
},
{ .name = "message-command-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "bg=black,fg=yellow"
.default_str = "bg=black,fg=yellow",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "message-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "bg=yellow,fg=black"
.default_str = "bg=yellow,fg=black",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "mouse",
@ -472,13 +476,13 @@ const struct options_table_entry options_table[] = {
{ .name = "status-bg",
.type = OPTIONS_TABLE_COLOUR,
.scope = OPTIONS_TABLE_SESSION,
.default_num = 2,
.default_num = 8,
},
{ .name = "status-fg",
.type = OPTIONS_TABLE_COLOUR,
.scope = OPTIONS_TABLE_SESSION,
.default_num = 0,
.default_num = 8,
},
{ .name = "status-format",
@ -525,9 +529,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "status-left-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "status-position",
@ -554,15 +560,19 @@ const struct options_table_entry options_table[] = {
},
{ .name = "status-right-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "status-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "bg=green,fg=black"
.default_str = "bg=green,fg=black",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "update-environment",
@ -665,9 +675,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "mode-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "bg=yellow,fg=black"
.default_str = "bg=yellow,fg=black",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "monitor-activity",
@ -703,9 +715,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "pane-active-border-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "fg=green"
.default_str = "fg=green",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "pane-base-index",
@ -731,9 +745,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "pane-border-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "remain-on-exit",
@ -749,9 +765,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "window-active-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "window-size",
@ -762,21 +780,27 @@ const struct options_table_entry options_table[] = {
},
{ .name = "window-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "window-status-activity-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "reverse"
.default_str = "reverse",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "window-status-bell-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "reverse"
.default_str = "reverse",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "window-status-current-format",
@ -786,9 +810,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "window-status-current-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "window-status-format",
@ -798,9 +824,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "window-status-last-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "window-status-separator",
@ -810,9 +838,11 @@ const struct options_table_entry options_table[] = {
},
{ .name = "window-status-style",
.type = OPTIONS_TABLE_STYLE,
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default"
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
},
{ .name = "wrap-search",

View File

@ -53,6 +53,9 @@ struct options_entry {
const struct options_table_entry *tableentry;
union options_value value;
int cached;
struct style style;
RB_ENTRY(options_entry) entry;
};
@ -73,9 +76,6 @@ static struct options_entry *options_add(struct options *, const char *);
(o)->tableentry->type == OPTIONS_TABLE_COLOUR || \
(o)->tableentry->type == OPTIONS_TABLE_FLAG || \
(o)->tableentry->type == OPTIONS_TABLE_CHOICE))
#define OPTIONS_IS_STYLE(o) \
((o)->tableentry != NULL && \
(o)->tableentry->type == OPTIONS_TABLE_STYLE)
#define OPTIONS_IS_COMMAND(o) \
((o)->tableentry != NULL && \
(o)->tableentry->type == OPTIONS_TABLE_COMMAND)
@ -123,8 +123,6 @@ options_value_tostring(struct options_entry *o, union options_value *ov,
if (OPTIONS_IS_COMMAND(o))
return (cmd_list_print(ov->cmdlist, 0));
if (OPTIONS_IS_STYLE(o))
return (xstrdup(style_tostring(&ov->style)));
if (OPTIONS_IS_NUMBER(o)) {
switch (o->tableentry->type) {
case OPTIONS_TABLE_NUMBER:
@ -146,7 +144,6 @@ options_value_tostring(struct options_entry *o, union options_value *ov,
s = xstrdup(o->tableentry->choices[ov->number]);
break;
case OPTIONS_TABLE_STRING:
case OPTIONS_TABLE_STYLE:
case OPTIONS_TABLE_COMMAND:
fatalx("not a number option type");
}
@ -258,10 +255,6 @@ options_default(struct options *oo, const struct options_table_entry *oe)
case OPTIONS_TABLE_STRING:
ov->string = xstrdup(oe->default_str);
break;
case OPTIONS_TABLE_STYLE:
style_set(&ov->style, &grid_default_cell);
style_parse(&ov->style, &grid_default_cell, oe->default_str);
break;
default:
ov->number = oe->default_num;
break;
@ -653,25 +646,13 @@ options_get_number(struct options *oo, const char *name)
return (o->value.number);
}
struct style *
options_get_style(struct options *oo, const char *name)
{
struct options_entry *o;
o = options_get(oo, name);
if (o == NULL)
fatalx("missing option %s", name);
if (!OPTIONS_IS_STYLE(o))
fatalx("option %s is not a style", name);
return (&o->value.style);
}
struct options_entry *
options_set_string(struct options *oo, const char *name, int append,
const char *fmt, ...)
{
struct options_entry *o;
va_list ap;
const char *separator = "";
char *s, *value;
va_start(ap, fmt);
@ -680,7 +661,12 @@ options_set_string(struct options *oo, const char *name, int append,
o = options_get_only(oo, name);
if (o != NULL && append && OPTIONS_IS_STRING(o)) {
xasprintf(&value, "%s%s", o->value.string, s);
if (*name != '@') {
separator = o->tableentry->separator;
if (separator == NULL)
separator = "";
}
xasprintf(&value, "%s%s%s", o->value.string, separator, s);
free(s);
} else
value = s;
@ -696,6 +682,7 @@ options_set_string(struct options *oo, const char *name, int append,
fatalx("option %s is not a string", name);
free(o->value.string);
o->value.string = value;
o->cached = 0;
return (o);
}
@ -720,35 +707,6 @@ options_set_number(struct options *oo, const char *name, long long value)
return (o);
}
struct options_entry *
options_set_style(struct options *oo, const char *name, int append,
const char *value)
{
struct options_entry *o;
struct style sy;
if (*name == '@')
fatalx("user option %s must be a string", name);
o = options_get_only(oo, name);
if (o != NULL && append && OPTIONS_IS_STYLE(o))
style_copy(&sy, &o->value.style);
else
style_set(&sy, &grid_default_cell);
if (style_parse(&sy, &grid_default_cell, value) == -1)
return (NULL);
if (o == NULL) {
o = options_default(oo, options_parent_table_entry(oo, name));
if (o == NULL)
return (NULL);
}
if (!OPTIONS_IS_STYLE(o))
fatalx("option %s is not a style", name);
style_copy(&o->value.style, &sy);
return (o);
}
int
options_scope_from_name(struct args *args, int window,
const char *name, struct cmd_find_state *fs, struct options **oo,
@ -874,3 +832,35 @@ options_scope_from_flags(struct args *args, int window,
return (OPTIONS_TABLE_SESSION);
}
}
struct style *
options_string_to_style(struct options *oo, const char *name,
struct format_tree *ft)
{
struct options_entry *o;
const char *s;
char *expanded;
o = options_get(oo, name);
if (o == NULL || !OPTIONS_IS_STRING(o))
return (NULL);
if (o->cached)
return (&o->style);
s = o->value.string;
log_debug("%s: %s is '%s'", __func__, name, s);
o->cached = (strstr(s, "#{") == NULL);
if (ft != NULL && !o->cached) {
expanded = format_expand(ft, s);
if (style_parse(&o->style, &grid_default_cell, expanded) != 0) {
free(expanded);
return (NULL);
}
free(expanded);
} else {
if (style_parse(&o->style, &grid_default_cell, s) != 0)
return (NULL);
}
return (&o->style);
}

View File

@ -260,10 +260,9 @@ screen_redraw_make_pane_status(struct client *c, struct window *w,
struct screen old;
if (wp == w->active)
style_apply(&gc, w->options, "pane-active-border-style");
style_apply(&gc, w->options, "pane-active-border-style", NULL);
else
style_apply(&gc, w->options, "pane-border-style");
style_apply(&gc, w->options, "pane-border-style", NULL);
fmt = options_get_string(w->options, "pane-border-format");
ft = format_create(c, NULL, FORMAT_PANE|wp->id, FORMAT_STATUS);
@ -536,8 +535,8 @@ screen_redraw_draw_borders(struct screen_redraw_ctx *ctx)
log_debug("%s: %s @%u", __func__, c->name, w->id);
style_apply(&other_gc, oo, "pane-border-style");
style_apply(&active_gc, oo, "pane-active-border-style");
style_apply(&other_gc, oo, "pane-border-style", NULL);
style_apply(&active_gc, oo, "pane-active-border-style", NULL);
active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET;
memcpy(&m_other_gc, &other_gc, sizeof m_other_gc);

View File

@ -321,7 +321,7 @@ status_redraw(struct client *c)
struct screen_write_ctx ctx;
struct grid_cell gc;
u_int lines, i, n, width = c->tty.sx;
int flags, force = 0, changed = 0;
int flags, force = 0, changed = 0, fg, bg;
struct options_entry *o;
union options_value *ov;
struct format_tree *ft;
@ -339,7 +339,13 @@ status_redraw(struct client *c)
return (1);
/* Set up default colour. */
style_apply(&gc, s->options, "status-style");
style_apply(&gc, s->options, "status-style", NULL);
fg = options_get_number(s->options, "status-fg");
if (fg != 8)
gc.fg = fg;
bg = options_get_number(s->options, "status-bg");
if (bg != 8)
gc.bg = bg;
if (!grid_cells_equal(&gc, &sl->style)) {
force = 1;
memcpy(&sl->style, &gc, sizeof sl->style);
@ -490,7 +496,7 @@ status_message_redraw(struct client *c)
if (len > c->tty.sx)
len = c->tty.sx;
style_apply(&gc, s->options, "message-style");
style_apply(&gc, s->options, "message-style", NULL);
screen_write_start(&ctx, NULL, sl->active);
screen_write_fast_copy(&ctx, &sl->screen, 0, 0, c->tty.sx, lines - 1);
@ -633,9 +639,9 @@ status_prompt_redraw(struct client *c)
screen_init(sl->active, c->tty.sx, lines, 0);
if (c->prompt_mode == PROMPT_COMMAND)
style_apply(&gc, s->options, "message-command-style");
style_apply(&gc, s->options, "message-command-style", NULL);
else
style_apply(&gc, s->options, "message-style");
style_apply(&gc, s->options, "message-style", NULL);
memcpy(&cursorgc, &gc, sizeof cursorgc);
cursorgc.attr ^= GRID_ATTR_REVERSE;

34
style.c
View File

@ -260,17 +260,37 @@ style_tostring(struct style *sy)
return (s);
}
/* Apply a style. */
/* Apply a style on top of the given style. */
void
style_apply(struct grid_cell *gc, struct options *oo, const char *name)
style_add(struct grid_cell *gc, struct options *oo, const char *name,
struct format_tree *ft)
{
struct style *sy;
struct style *sy;
struct format_tree *ft0 = NULL;
memcpy(gc, &grid_default_cell, sizeof *gc);
sy = options_get_style(oo, name);
gc->fg = sy->gc.fg;
gc->bg = sy->gc.bg;
if (ft == NULL)
ft = ft0 = format_create(NULL, NULL, 0, FORMAT_NOJOBS);
sy = options_string_to_style(oo, name, ft);
if (sy == NULL)
sy = &style_default;
if (sy->gc.fg != 8)
gc->fg = sy->gc.fg;
if (sy->gc.bg != 8)
gc->bg = sy->gc.bg;
gc->attr |= sy->gc.attr;
if (ft0 != NULL)
format_free(ft0);
}
/* Apply a style on top of the default style. */
void
style_apply(struct grid_cell *gc, struct options *oo, const char *name,
struct format_tree *ft)
{
memcpy(gc, &grid_default_cell, sizeof *gc);
style_add(gc, oo, name, ft);
}
/* Initialize style from cell. */

28
tmux.h
View File

@ -898,6 +898,9 @@ struct window_pane {
u_int xoff;
u_int yoff;
int fg;
int bg;
int flags;
#define PANE_REDRAW 0x1
#define PANE_DROP 0x2
@ -1664,7 +1667,6 @@ enum options_table_type {
OPTIONS_TABLE_COLOUR,
OPTIONS_TABLE_FLAG,
OPTIONS_TABLE_CHOICE,
OPTIONS_TABLE_STYLE,
OPTIONS_TABLE_COMMAND
};
@ -1676,12 +1678,13 @@ enum options_table_type {
#define OPTIONS_TABLE_IS_ARRAY 0x1
#define OPTIONS_TABLE_IS_HOOK 0x2
#define OPTIONS_TABLE_IS_STYLE 0x4
struct options_table_entry {
const char *name;
enum options_table_type type;
int scope;
int flags;
int flags;
u_int minimum;
u_int maximum;
@ -1720,7 +1723,7 @@ struct spawn_context {
const char *name;
char **argv;
int argc;
struct environ *environ;
struct environ *environ;
int idx;
const char *cwd;
@ -1900,18 +1903,17 @@ struct options_entry *options_match_get(struct options *, const char *, int *,
int, int *);
const char *options_get_string(struct options *, const char *);
long long options_get_number(struct options *, const char *);
struct style *options_get_style(struct options *, const char *);
struct options_entry * printflike(4, 5) options_set_string(struct options *,
const char *, int, const char *, ...);
struct options_entry *options_set_number(struct options *, const char *,
long long);
struct options_entry *options_set_style(struct options *, const char *, int,
const char *);
int options_scope_from_name(struct args *, int,
const char *, struct cmd_find_state *, struct options **,
char **);
int options_scope_from_flags(struct args *, int,
struct cmd_find_state *, struct options **, char **);
struct style *options_string_to_style(struct options *, const char *,
struct format_tree *);
/* options-table.c */
extern const struct options_table_entry options_table[];
@ -2138,7 +2140,7 @@ enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
int, const char *, int);
/* cmd-parse.c */
void cmd_parse_empty(struct cmd_parse_input *);
void cmd_parse_empty(struct cmd_parse_input *);
struct cmd_parse_result *cmd_parse_from_file(FILE *, struct cmd_parse_input *);
struct cmd_parse_result *cmd_parse_from_string(const char *,
struct cmd_parse_input *);
@ -2229,8 +2231,8 @@ void file_fire_done(struct client_file *);
void file_fire_read(struct client_file *);
int file_can_print(struct client *);
void printflike(2, 3) file_print(struct client *, const char *, ...);
void file_vprint(struct client *, const char *, va_list);
void file_print_buffer(struct client *, void *, size_t);
void file_vprint(struct client *, const char *, va_list);
void file_print_buffer(struct client *, void *, size_t);
void printflike(2, 3) file_error(struct client *, const char *, ...);
void file_write(struct client *, const char *, int, const void *, size_t,
client_file_cb, void *);
@ -2728,7 +2730,7 @@ struct session *session_find_by_id_str(const char *);
struct session *session_find_by_id(u_int);
struct session *session_create(const char *, const char *, const char *,
struct environ *, struct options *, struct termios *);
void session_destroy(struct session *, int, const char *);
void session_destroy(struct session *, int, const char *);
void session_add_ref(struct session *, const char *);
void session_remove_ref(struct session *, const char *);
char *session_check_name(const char *);
@ -2798,7 +2800,7 @@ struct menu *menu_create(const char *);
void menu_add_items(struct menu *, const struct menu_item *,
struct cmdq_item *, struct client *,
struct cmd_find_state *);
void menu_add_item(struct menu *, const struct menu_item *,
void menu_add_item(struct menu *, const struct menu_item *,
struct cmdq_item *, struct client *,
struct cmd_find_state *);
void menu_free(struct menu *);
@ -2821,8 +2823,10 @@ int popup_display(int, struct cmdq_item *, u_int, u_int, u_int,
int style_parse(struct style *,const struct grid_cell *,
const char *);
const char *style_tostring(struct style *);
void style_add(struct grid_cell *, struct options *,
const char *, struct format_tree *);
void style_apply(struct grid_cell *, struct options *,
const char *);
const char *, struct format_tree *);
void style_set(struct style *, const struct grid_cell *);
void style_copy(struct style *, struct style *);

16
tty.c
View File

@ -2686,6 +2686,14 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
return (-1);
}
static void
tty_window_default_style(struct grid_cell *gc, struct window_pane *wp)
{
memcpy(gc, &grid_default_cell, sizeof *gc);
gc->fg = wp->fg;
gc->bg = wp->bg;
}
static void
tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
{
@ -2694,8 +2702,12 @@ tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
if (wp->flags & PANE_STYLECHANGED) {
wp->flags &= ~PANE_STYLECHANGED;
style_apply(&wp->cached_active_gc, oo, "window-active-style");
style_apply(&wp->cached_gc, oo, "window-style");
tty_window_default_style(&wp->cached_active_gc, wp);
style_add(&wp->cached_active_gc, oo, "window-active-style",
NULL);
tty_window_default_style(&wp->cached_gc, wp);
style_add(&wp->cached_gc, oo, "window-style", NULL);
}
if (gc->fg == 8) {

View File

@ -3004,7 +3004,7 @@ window_copy_write_line(struct window_mode_entry *wme,
size_t size = 0;
u_int hsize = screen_hsize(data->backing);
style_apply(&gc, oo, "mode-style");
style_apply(&gc, oo, "mode-style", NULL);
gc.flags |= GRID_FLAG_NOPALETTE;
if (py == 0 && s->rupper < s->rlower && !data->hide_position) {
@ -3311,7 +3311,7 @@ window_copy_set_selection(struct window_mode_entry *wme, int may_redraw,
}
/* Set colours and selection. */
style_apply(&gc, oo, "mode-style");
style_apply(&gc, oo, "mode-style", NULL);
gc.flags |= GRID_FLAG_NOPALETTE;
screen_set_selection(s, sx, sy, endsx, endsy, data->rectflag,
data->modekeys, &gc);

View File

@ -872,6 +872,9 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->fd = -1;
wp->event = NULL;
wp->fg = 8;
wp->bg = 8;
TAILQ_INIT(&wp->modes);
wp->layout_cell = NULL;