diff --git a/colour.c b/colour.c index 5be60445..a0274dd3 100644 --- a/colour.c +++ b/colour.c @@ -141,6 +141,8 @@ colour_tostring(int c) return ("white"); case 8: return ("default"); + case 9: + return ("terminal"); case 90: return ("brightblack"); case 91: @@ -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) @@ -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) diff --git a/grid.c b/grid.c index a7c9a67e..7329f855 100644 --- a/grid.c +++ b/grid.c @@ -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); } @@ -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; @@ -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 */ diff --git a/options-table.c b/options-table.c index 4bc7982f..2f760b74 100644 --- a/options-table.c +++ b/options-table.c @@ -770,7 +770,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", diff --git a/screen-write.c b/screen-write.c index 4f5bee61..e583c72d 100644 --- a/screen-write.c +++ b/screen-write.c @@ -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); @@ -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); diff --git a/tmux.1 b/tmux.1 index 86f2ef21..9ecf25b9 100644 --- a/tmux.1 +++ b/tmux.1 @@ -2837,7 +2837,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 @@ -2860,8 +2860,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 diff --git a/tmux.h b/tmux.h index 2f8ed88d..cf8bf087 100644 --- a/tmux.h +++ b/tmux.h @@ -545,6 +545,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 diff --git a/tty.c b/tty.c index 7cc129e5..6b63aa3b 100644 --- a/tty.c +++ b/tty.c @@ -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); } @@ -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); @@ -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; } } @@ -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 @@ -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); } @@ -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) { @@ -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; + } } }