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.
pull/2219/head
nicm 2020-05-16 15:01:30 +00:00
parent 0487029fc5
commit f03b61131b
18 changed files with 514 additions and 350 deletions

View File

@ -54,6 +54,7 @@ cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
window_set_name(wl->window, newname); window_set_name(wl->window, newname);
options_set_number(wl->window->options, "automatic-rename", 0); options_set_number(wl->window->options, "automatic-rename", 0);
server_redraw_window_borders(wl->window);
server_status_window(wl->window); server_status_window(wl->window);
free(newname); free(newname);

View File

@ -91,7 +91,6 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
else else
window_zoom(wp); window_zoom(wp);
server_redraw_window(w); server_redraw_window(w);
server_status_window(w);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
server_unzoom_window(w); server_unzoom_window(w);

View File

@ -90,6 +90,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
} }
wp->flags |= PANE_REDRAW; wp->flags |= PANE_REDRAW;
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
environ_free(sc.environ); environ_free(sc.environ);

View File

@ -91,9 +91,9 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window; struct window *w = wl->window;
struct session *s = target->s; struct session *s = target->s;
struct window_pane *wp = target->wp, *lastwp, *markedwp; struct window_pane *wp = target->wp, *lastwp, *markedwp;
struct options *oo = wp->options;
char *title; char *title;
const char *style; const char *style;
struct style *sy;
struct options_entry *o; struct options_entry *o;
if (entry == &cmd_last_pane_entry || args_has(args, 'l')) { 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); return (CMD_RETURN_NORMAL);
} }
if (args_has(args, 'P') || args_has(args, 'g')) { style = args_get(args, 'P');
if ((style = args_get(args, 'P')) != NULL) { if (style != NULL) {
o = options_set_style(wp->options, "window-style", 0, o = options_set_string(oo, "window-style", 0, "%s", style);
style); if (o == NULL) {
if (o == NULL) { cmdq_error(item, "bad style: %s", style);
cmdq_error(item, "bad style: %s", style); return (CMD_RETURN_ERROR);
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));
} }
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); return (CMD_RETURN_NORMAL);
} }
@ -197,8 +193,10 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'T')) { if (args_has(args, 'T')) {
title = format_single_from_target(item, args_get(args, 'T')); title = format_single_from_target(item, args_get(args, 'T'));
if (screen_set_title(&wp->base, title)) if (screen_set_title(&wp->base, title)) {
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
}
free(title); free(title);
return (CMD_RETURN_NORMAL); 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; char *name, *argument, *value = NULL, *cause;
int window, idx, already, error, ambiguous; int window, idx, already, error, ambiguous;
int scope; int scope;
struct style *sy;
window = (cmd_get_entry(self) == &cmd_set_window_option_entry); 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); 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 || if (strcmp(name, "status") == 0 ||
strcmp(name, "status-interval") == 0) strcmp(name, "status-interval") == 0)
status_timer_start_all(); status_timer_start_all();
@ -282,6 +271,29 @@ fail:
return (CMD_RETURN_ERROR); 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 static int
cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo, cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
struct options_entry *parent, const char *value) 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; const struct options_table_entry *oe;
struct args *args = cmd_get_args(self); struct args *args = cmd_get_args(self);
int append = args_has(args, 'a'); int append = args_has(args, 'a');
struct options_entry *o;
long long number; long long number;
const char *errstr, *new; const char *errstr, *new;
char *old; char *old, *cause;
key_code key; key_code key;
oe = options_table_entry(parent); 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)); old = xstrdup(options_get_string(oo, oe->name));
options_set_string(oo, oe->name, append, "%s", value); options_set_string(oo, oe->name, append, "%s", value);
new = options_get_string(oo, oe->name); new = options_get_string(oo, oe->name);
if (strcmp(oe->name, "default-shell") == 0 && if (cmd_set_option_check_string(oe, new, &cause) != 0) {
!checkshell(new)) { cmdq_error(item, "%s", cause);
free(cause);
options_set_string(oo, oe->name, 0, "%s", old); options_set_string(oo, oe->name, 0, "%s", old);
free(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); return (-1);
} }
free(old); 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)); return (cmd_set_option_flag(item, oe, oo, value));
case OPTIONS_TABLE_CHOICE: case OPTIONS_TABLE_CHOICE:
return (cmd_set_option_choice(item, oe, oo, value)); 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: case OPTIONS_TABLE_COMMAND:
break; break;
} }

29
input.c
View File

