From 0ec1ce005c98f4fa1813cf47e4bcc11d8cd4b523 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Fri, 11 Sep 2009 14:13:52 +0000 Subject: [PATCH] Sync OpenBSD patchset 322: Permit options such as status-bg to be configured using the entire 256 colour palette by setting "colour0" to "colour255". --- clock.c | 6 +++--- colour.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- screen-redraw.c | 13 ++++++------- screen-write.c | 29 +++++++++++++++++++++-------- server.c | 4 ++-- status.c | 47 ++++++++++++++++++++++++----------------------- tmux.1 | 11 +++++++---- tmux.h | 6 ++++-- tty.c | 5 +++-- window-choose.c | 9 +++++---- window-copy.c | 16 +++++++++------- window-more.c | 9 +++++---- window-scroll.c | 9 +++++---- 13 files changed, 136 insertions(+), 73 deletions(-) diff --git a/clock.c b/clock.c index 50d48bed..45426828 100644 --- a/clock.c +++ b/clock.c @@ -1,4 +1,4 @@ -/* $Id: clock.c,v 1.6 2009-08-26 22:12:21 tcunha Exp $ */ +/* $Id: clock.c,v 1.7 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -120,7 +120,7 @@ clock_draw(struct screen_write_ctx *ctx, u_int colour, int style) screen_write_cursormove(ctx, x, y); memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = colour; + colour_set_fg(&gc, colour); screen_write_puts(ctx, &gc, "%s", tim); } return; @@ -130,7 +130,7 @@ clock_draw(struct screen_write_ctx *ctx, u_int colour, int style) y = (screen_size_y(s) / 2) - 3; memcpy(&gc, &grid_default_cell, sizeof gc); - gc.bg = colour; + colour_set_bg(&gc, colour); for (ptr = tim; *ptr != '\0'; ptr++) { if (*ptr >= '0' && *ptr <= '9') idx = *ptr - '0'; diff --git a/colour.c b/colour.c index 2509a769..d4894c50 100644 --- a/colour.c +++ b/colour.c @@ -1,4 +1,4 @@ -/* $Id: colour.c,v 1.6 2009-05-18 15:42:30 nicm Exp $ */ +/* $Id: colour.c,v 1.7 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -18,13 +18,42 @@ #include +#include #include #include "tmux.h" -const char * -colour_tostring(u_char c) +/* + * Colour to string conversion functions. Bit 8 of the colour means it is one + * of the 256 colour palette. + */ + +void +colour_set_fg(struct grid_cell *gc, int c) { + if (c & 0x100) + gc->flags |= GRID_FLAG_FG256; + gc->fg = c; +} + +void +colour_set_bg(struct grid_cell *gc, int c) +{ + if (c & 0x100) + gc->flags |= GRID_FLAG_BG256; + gc->bg = c; +} + +const char * +colour_tostring(int c) +{ + static char s[32]; + + if (c & 0x100) { + xsnprintf(s, sizeof s, "colour%u", c & ~0x100); + return (s); + } + switch (c) { case 0: return ("black"); @@ -51,6 +80,16 @@ colour_tostring(u_char c) int colour_fromstring(const char *s) { + const char *errstr; + int n; + + if (strncasecmp(s, "colour", (sizeof "colour") - 1) == 0) { + n = strtonum(s + (sizeof "colour") - 1, 0, 255, &errstr); + if (errstr != NULL) + return (-1); + return (n | 0x100); + } + if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0')) return (0); if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0')) diff --git a/screen-redraw.c b/screen-redraw.c index 649b8f5f..466c3569 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -1,4 +1,4 @@ -/* $Id: screen-redraw.c,v 1.46 2009-08-31 22:30:15 tcunha Exp $ */ +/* $Id: screen-redraw.c,v 1.47 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -240,7 +240,7 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) struct session *s = c->session; struct grid_cell gc; u_int idx, px, py, i, j; - u_char colour; + int colour; char buf[16], *ptr; size_t len; @@ -256,7 +256,7 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) if (wp->sx < len * 6 || wp->sy < 5) { tty_cursor(tty, px - len / 2, py, wp->xoff, wp->yoff); memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = colour; + colour_set_fg(&gc, colour); tty_attributes(tty, &gc); tty_puts(tty, buf); return; @@ -266,7 +266,7 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) py -= 2; memcpy(&gc, &grid_default_cell, sizeof gc); - gc.bg = colour; + colour_set_bg(&gc, colour); tty_attributes(tty, &gc); for (ptr = buf; *ptr != '\0'; ptr++) { if (*ptr < '0' || *ptr > '9') @@ -276,9 +276,8 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) for (j = 0; j < 5; j++) { for (i = px; i < px + 5; i++) { tty_cursor(tty, i, py + j, wp->xoff, wp->yoff); - if (!clock_table[idx][j][i - px]) - continue; - tty_putc(tty, ' '); + if (clock_table[idx][j][i - px]) + tty_putc(tty, ' '); } } px += 6; diff --git a/screen-write.c b/screen-write.c index fbab37c9..2bfdef76 100644 --- a/screen-write.c +++ b/screen-write.c @@ -1,4 +1,4 @@ -/* $Id: screen-write.c,v 1.71 2009-09-07 23:37:48 tcunha Exp $ */ +/* $Id: screen-write.c,v 1.72 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -300,7 +300,7 @@ screen_write_parsestyle( char tmp[32]; int val; size_t end; - u_char fg, bg, attr; + u_char fg, bg, attr, flags; if (*in == '\0') return; @@ -309,7 +309,8 @@ screen_write_parsestyle( fg = gc->fg; bg = gc->bg; - attr = 0; + attr = gc->attr; + flags = gc->flags; do { end = strcspn(in, delimiters); if (end > (sizeof tmp) - 1) @@ -325,14 +326,24 @@ screen_write_parsestyle( if ((val = colour_fromstring(tmp + 3)) == -1) return; if (*in == 'f' || *in == 'F') { - if (val != 8) + if (val != 8) { + if (val & 0x100) { + flags |= GRID_FLAG_FG256; + val &= ~0x100; + } else + flags &= ~GRID_FLAG_FG256; fg = val; - else + } else fg = defgc->fg; } else if (*in == 'b' || *in == 'B') { - if (val != 8) + if (val != 8) { + if (val & 0x100) { + flags |= GRID_FLAG_BG256; + val &= ~0x100; + } else + flags &= ~GRID_FLAG_BG256; bg = val; - else + } else bg = defgc->bg; } else return; @@ -347,6 +358,7 @@ screen_write_parsestyle( gc->fg = fg; gc->bg = bg; gc->attr = attr; + gc->flags = flags; } /* Copy from another screen. */ @@ -1002,7 +1014,8 @@ screen_write_cell( if (screen_check_selection(s, s->cx - width, s->cy)) { memcpy(&tmp_gc2, &s->sel.cell, sizeof tmp_gc2); tmp_gc2.data = gc->data; - tmp_gc2.flags = gc->flags; + tmp_gc2.flags = gc->flags & ~(GRID_FLAG_FG256|GRID_FLAG_BG256); + tmp_gc2.flags |= s->sel.cell.flags & (GRID_FLAG_FG256|GRID_FLAG_BG256); ttyctx.cell = &tmp_gc2; tty_write(tty_cmd_cell, &ttyctx); } else { diff --git a/server.c b/server.c index d9a97d85..4d8fccaa 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.183 2009-09-08 00:01:11 tcunha Exp $ */ +/* $Id: server.c,v 1.184 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -604,7 +604,7 @@ server_redraw_locked(struct client *c) style = options_get_number(&global_w_options, "clock-mode-style"); memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = colour; + colour_set_fg(&gc, colour); gc.attr |= GRID_ATTR_BRIGHT; screen_init(&screen, xx, yy, 0); diff --git a/status.c b/status.c index 22617f16..9cf5dbc8 100644 --- a/status.c +++ b/status.c @@ -1,4 +1,4 @@ -/* $Id: status.c,v 1.117 2009-09-07 23:48:54 tcunha Exp $ */ +/* $Id: status.c,v 1.118 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -66,8 +66,8 @@ status_redraw(struct client *c) if (gettimeofday(&c->status_timer, NULL) != 0) fatal("gettimeofday"); memcpy(&stdgc, &grid_default_cell, sizeof gc); - stdgc.fg = options_get_number(&s->options, "status-fg"); - stdgc.bg = options_get_number(&s->options, "status-bg"); + colour_set_fg(&stdgc, options_get_number(&s->options, "status-fg")); + colour_set_bg(&stdgc, options_get_number(&s->options, "status-bg")); stdgc.attr |= options_get_number(&s->options, "status-attr"); /* @@ -79,19 +79,19 @@ status_redraw(struct client *c) memcpy(&sr_stdgc, &stdgc, sizeof sr_stdgc); sl_fg = options_get_number(&s->options, "status-left-fg"); if (sl_fg != 8) - sl_stdgc.fg = sl_fg; + colour_set_fg(&sl_stdgc, sl_fg); sl_bg = options_get_number(&s->options, "status-left-bg"); if (sl_bg != 8) - sl_stdgc.bg = sl_bg; + colour_set_bg(&sl_stdgc, sl_bg); sl_attr = options_get_number(&s->options, "status-left-attr"); if (sl_attr != 0) sl_stdgc.attr = sl_attr; sr_fg = options_get_number(&s->options, "status-right-fg"); if (sr_fg != 8) - sr_stdgc.fg = sr_fg; + colour_set_fg(&sr_stdgc, sr_fg); sr_bg = options_get_number(&s->options, "status-right-bg"); if (sr_bg != 8) - sr_stdgc.bg = sr_bg; + colour_set_bg(&sr_stdgc, sr_bg); sr_attr = options_get_number(&s->options, "status-right-attr"); if (sr_attr != 0) sr_stdgc.attr = sr_attr; @@ -501,16 +501,17 @@ status_width(struct winlink *wl) char * status_print(struct session *s, struct winlink *wl, struct grid_cell *gc) { - char *text, flag; - u_char fg, bg, attr; + struct options *oo = &wl->window->options; + char *text, flag; + u_char fg, bg, attr; - fg = options_get_number(&wl->window->options, "window-status-fg"); + fg = options_get_number(oo, "window-status-fg"); if (fg != 8) - gc->fg = fg; - bg = options_get_number(&wl->window->options, "window-status-bg"); + colour_set_fg(gc, fg); + bg = options_get_number(oo, "window-status-bg"); if (bg != 8) - gc->bg = bg; - attr = options_get_number(&wl->window->options, "window-status-attr"); + colour_set_bg(gc, bg); + attr = options_get_number(oo, "window-status-attr"); if (attr != 0) gc->attr = attr; @@ -518,13 +519,13 @@ status_print(struct session *s, struct winlink *wl, struct grid_cell *gc) if (wl == SLIST_FIRST(&s->lastw)) flag = '-'; if (wl == s->curw) { - fg = options_get_number(&wl->window->options, "window-status-current-fg"); + fg = options_get_number(oo, "window-status-current-fg"); if (fg != 8) - gc->fg = fg; - bg = options_get_number(&wl->window->options, "window-status-current-bg"); + colour_set_fg(gc, fg); + bg = options_get_number(oo, "window-status-current-bg"); if (bg != 8) - gc->bg = bg; - attr = options_get_number(&wl->window->options, "window-status-current-attr"); + colour_set_bg(gc, bg); + attr = options_get_number(oo, "window-status-current-attr"); if (attr != 0) gc->attr = attr; flag = '*'; @@ -606,8 +607,8 @@ status_message_redraw(struct client *c) len = c->tty.sx; memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = options_get_number(&s->options, "message-fg"); - gc.bg = options_get_number(&s->options, "message-bg"); + colour_set_fg(&gc, options_get_number(&s->options, "message-fg")); + colour_set_bg(&gc, options_get_number(&s->options, "message-bg")); gc.attr |= options_get_number(&s->options, "message-attr"); screen_write_start(&ctx, NULL, &c->status); @@ -719,8 +720,8 @@ status_prompt_redraw(struct client *c) len = c->tty.sx; memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = options_get_number(&s->options, "message-fg"); - gc.bg = options_get_number(&s->options, "message-bg"); + colour_set_fg(&gc, options_get_number(&s->options, "message-fg")); + colour_set_bg(&gc, options_get_number(&s->options, "message-bg")); gc.attr |= options_get_number(&s->options, "message-attr"); screen_write_start(&ctx, NULL, &c->status); diff --git a/tmux.1 b/tmux.1 index 78d43c9f..64918e13 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.166 2009-09-08 00:01:11 tcunha Exp $ +.\" $Id: tmux.1,v 1.167 2009-09-11 14:13:52 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 7 2009 $ +.Dd $Mdocdate: September 10 2009 $ .Dt TMUX 1 .Os .Sh NAME @@ -1250,8 +1250,11 @@ is one of: .Ic blue , .Ic magenta , .Ic cyan , -.Ic white -or +.Ic white , +.Ic colour0 +to +.Ic colour255 +from the 256-colour palette, or .Ic default . .It Ic message-fg Ar colour Set status line message foreground colour. diff --git a/tmux.h b/tmux.h index 2995fb0c..94e0c533 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.439 2009-09-07 23:59:19 tcunha Exp $ */ +/* $Id: tmux.h,v 1.440 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1484,7 +1484,9 @@ void input_key(struct window_pane *, int); void input_mouse(struct window_pane *, u_char, u_char, u_char); /* colour.c */ -const char *colour_tostring(u_char); +void colour_set_fg(struct grid_cell *, int); +void colour_set_bg(struct grid_cell *, int); +const char *colour_tostring(int); int colour_fromstring(const char *); u_char colour_256to16(u_char); u_char colour_256to88(u_char); diff --git a/tty.c b/tty.c index d7bf11a6..339826e8 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.131 2009-08-31 22:30:15 tcunha Exp $ */ +/* $Id: tty.c,v 1.132 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -520,7 +520,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) if (screen_check_selection(s, i, py)) { memcpy(&tmpgc, &s->sel.cell, sizeof tmpgc); tmpgc.data = gc->data; - tmpgc.flags = gc->flags; + tmpgc.flags = gc->flags & ~(GRID_FLAG_FG256|GRID_FLAG_BG256); + tmpgc.flags |= s->sel.cell.flags & (GRID_FLAG_FG256|GRID_FLAG_BG256); tty_cell(tty, &tmpgc, gu); } else tty_cell(tty, gc, gu); diff --git a/window-choose.c b/window-choose.c index 6bea76ea..aa6bc5ea 100644 --- a/window-choose.c +++ b/window-choose.c @@ -1,4 +1,4 @@ -/* $Id: window-choose.c,v 1.22 2009-08-09 16:50:57 tcunha Exp $ */ +/* $Id: window-choose.c,v 1.23 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -295,6 +295,7 @@ window_choose_write_line( { struct window_choose_mode_data *data = wp->modedata; struct window_choose_mode_item *item; + struct options *oo = &wp->window->options; struct screen *s = &data->screen; struct grid_cell gc; int utf8flag; @@ -305,9 +306,9 @@ window_choose_write_line( utf8flag = options_get_number(&wp->window->options, "utf8"); memcpy(&gc, &grid_default_cell, sizeof gc); if (data->selected == data->top + py) { - gc.fg = options_get_number(&wp->window->options, "mode-fg"); - gc.bg = options_get_number(&wp->window->options, "mode-bg"); - gc.attr |= options_get_number(&wp->window->options, "mode-attr"); + colour_set_fg(&gc, options_get_number(oo, "mode-fg")); + colour_set_bg(&gc, options_get_number(oo, "mode-bg")); + gc.attr |= options_get_number(oo, "mode-attr"); } screen_write_cursormove(ctx, 0, py); diff --git a/window-copy.c b/window-copy.c index bafdaf75..e5d4bc86 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1,4 +1,4 @@ -/* $Id: window-copy.c,v 1.85 2009-09-07 23:48:54 tcunha Exp $ */ +/* $Id: window-copy.c,v 1.86 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -660,14 +660,15 @@ window_copy_write_line( { struct window_copy_mode_data *data = wp->modedata; struct screen *s = &data->screen; + struct options *oo = &wp->window->options; struct grid_cell gc; char hdr[32]; size_t last, xoff = 0, size = 0; memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = options_get_number(&wp->window->options, "mode-fg"); - gc.bg = options_get_number(&wp->window->options, "mode-bg"); - gc.attr |= options_get_number(&wp->window->options, "mode-attr"); + colour_set_fg(&gc, options_get_number(oo, "mode-fg")); + colour_set_bg(&gc, options_get_number(oo, "mode-bg")); + gc.attr |= options_get_number(oo, "mode-attr"); last = screen_size_y(s) - 1; if (py == 0) { @@ -765,6 +766,7 @@ window_copy_update_selection(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; struct screen *s = &data->screen; + struct options *oo = &wp->window->options; struct grid_cell gc; u_int sx, sy, ty; @@ -773,9 +775,9 @@ window_copy_update_selection(struct window_pane *wp) /* Set colours. */ memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = options_get_number(&wp->window->options, "mode-fg"); - gc.bg = options_get_number(&wp->window->options, "mode-bg"); - gc.attr |= options_get_number(&wp->window->options, "mode-attr"); + colour_set_fg(&gc, options_get_number(oo, "mode-fg")); + colour_set_bg(&gc, options_get_number(oo, "mode-bg")); + gc.attr |= options_get_number(oo, "mode-attr"); /* Find top of screen. */ ty = screen_hsize(&wp->base) - data->oy; diff --git a/window-more.c b/window-more.c index c4acfbfd..d9b3a728 100644 --- a/window-more.c +++ b/window-more.c @@ -1,4 +1,4 @@ -/* $Id: window-more.c,v 1.37 2009-08-20 11:24:33 tcunha Exp $ */ +/* $Id: window-more.c,v 1.38 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -164,6 +164,7 @@ window_more_write_line( { struct window_more_mode_data *data = wp->modedata; struct screen *s = &data->screen; + struct options *oo = &wp->window->options; struct grid_cell gc; char *msg, hdr[32]; size_t size; @@ -176,9 +177,9 @@ window_more_write_line( size = xsnprintf(hdr, sizeof hdr, "[%u/%u]", data->top, ARRAY_LENGTH(&data->list)); screen_write_cursormove(ctx, screen_size_x(s) - size, 0); - gc.fg = options_get_number(&wp->window->options, "mode-fg"); - gc.bg = options_get_number(&wp->window->options, "mode-bg"); - gc.attr |= options_get_number(&wp->window->options, "mode-attr"); + colour_set_fg(&gc, options_get_number(oo, "mode-fg")); + colour_set_bg(&gc, options_get_number(oo, "mode-bg")); + gc.attr |= options_get_number(oo, "mode-attr"); screen_write_puts(ctx, &gc, "%s", hdr); memcpy(&gc, &grid_default_cell, sizeof gc); } else diff --git a/window-scroll.c b/window-scroll.c index 188ee9a3..549b684a 100644 --- a/window-scroll.c +++ b/window-scroll.c @@ -1,4 +1,4 @@ -/* $Id: window-scroll.c,v 1.40 2009-08-16 19:26:49 tcunha Exp $ */ +/* $Id: window-scroll.c,v 1.41 2009-09-11 14:13:52 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -192,6 +192,7 @@ window_scroll_write_line( { struct window_scroll_mode_data *data = wp->modedata; struct screen *s = &data->screen; + struct options *oo = &wp->window->options; struct grid_cell gc; char hdr[32]; size_t size; @@ -200,9 +201,9 @@ window_scroll_write_line( memcpy(&gc, &grid_default_cell, sizeof gc); size = xsnprintf(hdr, sizeof hdr, "[%u,%u/%u]", data->ox, data->oy, screen_hsize(&wp->base)); - gc.fg = options_get_number(&wp->window->options, "mode-fg"); - gc.bg = options_get_number(&wp->window->options, "mode-bg"); - gc.attr |= options_get_number(&wp->window->options, "mode-attr"); + colour_set_fg(&gc, options_get_number(oo, "mode-fg")); + colour_set_bg(&gc, options_get_number(oo, "mode-bg")); + gc.attr |= options_get_number(oo, "mode-attr"); screen_write_cursormove(ctx, screen_size_x(s) - size, 0); screen_write_puts(ctx, &gc, "%s", hdr); memcpy(&gc, &grid_default_cell, sizeof gc);