Skip to content

Commit

Permalink
Add a per-pane option set. Pane options inherit from window options (so
Browse files Browse the repository at this point in the history
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.
  • Loading branch information
nicm committed Jun 20, 2019
1 parent c1ede50 commit 5f92f92
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 279 deletions.
2 changes: 2 additions & 0 deletions cmd-break-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
layout_close_pane(wp);

w = wp->window = window_create(w->sx, w->sy);
options_set_parent(wp->options, w->options);
wp->flags |= PANE_STYLECHANGED;
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
w->active = wp;

Expand Down
2 changes: 2 additions & 0 deletions cmd-join-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
TAILQ_REMOVE(&src_w->panes, src_wp, entry);

src_wp->window = dst_w;
options_set_parent(src_wp->options, dst_w->options);
src_wp->flags |= PANE_STYLECHANGED;
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
layout_assign_pane(lc, src_wp);

Expand Down
18 changes: 11 additions & 7 deletions cmd-select-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const struct cmd_entry cmd_select_pane_entry = {
.name = "select-pane",
.alias = "selectp",

.args = { "DdegLlMmP:RT:t:U", 0, 0 },
.usage = "[-DdegLlMmRU] [-P style] [-T title] " CMD_TARGET_PANE_USAGE,
.args = { "DdegLlMmP:RT:t:U", 0, 0 }, /* -P and -g deprecated */
.usage = "[-DdeLlMmRU] [-T title] " CMD_TARGET_PANE_USAGE,

.target = { 't', CMD_FIND_PANE, 0 },

Expand Down Expand Up @@ -90,9 +90,10 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window;
struct session *s = item->target.s;
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
struct style *sy = &wp->style;
char *pane_title;
const char *style;
struct style *sy;
struct options_entry *o;

if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
lastwp = w->last;
Expand Down Expand Up @@ -144,15 +145,18 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)

if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
if ((style = args_get(args, 'P')) != NULL) {
style_set(sy, &grid_default_cell);
if (style_parse(sy, &grid_default_cell, style) == -1) {
o = options_set_style(wp->options, "window-style", 0,
style);
if (o == NULL) {
cmdq_error(item, "bad style: %s", style);
return (CMD_RETURN_ERROR);
}
wp->flags |= PANE_REDRAW;
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
}
if (args_has(self->args, 'g'))
if (args_has(self->args, 'g')) {
sy = options_get_style(wp->options, "window-style");
cmdq_print(item, "%s", style_tostring(sy));
}
return (CMD_RETURN_NORMAL);
}

Expand Down
13 changes: 7 additions & 6 deletions cmd-set-option.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const struct cmd_entry cmd_set_option_entry = {
.name = "set-option",
.alias = "set",

.args = { "aFgoqst:uw", 1, 2 },
.usage = "[-aFgosquw] [-t target-window] option [value]",
.args = { "aFgopqst:uw", 1, 2 },
.usage = "[-aFgopqsuw] " CMD_TARGET_PANE_USAGE " option [value]",

.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },

.flags = CMD_AFTERHOOK,
.exec = cmd_set_option_exec
Expand Down Expand Up @@ -88,11 +88,12 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = fs->s;
struct winlink *wl = fs->wl;
struct window *w;
enum options_table_scope scope;
struct window_pane *wp;
struct options *oo;
struct options_entry *parent, *o;
char *name, *argument, *value = NULL, *cause;
int window, idx, already, error, ambiguous;
int scope;
struct style *sy;

window = (self->entry == &cmd_set_window_option_entry);
Expand Down Expand Up @@ -249,8 +250,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
alerts_reset_all();
if (strcmp(name, "window-style") == 0 ||
strcmp(name, "window-active-style") == 0) {
RB_FOREACH(w, windows, &windows)
w->flags |= WINDOW_STYLECHANGED;
RB_FOREACH(wp, window_pane_tree, &all_window_panes)
wp->flags |= PANE_STYLECHANGED;
}
if (strcmp(name, "pane-border-status") == 0) {
RB_FOREACH(w, windows, &windows)
Expand Down
26 changes: 14 additions & 12 deletions cmd-show-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *);
static void cmd_show_options_print(struct cmd *, struct cmdq_item *,
struct options_entry *, int, int);
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
enum options_table_scope, struct options *);
int, struct options *);

