mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
Instead of representing colours in several different forms with various
cell flags, convert to use an int with flags marking 256 or RGB colours in the top byte (except in cells, which we don't want to make any bigger). From Brad Town.
This commit is contained in:
105
style.c
105
style.c
@ -33,7 +33,8 @@ style_parse(const struct grid_cell *defgc, struct grid_cell *gc,
|
||||
char tmp[32];
|
||||
int val;
|
||||
size_t end;
|
||||
u_char fg, bg, attr, flags;
|
||||
int fg, bg;
|
||||
u_char attr, flags;
|
||||
|
||||
if (*in == '\0')
|
||||
return (0);
|
||||
@ -56,38 +57,20 @@ style_parse(const struct grid_cell *defgc, struct grid_cell *gc,
|
||||
fg = defgc->fg;
|
||||
bg = defgc->bg;
|
||||
attr = defgc->attr;
|
||||
flags &= ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
|
||||
flags |=
|
||||
defgc->flags & (GRID_FLAG_FG256|GRID_FLAG_BG256);
|
||||
flags = defgc->flags;
|
||||
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
|
||||
if ((val = colour_fromstring(tmp + 3)) == -1)
|
||||
goto error;
|
||||
if (*in == 'f' || *in == 'F') {
|
||||
if (val != 8) {
|
||||
if (val & 0x100) {
|
||||
flags |= GRID_FLAG_FG256;
|
||||
val &= ~0x100;
|
||||
} else
|
||||
flags &= ~GRID_FLAG_FG256;
|
||||
if (val != 8)
|
||||
fg = val;
|
||||
} else {
|
||||
else
|
||||
fg = defgc->fg;
|
||||
flags &= ~GRID_FLAG_FG256;
|
||||
flags |= defgc->flags & GRID_FLAG_FG256;
|
||||
}
|
||||
} else if (*in == 'b' || *in == 'B') {
|
||||
if (val != 8) {
|
||||
if (val & 0x100) {
|
||||
flags |= GRID_FLAG_BG256;
|
||||
val &= ~0x100;
|
||||
} else
|
||||
flags &= ~GRID_FLAG_BG256;
|
||||
if (val != 8)
|
||||
bg = val;
|
||||
} else {
|
||||
else
|
||||
bg = defgc->bg;
|
||||
flags &= ~GRID_FLAG_BG256;
|
||||
flags |= defgc->flags & GRID_FLAG_BG256;
|
||||
}
|
||||
} else
|
||||
goto error;
|
||||
} else if (strcasecmp(tmp, "none") == 0)
|
||||
@ -120,27 +103,19 @@ error:
|
||||
const char *
|
||||
style_tostring(struct grid_cell *gc)
|
||||
{
|
||||
int c, off = 0, comma = 0;
|
||||
int off = 0, comma = 0;
|
||||
static char s[256];
|
||||
|
||||
*s = '\0';
|
||||
|
||||
if (gc->fg != 8 || gc->flags & GRID_FLAG_FG256) {
|
||||
if (gc->flags & GRID_FLAG_FG256)
|
||||
c = gc->fg | 0x100;
|
||||
else
|
||||
c = gc->fg;
|
||||
off += xsnprintf(s, sizeof s, "fg=%s", colour_tostring(c));
|
||||
if (gc->fg != 8) {
|
||||
off += xsnprintf(s, sizeof s, "fg=%s", colour_tostring(gc->fg));
|
||||
comma = 1;
|
||||
}
|
||||
|
||||
if (gc->bg != 8 || gc->flags & GRID_FLAG_BG256) {
|
||||
if (gc->flags & GRID_FLAG_BG256)
|
||||
c = gc->bg | 0x100;
|
||||
else
|
||||
c = gc->bg;
|
||||
if (gc->bg != 8) {
|
||||
off += xsnprintf(s + off, sizeof s - off, "%sbg=%s",
|
||||
comma ? "," : "", colour_tostring(c));
|
||||
comma ? "," : "", colour_tostring(gc->bg));
|
||||
comma = 1;
|
||||
}
|
||||
|
||||
@ -177,9 +152,9 @@ style_update_new(struct options *oo, const char *name, const char *newname)
|
||||
value = o->num;
|
||||
|
||||
if (strstr(name, "-bg") != NULL)
|
||||
colour_set_bg(gc, value);
|
||||
gc->bg = value;
|
||||
else if (strstr(name, "-fg") != NULL)
|
||||
colour_set_fg(gc, value);
|
||||
gc->fg = value;
|
||||
else if (strstr(name, "-attr") != NULL)
|
||||
gc->attr = value;
|
||||
}
|
||||
@ -189,23 +164,15 @@ void
|
||||
style_update_old(struct options *oo, const char *name, struct grid_cell *gc)
|
||||
{
|
||||
char newname[128];
|
||||
int c, size;
|
||||
int size;
|
||||
|
||||
size = strrchr(name, '-') - name;
|
||||
|
||||
if (gc->flags & GRID_FLAG_BG256)
|
||||
c = gc->bg | 0x100;
|
||||
else
|
||||
c = gc->bg;
|
||||
xsnprintf(newname, sizeof newname, "%.*s-bg", size, name);
|
||||
options_set_number(oo, newname, c);
|
||||
options_set_number(oo, newname, gc->bg);
|
||||
|
||||
if (gc->flags & GRID_FLAG_FG256)
|
||||
c = gc->fg | 0x100;
|
||||
else
|
||||
c = gc->fg;
|
||||
xsnprintf(newname, sizeof newname, "%.*s-fg", size, name);
|
||||
options_set_number(oo, newname, c);
|
||||
options_set_number(oo, newname, gc->fg);
|
||||
|
||||
xsnprintf(newname, sizeof newname, "%.*s-attr", size, name);
|
||||
options_set_number(oo, newname, gc->attr);
|
||||
@ -219,14 +186,8 @@ style_apply(struct grid_cell *gc, struct options *oo, const char *name)
|
||||
|
||||
memcpy(gc, &grid_default_cell, sizeof *gc);
|
||||
gcp = options_get_style(oo, name);
|
||||
if (gcp->flags & GRID_FLAG_FG256)
|
||||
colour_set_fg(gc, gcp->fg | 0x100);
|
||||
else
|
||||
colour_set_fg(gc, gcp->fg);
|
||||
if (gcp->flags & GRID_FLAG_BG256)
|
||||
colour_set_bg(gc, gcp->bg | 0x100);
|
||||
else
|
||||
colour_set_bg(gc, gcp->bg);
|
||||
gc->fg = gcp->fg;
|
||||
gc->bg = gcp->bg;
|
||||
gc->attr |= gcp->attr;
|
||||
}
|
||||
|
||||
@ -237,18 +198,10 @@ style_apply_update(struct grid_cell *gc, struct options *oo, const char *name)
|
||||
struct grid_cell *gcp;
|
||||
|
||||
gcp = options_get_style(oo, name);
|
||||
if (gcp->fg != 8 || gcp->flags & GRID_FLAG_FG256) {
|
||||
if (gcp->flags & GRID_FLAG_FG256)
|
||||
colour_set_fg(gc, gcp->fg | 0x100);
|
||||
else
|
||||
colour_set_fg(gc, gcp->fg);
|
||||
}
|
||||
if (gcp->bg != 8 || gcp->flags & GRID_FLAG_BG256) {
|
||||
if (gcp->flags & GRID_FLAG_BG256)
|
||||
colour_set_bg(gc, gcp->bg | 0x100);
|
||||
else
|
||||
colour_set_bg(gc, gcp->bg);
|
||||
}
|
||||
if (gcp->fg != 8)
|
||||
gc->fg = gcp->fg;
|
||||
if (gcp->bg != 8)
|
||||
gc->bg = gcp->bg;
|
||||
if (gcp->attr != 0)
|
||||
gc->attr |= gcp->attr;
|
||||
}
|
||||
@ -257,10 +210,10 @@ style_apply_update(struct grid_cell *gc, struct options *oo, const char *name)
|
||||
int
|
||||
style_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
|
||||
{
|
||||
return gc1->fg == gc2->fg &&
|
||||
gc1->bg == gc2->bg &&
|
||||
(gc1->flags & ~GRID_FLAG_PADDING) ==
|
||||
(gc2->flags & ~GRID_FLAG_PADDING) &&
|
||||
(gc1->attr & ~GRID_ATTR_CHARSET) ==
|
||||
(gc2->attr & ~GRID_ATTR_CHARSET);
|
||||
return (gc1->fg == gc2->fg &&
|
||||
gc1->bg == gc2->bg &&
|
||||
(gc1->flags & ~GRID_FLAG_PADDING) ==
|
||||
(gc2->flags & ~GRID_FLAG_PADDING) &&
|
||||
(gc1->attr & ~GRID_ATTR_CHARSET) ==
|
||||
(gc2->attr & ~GRID_ATTR_CHARSET));
|
||||
}
|
||||
|
Reference in New Issue
Block a user