Skip to content

Commit

Permalink
Add a "terminal" colour which can be used instead of "default" in style
Browse files Browse the repository at this point in the history
options for the terminal default colour, bypassing any inheritance from
other options. Prompted by a discussion with abieber@.
  • Loading branch information
nicm committed Oct 25, 2018
1 parent 9feb35b commit fc41bf4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 32 deletions.
9 changes: 7 additions & 2 deletions colour.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ colour_tostring(int c)
return ("white");
case 8:
return ("default");
case 9:
return ("terminal");
case 90:
return ("brightblack");
case 91:
Expand Down Expand Up @@ -188,6 +190,11 @@ colour_fromstring(const char *s)
return (n | COLOUR_FLAG_256);
}

if (strcasecmp(s, "default") == 0)
return (8);
if (strcasecmp(s, "terminal") == 0)
return (9);

if (strcasecmp(s, "black") == 0 || strcmp(s, "0") == 0)
return (0);
if (strcasecmp(s, "red") == 0 || strcmp(s, "1") == 0)
Expand All @@ -204,8 +211,6 @@ colour_fromstring(const char *s)
return (6);
if (strcasecmp(s, "white") == 0 || strcmp(s, "7") == 0)
return (7);
if (strcasecmp(s, "default") == 0 || strcmp(s, "8") == 0)
return (8);
if (strcasecmp(s, "brightblack") == 0 || strcmp(s, "90") == 0)
return (90);
if (strcasecmp(s, "brightred") == 0 || strcmp(s, "91") == 0)
Expand Down
16 changes: 9 additions & 7 deletions grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ static void
grid_empty_line(struct grid *gd, u_int py, u_int bg)
{
memset(&gd->linedata[py], 0, sizeof gd->linedata[py]);
if (bg != 8)
if (!COLOUR_DEFAULT(bg))
grid_expand_line(gd, py, gd->sx, bg);
}

