From 514d6fa1ec60563318c67806334c3b8d97c95b02 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 12 Oct 2007 13:51:44 +0000 Subject: [PATCH] Accept colours as strings. --- CHANGES | 5 +++-- TODO | 3 +-- cmd-set-option.c | 8 ++++--- cmd.c | 5 +++-- screen.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++- tmux.h | 4 +++- 6 files changed, 68 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index 7bed252f..988da18a 100644 --- a/CHANGES +++ b/CHANGES @@ -2,7 +2,8 @@ * (nicm) send-prefix command. Bound to C-b by default. * (nicm) set status, status-fg, status-bg commands. fg and bg are as a number - from 0 to 7. status may be 0/1/on/off/yes/no. + from 0 to 8 or a string ("red", "blue", etc). status may be 1/0, on/off, + yes/no. * (nicm) Make status line mark window in yellow on bell. 04 October 2007 @@ -125,5 +126,5 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.39 2007-10-12 13:03:58 nicm Exp $ +$Id: CHANGES,v 1.40 2007-10-12 13:51:44 nicm Exp $ diff --git a/TODO b/TODO index dd2ee049..631c2958 100644 --- a/TODO +++ b/TODO @@ -42,8 +42,7 @@ - Nested sessions over the network, plug-in another tmux as a window/subsession - it would be nice to have multichar commands so you could have C-b K K for kill-window to limit accidental presses -- status-fg/status-bg should be able to a) use strings for colours "red" etc - b) set attributes too ("bold-red"?) +- status-fg/status-bg should be to set attributes: bold, etc -- For 0.1 -------------------------------------------------------------------- - man page diff --git a/cmd-set-option.c b/cmd-set-option.c index a3a12fb8..4c776ab9 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.6 2007-10-12 12:11:40 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.7 2007-10-12 13:51:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -139,7 +139,8 @@ cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx) ctx->error(ctx, "invalid value"); return; } - if (errstr != NULL || number > 7) { + number = screen_stringcolour(data->value); + if (number > 8) { ctx->error(ctx, "bad colour: %s", data->value); return; } @@ -157,7 +158,8 @@ cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx) ctx->error(ctx, "invalid value"); return; } - if (errstr != NULL || number > 7) { + number = screen_stringcolour(data->value); + if (number > 8) { ctx->error(ctx, "bad colour: %s", data->value); return; } diff --git a/cmd.c b/cmd.c index de07e3b4..c0bcd138 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.15 2007-10-12 13:03:58 nicm Exp $ */ +/* $Id: cmd.c,v 1.16 2007-10-12 13:51:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -56,7 +56,8 @@ cmd_parse(int argc, char **argv, char **cause) entry = NULL; for (entryp = cmd_table; *entryp != NULL; entryp++) { - if (strcmp((*entryp)->alias, argv[0]) == 0) { + if ((*entryp)->alias != NULL && + strcmp((*entryp)->alias, argv[0]) == 0) { entry = *entryp; break; } diff --git a/screen.c b/screen.c index dc4ccc2b..e9c66aa0 100644 --- a/screen.c +++ b/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.22 2007-10-05 17:51:56 nicm Exp $ */ +/* $Id: screen.c,v 1.23 2007-10-12 13:51:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -43,6 +43,58 @@ void screen_fill_lines( #define screen_offset_y(py, ny) ((py) + (ny) - 1) #define screen_offset_x(px, nx) ((px) + (nx) - 1) +/* Colour to string. */ +const char * +screen_colourstring(u_char c) +{ + switch (c) { + case 0: + return ("black"); + case 1: + return ("red"); + case 2: + return ("green"); + case 3: + return ("yellow"); + case 4: + return ("blue"); + case 5: + return ("magenta"); + case 6: + return ("cyan"); + case 7: + return ("white"); + case 8: + return ("default"); + } + return (NULL); +} + +/* String to colour. */ +u_char +screen_stringcolour(const char *s) +{ + if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0')) + return (0); + if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0')) + return (1); + if (strcasecmp(s, "green") == 0 || (s[0] == '2' && s[1] == '\0')) + return (2); + if (strcasecmp(s, "yellow") == 0 || (s[0] == '3' && s[1] == '\0')) + return (3); + if (strcasecmp(s, "blue") == 0 || (s[0] == '4' && s[1] == '\0')) + return (4); + if (strcasecmp(s, "magenta") == 0 || (s[0] == '5' && s[1] == '\0')) + return (5); + if (strcasecmp(s, "cyan") == 0 || (s[0] == '6' && s[1] == '\0')) + return (6); + if (strcasecmp(s, "white") == 0 || (s[0] == '7' && s[1] == '\0')) + return (7); + if (strcasecmp(s, "default") == 0 || (s[0] == '8' && s[1] == '\0')) + return (8); + return (255); +} + /* Create a new screen. */ void screen_create(struct screen *s, u_int sx, u_int sy) diff --git a/tmux.h b/tmux.h index f5833e55..8dfc8824 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.56 2007-10-12 13:03:58 nicm Exp $ */ +/* $Id: tmux.h,v 1.57 2007-10-12 13:51:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -603,6 +603,8 @@ void input_store_two(struct buffer *, u_char, uint16_t, uint16_t); void input_translate_key(struct buffer *, int); /* screen.c */ +const char *screen_colourstring(u_char); +u_char screen_stringcolour(const char *); void screen_create(struct screen *, u_int, u_int); void screen_destroy(struct screen *); void screen_resize(struct screen *, u_int, u_int);