Sync OpenBSD patchset 322:

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".
This commit is contained in:
Tiago Cunha 2009-09-11 14:13:52 +00:00
parent f0cb57d8ac
commit 0ec1ce005c
13 changed files with 136 additions and 73 deletions

View File

@ -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 <nicm@users.sourceforge.net>
@ -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';

View File

@ -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 <nicm@users.sourceforge.net>
@ -18,13 +18,42 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#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'))

View File

@ -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 <nicm@users.sourceforge.net>
@ -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;

View File

@ -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 <nicm@users.sourceforge.net>
@ -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 {

View File

@ -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 <nicm@users.sourceforge.net>
@ -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);

View File

@ -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 <nicm@users.sourceforge.net>
@ -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);

11
tmux.1
View File

@ -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 <nicm@users.sourceforge.net>
.\"
@ -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.

6
tmux.h
View File

@ -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 <nicm@users.sourceforge.net>
@ -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);

5
tty.c
View File

@ -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 <nicm@users.sourceforge.net>
@ -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);

View File

@ -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 <nicm@users.sourceforge.net>
@ -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);

View File

@ -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 <nicm@users.sourceforge.net>
@ -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;

View File

@ -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 <nicm@users.sourceforge.net>
@ -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

View File

@ -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 <nicm@users.sourceforge.net>
@ -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);