const struct cmd_entry cmd_show_options_entry = {
.name = "show-options",
.alias = "show",

.args = { "AgHqst:vw", 0, 1 },
.usage = "[-AgHqsvw] [-t target-session|target-window] [option]",
.args = { "AgHpqst:vw", 0, 1 },
.usage = "[-AgHpqsvw] " CMD_TARGET_PANE_USAGE " [option]",

.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },

.flags = CMD_AFTERHOOK,
.exec = cmd_show_options_exec
Expand Down Expand Up @@ -83,9 +83,8 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct options *oo;
enum options_table_scope scope;
char *argument, *name = NULL, *cause;
int window, idx, ambiguous, parent;
int window, idx, ambiguous, parent, scope;
struct options_entry *o;

window = (self->entry == &cmd_show_window_options_entry);
Expand Down Expand Up @@ -191,17 +190,18 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
}

static enum cmd_retval
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
enum options_table_scope scope, struct options *oo)
cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope,
struct options *oo)
{
const struct options_table_entry *oe;
struct options_entry *o;
struct options_array_item *a;
const char *name;
u_int idx;
int parent;

for (oe = options_table; oe->name != NULL; oe++) {
if (oe->scope != scope)
if (~oe->scope & scope)
continue;

if ((self->entry != &cmd_show_hooks_entry &&
Expand All @@ -228,15 +228,17 @@ cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
cmd_show_options_print(self, item, o, -1, parent);
else if ((a = options_array_first(o)) == NULL) {
if (!args_has(self->args, 'v')) {
name = options_name(o);
if (parent)
cmdq_print(item, "%s*", options_name(o));
cmdq_print(item, "%s*", name);
else
cmdq_print(item, "%s", options_name(o));
cmdq_print(item, "%s", name);
}
} else {
while (a != NULL) {
idx = options_array_item_index(a);
cmd_show_options_print(self, item, o, idx, parent);
cmd_show_options_print(self, item, o, idx,
parent);
a = options_array_next(a);
}
}
Expand Down
4 changes: 4 additions & 0 deletions cmd-swap-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
src_wp->layout_cell = dst_lc;

src_wp->window = dst_w;
options_set_parent(src_wp->options, dst_w->options);
src_wp->flags |= PANE_STYLECHANGED;
dst_wp->window = src_w;
options_set_parent(dst_wp->options, src_w->options);
dst_wp->flags |= PANE_STYLECHANGED;

sx = src_wp->sx; sy = src_wp->sy;
xoff = src_wp->xoff; yoff = src_wp->yoff;
Expand Down
2 changes: 2 additions & 0 deletions format.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ format_find(struct format_tree *ft, const char *key, int modifiers)

if (~modifiers & FORMAT_TIMESTRING) {
o = options_parse_get(global_options, key, &idx, 0);
if (o == NULL && ft->wp != NULL)
o = options_parse_get(ft->wp->options, key, &idx, 0);
if (o == NULL && ft->w != NULL)
o = options_parse_get(ft->w->options, key, &idx, 0);
if (o == NULL)
Expand Down
16 changes: 10 additions & 6 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -2347,12 +2347,14 @@ 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 (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3)
goto bad;

wp->style.gc.fg = colour_join_rgb(r, g, b);
wp->flags |= PANE_REDRAW;
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->flags |= (PANE_REDRAW|PANE_STYLECHANGED);

return;

Expand All @@ -2366,12 +2368,14 @@ 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 (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3)
goto bad;

wp->style.gc.bg = colour_join_rgb(r, g, b);
wp->flags |= PANE_REDRAW;
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->flags |= (PANE_REDRAW|PANE_STYLECHANGED);

return;

Expand Down
6 changes: 3 additions & 3 deletions options-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ const struct options_table_entry options_table[] = {

{ .name = "remain-on-exit",
.type = OPTIONS_TABLE_FLAG,
.scope = OPTIONS_TABLE_WINDOW,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_num = 0
},

Expand All @@ -712,7 +712,7 @@ const struct options_table_entry options_table[] = {

{ .name = "window-active-style",
.type = OPTIONS_TABLE_STYLE,
.scope = OPTIONS_TABLE_WINDOW,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "default"
},

Expand All @@ -725,7 +725,7 @@ const struct options_table_entry options_table[] = {

{ .name = "window-style",
.type = OPTIONS_TABLE_STYLE,
.scope = OPTIONS_TABLE_WINDOW,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "default"
},

Expand Down
Loading

0 comments on commit 5f92f92

Please sign in to comment.