From: nicm Date: Tue, 25 Apr 2017 18:20:51 +0000 (+0000) Subject: When we write out the grid including escape sequences, an SGR 0 needs to X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0a64112d3d4e661977ecce0d7aa78ca5d207e372;p=openbsd When we write out the grid including escape sequences, an SGR 0 needs to cause the colours to be written again. Also treat colours separately from attributes so that RGB colours will work. --- diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c index 1a926acba42..7e9c3b6ed33 100644 --- a/usr.bin/tmux/grid.c +++ b/usr.bin/tmux/grid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grid.c,v 1.69 2017/04/19 12:44:29 nicm Exp $ */ +/* $OpenBSD: grid.c,v 1.70 2017/04/25 18:20:51 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -675,8 +675,7 @@ grid_string_cells_code(const struct grid_cell *lastgc, { int oldc[64], newc[64], s[128]; size_t noldc, nnewc, n, i; - u_int attr = gc->attr; - u_int lastattr = lastgc->attr; + u_int attr = gc->attr, lastattr = lastgc->attr; char tmp[64]; struct { @@ -708,34 +707,58 @@ grid_string_cells_code(const struct grid_cell *lastgc, s[n++] = attrs[i].code; } - /* If the foreground colour changed, append its parameters. */ + /* Write the attributes. */ + *buf = '\0'; + if (n > 0) { + if (escape_c0) + strlcat(buf, "\\033[", len); + else + strlcat(buf, "\033[", len); + for (i = 0; i < n; i++) { + if (i + 1 < n) + xsnprintf(tmp, sizeof tmp, "%d;", s[i]); + else + xsnprintf(tmp, sizeof tmp, "%d", s[i]); + strlcat(buf, tmp, len); + } + strlcat(buf, "m", len); + } + + /* If the foreground colour changed, write its parameters. */ nnewc = grid_string_cells_fg(gc, newc); noldc = grid_string_cells_fg(lastgc, oldc); - if (nnewc != noldc || memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) { - for (i = 0; i < nnewc; i++) - s[n++] = newc[i]; + if (nnewc != noldc || + memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 || + (n != 0 && s[0] == 0)) { + if (escape_c0) + strlcat(buf, "\\033[", len); + else + strlcat(buf, "\033[", len); + for (i = 0; i < nnewc; i++) { + if (i + 1 < nnewc) + xsnprintf(tmp, sizeof tmp, "%d;", newc[i]); + else + xsnprintf(tmp, sizeof tmp, "%d", newc[i]); + strlcat(buf, tmp, len); + } + strlcat(buf, "m", len); } /* If the background colour changed, append its parameters. */ nnewc = grid_string_cells_bg(gc, newc); noldc = grid_string_cells_bg(lastgc, oldc); - if (nnewc != noldc || memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) { - for (i = 0; i < nnewc; i++) - s[n++] = newc[i]; - } - - /* If there are any parameters, append an SGR code. */ - *buf = '\0'; - if (n > 0) { + if (nnewc != noldc || + memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 || + (n != 0 && s[0] == 0)) { if (escape_c0) strlcat(buf, "\\033[", len); else strlcat(buf, "\033[", len); - for (i = 0; i < n; i++) { - if (i + 1 < n) - xsnprintf(tmp, sizeof tmp, "%d;", s[i]); + for (i = 0; i < nnewc; i++) { + if (i + 1 < nnewc) + xsnprintf(tmp, sizeof tmp, "%d;", newc[i]); else - xsnprintf(tmp, sizeof tmp, "%d", s[i]); + xsnprintf(tmp, sizeof tmp, "%d", newc[i]); strlcat(buf, tmp, len); } strlcat(buf, "m", len); @@ -744,13 +767,13 @@ grid_string_cells_code(const struct grid_cell *lastgc, /* Append shift in/shift out if needed. */ if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) { if (escape_c0) - strlcat(buf, "\\016", len); /* SO */ + strlcat(buf, "\\016", len); /* SO */ else strlcat(buf, "\016", len); /* SO */ } if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) { if (escape_c0) - strlcat(buf, "\\017", len); /* SI */ + strlcat(buf, "\\017", len); /* SI */ else strlcat(buf, "\017", len); /* SI */ } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ffca8523358..f2c062586d2 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.752 2017/04/25 15:35:10 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.753 2017/04/25 18:20:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1470,7 +1470,6 @@ void proc_kill_peer(struct tmuxpeer *); /* cfg.c */ extern int cfg_finished; -extern struct client *cfg_client; void start_cfg(void); int load_cfg(const char *, struct client *, struct cmdq_item *, int); void set_cfg_file(const char *);