@ -1861,8 +1861,10 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
case 0: case 0:
case 2: case 2:
screen_pop_title(sctx->s); screen_pop_title(sctx->s);
if (wp != NULL) if (wp != NULL) {
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
}
break; break;
} }
break; break;
@ -2253,8 +2255,10 @@ input_exit_osc(struct input_ctx *ictx)
switch (option) { switch (option) {
case 0: case 0:
case 2: case 2:
if (screen_set_title(sctx->s, p) && wp != NULL) if (screen_set_title(sctx->s, p) && wp != NULL) {
server_status_window(ictx->wp->window); server_redraw_window_borders(wp->window);
server_status_window(wp->window);
}
break; break;
case 4: case 4:
input_osc_4(ictx, p); input_osc_4(ictx, p);
@ -2262,8 +2266,10 @@ input_exit_osc(struct input_ctx *ictx)
case 7: case 7:
if (utf8_isvalid(p)) { if (utf8_isvalid(p)) {
screen_set_path(sctx->s, p); screen_set_path(sctx->s, p);
if (wp != NULL) if (wp != NULL) {
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
}
} }
break; break;
case 10: case 10:
@ -2314,8 +2320,10 @@ input_exit_apc(struct input_ctx *ictx)
return; return;
log_debug("%s: \"%s\"", __func__, ictx->input_buf); log_debug("%s: \"%s\"", __func__, ictx->input_buf);
if (screen_set_title(sctx->s, ictx->input_buf) && wp != NULL) if (screen_set_title(sctx->s, ictx->input_buf) && wp != NULL) {
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
}
} }
/* Rename string started. */ /* Rename string started. */
@ -2355,6 +2363,7 @@ input_exit_rename(struct input_ctx *ictx)
} }
window_set_name(wp->window, ictx->input_buf); window_set_name(wp->window, ictx->input_buf);
options_set_number(wp->window->options, "automatic-rename", 0); options_set_number(wp->window->options, "automatic-rename", 0);
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
} }
@ -2486,7 +2495,6 @@ input_osc_10(struct input_ctx *ictx, const char *p)
{ {
struct window_pane *wp = ictx->wp; struct window_pane *wp = ictx->wp;
u_int r, g, b; u_int r, g, b;
char tmp[16];
if (wp == NULL) if (wp == NULL)
return; return;
@ -2495,9 +2503,7 @@ input_osc_10(struct input_ctx *ictx, const char *p)
if (!input_osc_parse_colour(p, &r, &g, &b)) if (!input_osc_parse_colour(p, &r, &g, &b))
goto bad; goto bad;
xsnprintf(tmp, sizeof tmp, "fg=#%02x%02x%02x", r, g, b); wp->fg = colour_join_rgb(r, g, b);
options_set_style(wp->options, "window-style", 1, tmp);
options_set_style(wp->options, "window-active-style", 1, tmp);
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
return; return;
@ -2512,7 +2518,6 @@ input_osc_11(struct input_ctx *ictx, const char *p)
{ {
struct window_pane *wp = ictx->wp; struct window_pane *wp = ictx->wp;
u_int r, g, b; u_int r, g, b;
char tmp[16];
if (wp == NULL) if (wp == NULL)
return; return;
@ -2521,9 +2526,7 @@ input_osc_11(struct input_ctx *ictx, const char *p)
if (!input_osc_parse_colour(p, &r, &g, &b)) if (!input_osc_parse_colour(p, &r, &g, &b))
goto bad; goto bad;
xsnprintf(tmp, sizeof tmp, "bg=#%02x%02x%02x", r, g, b); wp->bg = colour_join_rgb(r, g, b);
options_set_style(wp->options, "window-style", 1, tmp);
options_set_style(wp->options, "window-active-style", 1, tmp);
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
return; 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; u_int i, px = md->px, py = md->py;
struct grid_cell gc; struct grid_cell gc;
memcpy(&gc, &grid_default_cell, sizeof gc); style_apply(&gc, c->session->curw->window->options, "mode-style", NULL);
style_apply(&gc, c->session->curw->window->options, "mode-style");
screen_write_start(&ctx, NULL, s); screen_write_start(&ctx, NULL, s);
screen_write_clearscreen(&ctx, 8); 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(&gc0, &grid_default_cell, sizeof gc0);
memcpy(&gc, &grid_default_cell, sizeof gc); memcpy(&gc, &grid_default_cell, sizeof gc);
style_apply(&gc, oo, "mode-style"); style_apply(&gc, oo, "mode-style", NULL);
w = mtd->width; w = mtd->width;
h = mtd->height; h = mtd->height;

View File

@ -96,6 +96,7 @@ check_window_name(struct window *w)
if (strcmp(name, w->name) != 0) { if (strcmp(name, w->name) != 0) {
log_debug("@%u new name %s (was %s)", w->id, name, w->name); log_debug("@%u new name %s (was %s)", w->id, name, w->name);
window_set_name(w, name); window_set_name(w, name);
server_redraw_window_borders(w);
server_status_window(w); server_status_window(w);
} else } else
log_debug("@%u name not changed (still %s)", w->id, w->name); log_debug("@%u name not changed (still %s)", w->id, w->name);

View File

@ -401,15 +401,19 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "message-command-style", { .name = "message-command-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION, .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", { .name = "message-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
.default_str = "bg=yellow,fg=black" .default_str = "bg=yellow,fg=black",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "mouse", { .name = "mouse",
@ -473,13 +477,13 @@ const struct options_table_entry options_table[] = {
{ .name = "status-bg", { .name = "status-bg",
.type = OPTIONS_TABLE_COLOUR, .type = OPTIONS_TABLE_COLOUR,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
.default_num = 2, .default_num = 8,
}, },
{ .name = "status-fg", { .name = "status-fg",
.type = OPTIONS_TABLE_COLOUR, .type = OPTIONS_TABLE_COLOUR,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
.default_num = 0, .default_num = 8,
}, },
{ .name = "status-format", { .name = "status-format",
@ -526,9 +530,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "status-left-style", { .name = "status-left-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "status-position", { .name = "status-position",
@ -555,15 +561,19 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "status-right-style", { .name = "status-right-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "status-style", { .name = "status-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION, .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", { .name = "update-environment",
@ -666,9 +676,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "mode-style", { .name = "mode-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .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", { .name = "monitor-activity",
@ -704,9 +716,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "pane-active-border-style", { .name = "pane-active-border-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.default_str = "fg=green" .default_str = "#{?pane_in_mode,fg=yellow,#{?synchronize-panes,fg=red,fg=green}}",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "pane-base-index", { .name = "pane-base-index",
@ -732,9 +746,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "pane-border-style", { .name = "pane-border-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "remain-on-exit", { .name = "remain-on-exit",
@ -750,9 +766,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "window-active-style", { .name = "window-active-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "window-size", { .name = "window-size",
@ -763,21 +781,27 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "window-style", { .name = "window-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "window-status-activity-style", { .name = "window-status-activity-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.default_str = "reverse" .default_str = "reverse",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "window-status-bell-style", { .name = "window-status-bell-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.default_str = "reverse" .default_str = "reverse",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "window-status-current-format", { .name = "window-status-current-format",
@ -787,9 +811,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "window-status-current-style", { .name = "window-status-current-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "window-status-format", { .name = "window-status-format",
@ -799,9 +825,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "window-status-last-style", { .name = "window-status-last-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "window-status-separator", { .name = "window-status-separator",
@ -811,9 +839,11 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "window-status-style", { .name = "window-status-style",
.type = OPTIONS_TABLE_STYLE, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.default_str = "default" .default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ","
}, },
{ .name = "wrap-search", { .name = "wrap-search",

View File

@ -53,6 +53,9 @@ struct options_entry {
const struct options_table_entry *tableentry; const struct options_table_entry *tableentry;
union options_value value; union options_value value;
int cached;
struct style style;
RB_ENTRY(options_entry) entry; 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_COLOUR || \
(o)->tableentry->type == OPTIONS_TABLE_FLAG || \ (o)->tableentry->type == OPTIONS_TABLE_FLAG || \
(o)->tableentry->type == OPTIONS_TABLE_CHOICE)) (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) \ #define OPTIONS_IS_COMMAND(o) \
((o)->tableentry != NULL && \ ((o)->tableentry != NULL && \
(o)->tableentry->type == OPTIONS_TABLE_COMMAND) (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)) if (OPTIONS_IS_COMMAND(o))
return (cmd_list_print(ov->cmdlist, 0)); return (cmd_list_print(ov->cmdlist, 0));
if (OPTIONS_IS_STYLE(o))
return (xstrdup(style_tostring(&ov->style)));
if (OPTIONS_IS_NUMBER(o)) { if (OPTIONS_IS_NUMBER(o)) {
switch (o->tableentry->type) { switch (o->tableentry->type) {
case OPTIONS_TABLE_NUMBER: 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]); s = xstrdup(o->tableentry->choices[ov->number]);
break; break;
case OPTIONS_TABLE_STRING: case OPTIONS_TABLE_STRING:
case OPTIONS_TABLE_STYLE:
case OPTIONS_TABLE_COMMAND: case OPTIONS_TABLE_COMMAND:
fatalx("not a number option type"); 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: case OPTIONS_TABLE_STRING:
ov->string = xstrdup(oe->default_str); ov->string = xstrdup(oe->default_str);
break; break;
case OPTIONS_TABLE_STYLE:
style_set(&ov->style, &grid_default_cell);
style_parse(&ov->style, &grid_default_cell, oe->default_str);
break;
default: default:
ov->number = oe->default_num; ov->number = oe->default_num;
break; break;
@ -653,25 +646,13 @@ options_get_number(struct options *oo, const char *name)
return (o->value.number); 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 * struct options_entry *
options_set_string(struct options *oo, const char *name, int append, options_set_string(struct options *oo, const char *name, int append,
const char *fmt, ...) const char *fmt, ...)
{ {
struct options_entry *o; struct options_entry *o;
va_list ap; va_list ap;
const char *separator = "";
char *s, *value; char *s, *value;
va_start(ap, fmt); 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); o = options_get_only(oo, name);
if (o != NULL && append && OPTIONS_IS_STRING(o)) { 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); free(s);
} else } else
value = s; 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); fatalx("option %s is not a string", name);
free(o->value.string); free(o->value.string);
o->value.string = value; o->value.string = value;
o->cached = 0;
return (o); return (o);
} }
@ -720,35 +707,6 @@ options_set_number(struct options *oo, const char *name, long long value)
return (o); 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 int
options_scope_from_name(struct args *args, int window, options_scope_from_name(struct args *args, int window,
const char *name, struct cmd_find_state *fs, struct options **oo, const char *name, struct cmd_find_state *fs, struct options **oo,
@ -874,3 +832,37 @@ options_scope_from_flags(struct args *args, int window,
return (OPTIONS_TABLE_SESSION); 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);
style_set(&o->style, &grid_default_cell);
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

@ -45,54 +45,197 @@ static void screen_redraw_draw_pane(struct screen_redraw_ctx *,
#define CELL_BORDERS " xqlkmjwvtun~" #define CELL_BORDERS " xqlkmjwvtun~"
/* Check if cell is on the border of a particular pane. */ const struct grid_cell screen_redraw_border_cell = {
{ { ' ' }, 0, 1, 1 }, GRID_ATTR_CHARSET, 0, 8, 8, 0
};
enum screen_redraw_border_type {
SCREEN_REDRAW_OUTSIDE,
SCREEN_REDRAW_INSIDE,
SCREEN_REDRAW_BORDER
};
/* Return if window has only two panes. */
static int static int
screen_redraw_cell_border1(struct window_pane *wp, u_int px, u_int py) screen_redraw_two_panes(struct window *w, int direction)
{ {
/* Inside pane. */ struct window_pane *wp;
if (px >= wp->xoff && px < wp->xoff + wp->sx &&
py >= wp->yoff && py < wp->yoff + wp->sy) wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
if (wp == NULL)
return (0); /* one pane */
if (TAILQ_NEXT(wp, entry) != NULL)
return (0); /* more than two panes */
if (direction == 0 && wp->xoff == 0)
return (0); return (0);
if (direction == 1 && wp->yoff == 0)
return (0);
return (1);
}
/* Check if cell is on the border of a pane. */
static enum screen_redraw_border_type
screen_redraw_pane_border(struct window_pane *wp, u_int px, u_int py,
int pane_status)
{
u_int ex = wp->xoff + wp->sx, ey = wp->yoff + wp->sy;
/* Inside pane. */
if (px >= wp->xoff && px < ex && py >= wp->yoff && py < ey)
return (SCREEN_REDRAW_INSIDE);
/* Left/right borders. */ /* Left/right borders. */
if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= wp->yoff + wp->sy) { if (pane_status == PANE_STATUS_OFF) {
if (wp->xoff != 0 && px == wp->xoff - 1) if (screen_redraw_two_panes(wp->window, 0)) {
return (1); if (wp->xoff == 0 && px == wp->sx && py <= wp->sy / 2)
if (px == wp->xoff + wp->sx) return (SCREEN_REDRAW_BORDER);
return (2); if (wp->xoff != 0 &&
px == wp->xoff - 1 &&
py > wp->sy / 2)
return (SCREEN_REDRAW_BORDER);
} else {
if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= ey) {
if (wp->xoff != 0 && px == wp->xoff - 1)
return (SCREEN_REDRAW_BORDER);
if (px == ex)
return (SCREEN_REDRAW_BORDER);
}
}
} else {
if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= ey) {
if (wp->xoff != 0 && px == wp->xoff - 1)
return (SCREEN_REDRAW_BORDER);
if (px == ex)
return (SCREEN_REDRAW_BORDER);
}
} }
/* Top/bottom borders. */ /* Top/bottom borders. */
if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= wp->xoff + wp->sx) { if (pane_status == PANE_STATUS_OFF) {
if (wp->yoff != 0 && py == wp->yoff - 1) if (screen_redraw_two_panes(wp->window, 1)) {
return (3); if (wp->yoff == 0 && py == wp->sy && px <= wp->sx / 2)
if (py == wp->yoff + wp->sy) return (SCREEN_REDRAW_BORDER);
return (4); if (wp->yoff != 0 &&
py == wp->yoff - 1 &&
px > wp->sx / 2)
return (SCREEN_REDRAW_BORDER);
} else {
if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= ex) {
if (wp->yoff != 0 && py == wp->yoff - 1)
return (SCREEN_REDRAW_BORDER);
if (py == ey)
return (SCREEN_REDRAW_BORDER);
}
}
} else if (pane_status == PANE_STATUS_TOP) {
if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= ex) {
if (wp->yoff != 0 && py == wp->yoff - 1)
return (SCREEN_REDRAW_BORDER);
}
} else {
if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= ex) {
if (py == ey)
return (SCREEN_REDRAW_BORDER);
}
} }
/* Outside pane. */ /* Outside pane. */
return (-1); return (SCREEN_REDRAW_OUTSIDE);
} }
/* Check if a cell is on the pane border. */ /* Check if a cell is on a border. */
static int static int
screen_redraw_cell_border(struct client *c, u_int px, u_int py) screen_redraw_cell_border(struct client *c, u_int px, u_int py, int pane_status)
{ {
struct window *w = c->session->curw->window; struct window *w = c->session->curw->window;
struct window_pane *wp; struct window_pane *wp;
int retval;
/* Outside the window? */
if (px > w->sx || py > w->sy)
return (0);
/* On the window border? */
if (px == w->sx || py == w->sy)
return (1);
/* Check all the panes. */ /* Check all the panes. */
TAILQ_FOREACH(wp, &w->panes, entry) { TAILQ_FOREACH(wp, &w->panes, entry) {
if (!window_pane_visible(wp)) if (!window_pane_visible(wp))
continue; continue;
if ((retval = screen_redraw_cell_border1(wp, px, py)) != -1) switch (screen_redraw_pane_border(wp, px, py, pane_status)) {
return (!!retval); case SCREEN_REDRAW_INSIDE:
return (0);
case SCREEN_REDRAW_BORDER:
return (1);
case SCREEN_REDRAW_OUTSIDE:
break;
}
} }
return (0); return (0);
} }
/* Work out type of border cell from surrounding cells. */
static int
screen_redraw_type_of_cell(struct client *c, u_int px, u_int py,
int pane_status)
{
struct window *w = c->session->curw->window;
u_int sx = w->sx, sy = w->sy;
int borders = 0;
/*
* Construct a bitmask of whether the cells to the left (bit 4), right,
* top, and bottom (bit 1) of this cell are borders.
*/
if (px == 0 || screen_redraw_cell_border(c, px - 1, py, pane_status))
borders |= 8;
if (px <= sx && screen_redraw_cell_border(c, px + 1, py, pane_status))
borders |= 4;
if (pane_status == PANE_STATUS_TOP) {
if (py != 0 &&
screen_redraw_cell_border(c, px, py - 1, pane_status))
borders |= 2;
} else {
if (py == 0 ||
screen_redraw_cell_border(c, px, py - 1, pane_status))
borders |= 2;
}
if (py <= sy && screen_redraw_cell_border(c, px, py + 1, pane_status))
borders |= 1;
/*
* Figure out what kind of border this cell is. Only one bit set
* doesn't make sense (can't have a border cell with no others
* connected).
*/
switch (borders) {
case 15: /* 1111, left right top bottom */
return (CELL_JOIN);
case 14: /* 1110, left right top */
return (CELL_BOTTOMJOIN);
case 13: /* 1101, left right bottom */
return (CELL_TOPJOIN);
case 12: /* 1100, left right */
return (CELL_TOPBOTTOM);
case 11: /* 1011, left top bottom */
return (CELL_RIGHTJOIN);
case 10: /* 1010, left top */
return (CELL_BOTTOMRIGHT);
case 9: /* 1001, left bottom */
return (CELL_TOPRIGHT);
case 7: /* 0111, right top bottom */
return (CELL_LEFTJOIN);
case 6: /* 0110, right top */
return (CELL_BOTTOMLEFT);
case 5: /* 0101, right bottom */
return (CELL_TOPLEFT);
case 3: /* 0011, top bottom */
return (CELL_LEFTRIGHT);
}
return (CELL_OUTSIDE);
}
/* Check if cell inside a pane. */ /* Check if cell inside a pane. */
static int static int
screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status, screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
@ -100,18 +243,21 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
{ {
struct window *w = c->session->curw->window; struct window *w = c->session->curw->window;
struct window_pane *wp; struct window_pane *wp;
int borders; int border;
u_int right, line; u_int right, line;
*wpp = NULL; *wpp = NULL;
if (px > w->sx || py > w->sy) if (px > w->sx || py > w->sy)
return (CELL_OUTSIDE); return (CELL_OUTSIDE);
if (px == w->sx || py == w->sy) /* window border */
return (screen_redraw_type_of_cell(c, px, py, pane_status));
if (pane_status != PANE_STATUS_OFF) { if (pane_status != PANE_STATUS_OFF) {
TAILQ_FOREACH(wp, &w->panes, entry) { wp = w->active;
do {
if (!window_pane_visible(wp)) if (!window_pane_visible(wp))
continue; goto next1;
if (pane_status == PANE_STATUS_TOP) if (pane_status == PANE_STATUS_TOP)
line = wp->yoff - 1; line = wp->yoff - 1;
@ -121,129 +267,51 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
if (py == line && px >= wp->xoff + 2 && px <= right) if (py == line && px >= wp->xoff + 2 && px <= right)
return (CELL_INSIDE); return (CELL_INSIDE);
}
next1:
wp = TAILQ_NEXT(wp, entry);
if (wp == NULL)
wp = TAILQ_FIRST(&w->panes);
} while (wp != w->active);
} }
TAILQ_FOREACH(wp, &w->panes, entry) { wp = w->active;
do {
if (!window_pane_visible(wp)) if (!window_pane_visible(wp))
continue; goto next2;
*wpp = wp; *wpp = wp;
/* If outside the pane and its border, skip it. */ /*
if ((wp->xoff != 0 && px < wp->xoff - 1) || * If definitely inside, return. If not on border, skip.
px > wp->xoff + wp->sx || * Otherwise work out the cell.
(wp->yoff != 0 && py < wp->yoff - 1) || */
py > wp->yoff + wp->sy) border = screen_redraw_pane_border(wp, px, py, pane_status);
continue; if (border == SCREEN_REDRAW_INSIDE)
/* If definitely inside, return so. */
if (!screen_redraw_cell_border(c, px, py))
return (CELL_INSIDE); return (CELL_INSIDE);
if (border == SCREEN_REDRAW_OUTSIDE)
goto next2;
return (screen_redraw_type_of_cell(c, px, py, pane_status));
/* next2:
* Construct a bitmask of whether the cells to the left (bit wp = TAILQ_NEXT(wp, entry);
* 4), right, top, and bottom (bit 1) of this cell are borders. if (wp == NULL)
*/ wp = TAILQ_FIRST(&w->panes);
borders = 0; } while (wp != w->active);
if (px == 0 || screen_redraw_cell_border(c, px - 1, py))
borders |= 8;
if (px <= w->sx && screen_redraw_cell_border(c, px + 1, py))
borders |= 4;
if (pane_status == PANE_STATUS_TOP) {
if (py != 0 && screen_redraw_cell_border(c, px, py - 1))
borders |= 2;
} else {
if (py == 0 || screen_redraw_cell_border(c, px, py - 1))
borders |= 2;
}
if (py <= w->sy && screen_redraw_cell_border(c, px, py + 1))
borders |= 1;
/*
* Figure out what kind of border this cell is. Only one bit
* set doesn't make sense (can't have a border cell with no
* others connected).
*/
switch (borders) {
case 15: /* 1111, left right top bottom */
return (CELL_JOIN);
case 14: /* 1110, left right top */
return (CELL_BOTTOMJOIN);
case 13: /* 1101, left right bottom */
return (CELL_TOPJOIN);
case 12: /* 1100, left right */
return (CELL_TOPBOTTOM);
case 11: /* 1011, left top bottom */
return (CELL_RIGHTJOIN);
case 10: /* 1010, left top */
return (CELL_BOTTOMRIGHT);
case 9: /* 1001, left bottom */
return (CELL_TOPRIGHT);
case 7: /* 0111, right top bottom */
return (CELL_LEFTJOIN);
case 6: /* 0110, right top */
return (CELL_BOTTOMLEFT);
case 5: /* 0101, right bottom */
return (CELL_TOPLEFT);
case 3: /* 0011, top bottom */
return (CELL_LEFTRIGHT);
}
}
return (CELL_OUTSIDE); return (CELL_OUTSIDE);
} }
/* Check if the border of a particular pane. */ /* Check if the border of a particular pane. */
static int static int
screen_redraw_check_is(u_int px, u_int py, int type, int pane_status, screen_redraw_check_is(u_int px, u_int py, int pane_status,
struct window *w, struct window_pane *wantwp, struct window_pane *wp) struct window_pane *wp)
{ {
int border; enum screen_redraw_border_type border;
/* Is this off the active pane border? */ border = screen_redraw_pane_border(wp, px, py, pane_status);
border = screen_redraw_cell_border1(wantwp, px, py); if (border == SCREEN_REDRAW_BORDER)
if (border == 0 || border == -1)
return (0);
if (pane_status == PANE_STATUS_TOP && border == 4)
return (0);
if (pane_status == PANE_STATUS_BOTTOM && border == 3)
return (0);
/* If there are more than two panes, that's enough. */
if (window_count_panes(w) != 2)
return (1); return (1);
return (0);
/* Else if the cell is not a border cell, forget it. */
if (wp == NULL || (type == CELL_OUTSIDE || type == CELL_INSIDE))
return (1);
/* With status lines mark the entire line. */
if (pane_status != PANE_STATUS_OFF)
return (1);
/* Check if the pane covers the whole width. */
if (wp->xoff == 0 && wp->sx == w->sx) {
/* This can either be the top pane or the bottom pane. */
if (wp->yoff == 0) { /* top pane */
if (wp == wantwp)
return (px <= wp->sx / 2);
return (px > wp->sx / 2);
}
return (0);
}
/* Check if the pane covers the whole height. */
if (wp->yoff == 0 && wp->sy == w->sy) {
/* This can either be the left pane or the right pane. */
if (wp->xoff == 0) { /* left pane */
if (wp == wantwp)
return (py <= wp->sy / 2);
return (py > wp->sy / 2);
}
return (0);
}
return (1);
} }
/* Update pane status. */ /* Update pane status. */
@ -259,15 +327,14 @@ screen_redraw_make_pane_status(struct client *c, struct window *w,
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
struct screen old; struct screen old;
if (wp == w->active)
style_apply(&gc, w->options, "pane-active-border-style");
else
style_apply(&gc, w->options, "pane-border-style");
fmt = options_get_string(w->options, "pane-border-format");
ft = format_create(c, NULL, FORMAT_PANE|wp->id, FORMAT_STATUS); ft = format_create(c, NULL, FORMAT_PANE|wp->id, FORMAT_STATUS);
format_defaults(ft, c, NULL, NULL, wp); format_defaults(ft, c, c->session, c->session->curw, wp);
if (wp == w->active)
style_apply(&gc, w->options, "pane-active-border-style", ft);
else
style_apply(&gc, w->options, "pane-border-style", ft);
fmt = options_get_string(w->options, "pane-border-format");
expanded = format_expand_time(ft, fmt); expanded = format_expand_time(ft, fmt);
if (wp->sx < 4) if (wp->sx < 4)
@ -482,39 +549,73 @@ screen_redraw_pane(struct client *c, struct window_pane *wp)
tty_reset(&c->tty); tty_reset(&c->tty);
} }
/* Draw a border cell. */ /* Get border cell style. */
static void static const struct grid_cell *
screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j, screen_redraw_draw_borders_style(struct screen_redraw_ctx *ctx, u_int x,
struct grid_cell *m_active_gc, struct grid_cell *active_gc, u_int y, struct window_pane *wp)
struct grid_cell *m_other_gc, struct grid_cell *other_gc)
{ {
struct client *c = ctx->c; struct client *c = ctx->c;
struct session *s = c->session; struct session *s = c->session;
struct window *w = s->curw->window; struct window *w = s->curw->window;
struct options *oo = w->options;
struct grid_cell *gc;
struct format_tree *ft;
if (wp->border_gc_set)
return (&wp->border_gc);
wp->border_gc_set = 1;
ft = format_create_defaults(NULL, c, s, s->curw, wp);
gc = &wp->border_gc;
if (screen_redraw_check_is(x, y, ctx->pane_status, w->active)) {
style_apply(gc, oo, "pane-active-border-style", ft);
gc->attr |= GRID_ATTR_CHARSET;
} else {
style_apply(gc, oo, "pane-border-style", ft);
gc->attr |= GRID_ATTR_CHARSET;
}
format_free(ft);
return (gc);
}
/* Draw a border cell. */
static void
screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
{
struct client *c = ctx->c;
struct session *s = c->session;
struct tty *tty = &c->tty; struct tty *tty = &c->tty;
struct window_pane *wp; struct window_pane *wp;
struct window_pane *active = w->active;
struct window_pane *marked = marked_pane.wp;
u_int type, x = ctx->ox + i, y = ctx->oy + j; u_int type, x = ctx->ox + i, y = ctx->oy + j;
int flag, pane_status = ctx->pane_status; int pane_status = ctx->pane_status;
const struct grid_cell *gc;
struct grid_cell copy;
if (c->overlay_check != NULL && !c->overlay_check(c, x, y)) if (c->overlay_check != NULL && !c->overlay_check(c, x, y))
return; return;
type = screen_redraw_check_cell(c, x, y, pane_status, &wp); type = screen_redraw_check_cell(c, x, y, pane_status, &wp);
if (type == CELL_INSIDE) if (type == CELL_INSIDE)
return; return;
flag = screen_redraw_check_is(x, y, type, pane_status, w, active, wp);
if (server_is_marked(s, s->curw, marked_pane.wp) && if (wp == NULL)
screen_redraw_check_is(x, y, type, pane_status, w, marked, wp)) { gc = &screen_redraw_border_cell;
if (flag) else {
tty_attributes(tty, m_active_gc, NULL); gc = screen_redraw_draw_borders_style(ctx, x, y, wp);
else if (gc == NULL)
tty_attributes(tty, m_other_gc, NULL); return;
} else if (flag)
tty_attributes(tty, active_gc, NULL); if (server_is_marked(s, s->curw, marked_pane.wp) &&
else screen_redraw_check_is(x, y, pane_status, marked_pane.wp)) {
tty_attributes(tty, other_gc, NULL); memcpy(&copy, gc, sizeof copy);
copy.attr ^= GRID_ATTR_REVERSE;
gc = &copy;
}
}
tty_attributes(tty, gc, NULL);
if (ctx->statustop) if (ctx->statustop)
tty_cursor(tty, i, ctx->statuslines + j); tty_cursor(tty, i, ctx->statuslines + j);
else else
@ -529,27 +630,17 @@ screen_redraw_draw_borders(struct screen_redraw_ctx *ctx)
struct client *c = ctx->c; struct client *c = ctx->c;
struct session *s = c->session; struct session *s = c->session;
struct window *w = s->curw->window; struct window *w = s->curw->window;
struct tty *tty = &c->tty; struct window_pane *wp;
struct options *oo = w->options;
struct grid_cell m_active_gc, active_gc, m_other_gc, other_gc;
u_int i, j; u_int i, j;
log_debug("%s: %s @%u", __func__, c->name, w->id); log_debug("%s: %s @%u", __func__, c->name, w->id);
style_apply(&other_gc, oo, "pane-border-style"); TAILQ_FOREACH(wp, &w->panes, entry)
style_apply(&active_gc, oo, "pane-active-border-style"); wp->border_gc_set = 0;
active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET;
memcpy(&m_other_gc, &other_gc, sizeof m_other_gc); for (j = 0; j < c->tty.sy - ctx->statuslines; j++) {
m_other_gc.attr ^= GRID_ATTR_REVERSE; for (i = 0; i < c->tty.sx; i++)
memcpy(&m_active_gc, &active_gc, sizeof m_active_gc); screen_redraw_draw_borders_cell(ctx, i, j);
m_active_gc.attr ^= GRID_ATTR_REVERSE;
for (j = 0; j < tty->sy - ctx->statuslines; j++) {
for (i = 0; i < tty->sx; i++) {
screen_redraw_draw_borders_cell(ctx, i, j,
&m_active_gc, &active_gc, &m_other_gc, &other_gc);
}
} }
} }

View File

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

34
style.c
View File

@ -260,17 +260,37 @@ style_tostring(struct style *sy)
return (s); return (s);
} }
/* Apply a style. */ /* Apply a style on top of the given style. */
void 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); if (ft == NULL)
sy = options_get_style(oo, name); ft = ft0 = format_create(NULL, NULL, 0, FORMAT_NOJOBS);
gc->fg = sy->gc.fg;
gc->bg = sy->gc.bg; 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; 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. */ /* Initialize style from cell. */

31
tmux.h
View File

@ -896,6 +896,9 @@ struct window_pane {
u_int xoff; u_int xoff;
u_int yoff; u_int yoff;
int fg;
int bg;
int flags; int flags;
#define PANE_REDRAW 0x1 #define PANE_REDRAW 0x1
#define PANE_DROP 0x2 #define PANE_DROP 0x2
@ -950,6 +953,9 @@ struct window_pane {
size_t written; size_t written;
size_t skipped; size_t skipped;
int border_gc_set;
struct grid_cell border_gc;
TAILQ_ENTRY(window_pane) entry; TAILQ_ENTRY(window_pane) entry;
RB_ENTRY(window_pane) tree_entry; RB_ENTRY(window_pane) tree_entry;
}; };
@ -1662,7 +1668,6 @@ enum options_table_type {
OPTIONS_TABLE_COLOUR, OPTIONS_TABLE_COLOUR,
OPTIONS_TABLE_FLAG, OPTIONS_TABLE_FLAG,
OPTIONS_TABLE_CHOICE, OPTIONS_TABLE_CHOICE,
OPTIONS_TABLE_STYLE,
OPTIONS_TABLE_COMMAND OPTIONS_TABLE_COMMAND
}; };
@ -1674,12 +1679,13 @@ enum options_table_type {
#define OPTIONS_TABLE_IS_ARRAY 0x1 #define OPTIONS_TABLE_IS_ARRAY 0x1
#define OPTIONS_TABLE_IS_HOOK 0x2 #define OPTIONS_TABLE_IS_HOOK 0x2
#define OPTIONS_TABLE_IS_STYLE 0x4
struct options_table_entry { struct options_table_entry {
const char *name; const char *name;
enum options_table_type type; enum options_table_type type;
int scope; int scope;
int flags; int flags;
u_int minimum; u_int minimum;
u_int maximum; u_int maximum;
@ -1718,7 +1724,7 @@ struct spawn_context {
const char *name; const char *name;
char **argv; char **argv;
int argc; int argc;
struct environ *environ; struct environ *environ;
int idx; int idx;
const char *cwd; const char *cwd;
@ -1898,18 +1904,17 @@ struct options_entry *options_match_get(struct options *, const char *, int *,
int, int *); int, int *);
const char *options_get_string(struct options *, const char *); const char *options_get_string(struct options *, const char *);
long long options_get_number(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 *, struct options_entry * printflike(4, 5) options_set_string(struct options *,
const char *, int, const char *, ...); const char *, int, const char *, ...);
struct options_entry *options_set_number(struct options *, const char *, struct options_entry *options_set_number(struct options *, const char *,
long long); long long);
struct options_entry *options_set_style(struct options *, const char *, int,
const char *);
int options_scope_from_name(struct args *, int, int options_scope_from_name(struct args *, int,
const char *, struct cmd_find_state *, struct options **, const char *, struct cmd_find_state *, struct options **,
char **); char **);
int options_scope_from_flags(struct args *, int, int options_scope_from_flags(struct args *, int,
struct cmd_find_state *, struct options **, char **); struct cmd_find_state *, struct options **, char **);
struct style *options_string_to_style(struct options *, const char *,
struct format_tree *);
/* options-table.c */ /* options-table.c */
extern const struct options_table_entry options_table[]; extern const struct options_table_entry options_table[];
@ -2136,7 +2141,7 @@ enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
int, const char *, int); int, const char *, int);
/* cmd-parse.c */ /* 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_file(FILE *, struct cmd_parse_input *);
struct cmd_parse_result *cmd_parse_from_string(const char *, struct cmd_parse_result *cmd_parse_from_string(const char *,
struct cmd_parse_input *); struct cmd_parse_input *);
@ -2227,8 +2232,8 @@ void file_fire_done(struct client_file *);
void file_fire_read(struct client_file *); void file_fire_read(struct client_file *);
int file_can_print(struct client *); int file_can_print(struct client *);
void printflike(2, 3) file_print(struct client *, const char *, ...); void printflike(2, 3) file_print(struct client *, const char *, ...);
void file_vprint(struct client *, const char *, va_list); void file_vprint(struct client *, const char *, va_list);
void file_print_buffer(struct client *, void *, size_t); void file_print_buffer(struct client *, void *, size_t);
void printflike(2, 3) file_error(struct client *, const char *, ...); void printflike(2, 3) file_error(struct client *, const char *, ...);
void file_write(struct client *, const char *, int, const void *, size_t, void file_write(struct client *, const char *, int, const void *, size_t,
client_file_cb, void *); client_file_cb, void *);
@ -2726,7 +2731,7 @@ struct session *session_find_by_id_str(const char *);
struct session *session_find_by_id(u_int); struct session *session_find_by_id(u_int);
struct session *session_create(const char *, const char *, const char *, struct session *session_create(const char *, const char *, const char *,
struct environ *, struct options *, struct termios *); 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_add_ref(struct session *, const char *);
void session_remove_ref(struct session *, const char *); void session_remove_ref(struct session *, const char *);
char *session_check_name(const char *); char *session_check_name(const char *);
@ -2795,7 +2800,7 @@ struct menu *menu_create(const char *);
void menu_add_items(struct menu *, const struct menu_item *, void menu_add_items(struct menu *, const struct menu_item *,
struct cmdq_item *, struct client *, struct cmdq_item *, struct client *,
struct cmd_find_state *); 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 cmdq_item *, struct client *,
struct cmd_find_state *); struct cmd_find_state *);
void menu_free(struct menu *); void menu_free(struct menu *);
@ -2818,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 *, int style_parse(struct style *,const struct grid_cell *,
const char *); const char *);
const char *style_tostring(struct style *); 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 *, 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_set(struct style *, const struct grid_cell *);
void style_copy(struct style *, struct style *); 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); 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 static void
tty_default_colours(struct grid_cell *gc, struct window_pane *wp) 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) { if (wp->flags & PANE_STYLECHANGED) {
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) { if (gc->fg == 8) {

View File

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

View File

@ -865,6 +865,9 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->fd = -1; wp->fd = -1;
wp->event = NULL; wp->event = NULL;
wp->fg = 8;
wp->bg = 8;
TAILQ_INIT(&wp->modes); TAILQ_INIT(&wp->modes);
wp->layout_cell = NULL; wp->layout_cell = NULL;
@ -1096,6 +1099,7 @@ window_pane_set_mode(struct window_pane *wp, struct window_pane *swp,
wp->screen = wme->screen; wp->screen = wme->screen;
wp->flags |= (PANE_REDRAW|PANE_CHANGED); wp->flags |= (PANE_REDRAW|PANE_CHANGED);
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
notify_pane("pane-mode-changed", wp); notify_pane("pane-mode-changed", wp);
@ -1127,6 +1131,7 @@ window_pane_reset_mode(struct window_pane *wp)
} }
wp->flags |= (PANE_REDRAW|PANE_CHANGED); wp->flags |= (PANE_REDRAW|PANE_CHANGED);
server_redraw_window_borders(wp->window);
server_status_window(wp->window); server_status_window(wp->window);
notify_pane("pane-mode-changed", wp); notify_pane("pane-mode-changed", wp);
} }