Expand Down Expand Up @@ -524,7 +524,8 @@ grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc,
void
grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
{
u_int xx, yy;
struct grid_line *gl;
u_int xx, yy;

if (nx == 0 || ny == 0)
return;
Expand All @@ -540,12 +541,13 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
return;

for (yy = py; yy < py + ny; yy++) {
if (px + nx >= gd->sx && px < gd->linedata[yy].cellused)
gd->linedata[yy].cellused = px;
if (px > gd->linedata[yy].cellsize && bg == 8)
gl = &gd->linedata[yy];
if (px + nx >= gd->sx && px < gl->cellused)
gl->cellused = px;
if (px > gl->cellsize && COLOUR_DEFAULT(bg))
continue;
if (px + nx >= gd->linedata[yy].cellsize && bg == 8) {
gd->linedata[yy].cellsize = px;
if (px + nx >= gl->cellsize && COLOUR_DEFAULT(bg)) {
gl->cellsize = px;
continue;
}
grid_expand_line(gd, yy, px + nx, 8); /* default bg first */
Expand Down
2 changes: 1 addition & 1 deletion options-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ const struct options_table_entry options_table[] = {
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_WINDOW,
.choices = options_table_window_size_list,
.default_num = WINDOW_SIZE_LARGEST
.default_num = WINDOW_SIZE_SMALLEST
},

{ .name = "window-style",
Expand Down
4 changes: 2 additions & 2 deletions screen-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ screen_write_clearline(struct screen_write_ctx *ctx, u_int bg)
u_int sx = screen_size_x(s);

gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
if (gl->cellsize == 0 && bg == 8)
if (gl->cellsize == 0 && COLOUR_DEFAULT(bg))
return;

screen_write_initctx(ctx, &ttyctx);
Expand All @@ -988,7 +988,7 @@ screen_write_clearendofline(struct screen_write_ctx *ctx, u_int bg)
u_int sx = screen_size_x(s);

gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
if (s->cx > sx - 1 || (s->cx >= gl->cellsize && bg == 8))
if (s->cx > sx - 1 || (s->cx >= gl->cellsize && COLOUR_DEFAULT(bg)))
return;

screen_write_initctx(ctx, &ttyctx);
Expand Down
11 changes: 8 additions & 3 deletions tmux.1
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,7 @@ Set status line message command style, where
.Ar style
is a comma-separated list of characteristics to be specified.
.Pp
These may be
The style format is shared by many options and may be:
.Ql bg=colour
to set the background colour,
.Ql fg=colour
Expand All @@ -2773,8 +2773,13 @@ and so on),
to
.Ic colour255
from the 256-colour set,
.Ic default ,
or a hexadecimal RGB string such as
.Ic default
for the default colour (inherited from another option in the case of some options, for example
.Ic window-status-style
inherits from
.Ic status-style ) ,
.Ic terminal
for the terminal default colour, or a hexadecimal RGB string such as
.Ql #ffffff .
.Pp
The attributes is either
Expand Down
3 changes: 3 additions & 0 deletions tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ enum utf8_state {
#define COLOUR_FLAG_256 0x01000000
#define COLOUR_FLAG_RGB 0x02000000

/* Special colours. */
#define COLOUR_DEFAULT(c) ((c) == 8 || (c) == 9)

/* Grid attributes. Anything above 0xff is stored in an extended cell. */
#define GRID_ATTR_BRIGHT 0x1
#define GRID_ATTR_DIM 0x2
Expand Down
38 changes: 21 additions & 17 deletions tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ tty_fake_bce(const struct tty *tty, const struct window_pane *wp, u_int bg)
if (wp != NULL)
tty_default_colours(&gc, wp);

if (bg != 8 || gc.bg != 8)
if (!COLOUR_DEFAULT(bg) || !COLOUR_DEFAULT(gc.bg))
return (1);
return (0);
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py,
* background colour isn't default (because it doesn't work
* after SGR 0).
*/
if (tty->term_type == TTY_VT420 && bg != 8) {
if (tty->term_type == TTY_VT420 && COLOUR_DEFAULT(bg)) {
xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x",
py + 1, px + 1, py + ny, px + nx);
tty_puts(tty, tmp);
Expand Down Expand Up @@ -2134,10 +2134,10 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc,
*/
if (!tty_term_has(tty->term, TTYC_SETAB)) {
if (gc2.attr & GRID_ATTR_REVERSE) {
if (gc2.fg != 7 && gc2.fg != 8)
if (gc2.fg != 7 && !COLOUR_DEFAULT(gc2.fg))
gc2.attr &= ~GRID_ATTR_REVERSE;
} else {
if (gc2.bg != 0 && gc2.bg != 8)
if (gc2.bg != 0 && !COLOUR_DEFAULT(gc2.bg))
gc2.attr |= GRID_ATTR_REVERSE;
}
}
Expand Down Expand Up @@ -2212,7 +2212,7 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
* case if only one is default need to fall onward to set the other
* colour.
*/
if (gc->fg == 8 || gc->bg == 8) {
if (COLOUR_DEFAULT(gc->fg) || COLOUR_DEFAULT(gc->bg)) {
/*
* If don't have AX but do have op, send sgr0 (op can't
* actually be used because it is sometimes the same as sgr0
Expand All @@ -2224,32 +2224,32 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
if (!have_ax && tty_term_has(tty->term, TTYC_OP))
tty_reset(tty);
else {
if (gc->fg == 8 && tc->fg != 8) {
if (COLOUR_DEFAULT(gc->fg) && !COLOUR_DEFAULT(tc->fg)) {
if (have_ax)
tty_puts(tty, "\033[39m");
else if (tc->fg != 7)
tty_putcode1(tty, TTYC_SETAF, 7);
tc->fg = 8;
tc->fg = gc->fg;
}
if (gc->bg == 8 && tc->bg != 8) {
if (COLOUR_DEFAULT(gc->bg) && !COLOUR_DEFAULT(tc->bg)) {
if (have_ax)
tty_puts(tty, "\033[49m");
else if (tc->bg != 0)
tty_putcode1(tty, TTYC_SETAB, 0);
tc->bg = 8;
tc->bg = gc->fg;
}
}
}

/* Set the foreground colour. */
if (gc->fg != 8 && gc->fg != tc->fg)
if (!COLOUR_DEFAULT(gc->fg) && gc->fg != tc->fg)
tty_colours_fg(tty, gc);

/*
* Set the background colour. This must come after the foreground as
* tty_colour_fg() can call tty_reset().
*/
if (gc->bg != 8 && gc->bg != tc->bg)
if (!COLOUR_DEFAULT(gc->bg) && gc->bg != tc->bg)
tty_colours_bg(tty, gc);
}

Expand Down Expand Up @@ -2515,9 +2515,11 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp)
else
gc->fg = wgc->fg;

if (gc->fg != 8 &&
(c = window_pane_get_palette(wp, gc->fg)) != -1)
gc->fg = c;
if (gc->fg != 8) {
c = window_pane_get_palette(wp, gc->fg);
if (c != -1)
gc->fg = c;
}
}

if (gc->bg == 8) {
Expand All @@ -2528,9 +2530,11 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp)
else
gc->bg = wgc->bg;

if (gc->bg != 8 &&
(c = window_pane_get_palette(wp, gc->bg)) != -1)
gc->bg = c;
if (gc->bg != 8) {
c = window_pane_get_palette(wp, gc->bg);
if (c != -1)
gc->bg = c;
}
}
}

Expand Down

0 comments on commit fc41bf4

Please sign in to comment.