Index: tmux.h =================================================================== --- tmux.h (revision 2649) +++ tmux.h (working copy) @@ -1643,6 +1643,8 @@ extern const struct cmd_entry cmd_unbind_key_entry; extern const struct cmd_entry cmd_unlink_window_entry; extern const struct cmd_entry cmd_up_pane_entry; +extern const struct cmd_entry cmd_map_colour_entry; +extern const struct cmd_entry cmd_reset_colours_entry; /* cmd-list.c */ struct cmd_list *cmd_list_parse(int, char **, char **); @@ -2102,4 +2104,15 @@ int printflike3 xsnprintf(char *, size_t, const char *, ...); int xvsnprintf(char *, size_t, const char *, va_list); +/* cmd-map-colour.c */ +#define ANY_COLOUR -1 +struct colourpair { + u_int fg16; + u_int bg16; + u_int fg256; + u_int bg256; +}; +ARRAY_DECL(colourmap, struct colourpair *); +extern struct colourmap colourmap; + #endif /* TMUX_H */ Index: cmd-map-colour.c =================================================================== --- cmd-map-colour.c (revision 0) +++ cmd-map-colour.c (revision 0) @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2011 Benjamin Schweizer. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "tmux.h" + +struct colourmap colourmap = ARRAY_INITIALIZER; + +int cmd_map_colour_exec(struct cmd *, struct cmd_ctx *); +int cmd_reset_colours_exec(struct cmd *, struct cmd_ctx *); + +const struct cmd_entry cmd_map_colour_entry = { + "map-colour", "map-color", + ":", 4, 4, + "fg16 bg16 fg256 bg256", + 0, + NULL, + NULL, + cmd_map_colour_exec +}; + +const struct cmd_entry cmd_reset_colours_entry = { + "reset-colours", "reset-colors", + ":", 0, 0, + "", + 0, + NULL, + NULL, + cmd_reset_colours_exec +}; + +int +cmd_map_colour_exec(struct cmd *self, unused struct cmd_ctx *ctx) +{ + struct args *args = self->args; + struct colourpair *cp = NULL; + char *fg16 = args->argv[0], + *bg16 = args->argv[1], + *fg256 = args->argv[2], + *bg256 = args->argv[3]; + long long ll; + const char *errstr = NULL; + + /* + * parse config lines with format "map-colour ", e.g.: + * map-colour 7 0 254 34 + * map-colour 7 * 254 * + *c->fg16 = 7; c->bg16=0; c->fg256=143; c->bg256=113; + */ + cp = xmalloc(sizeof(struct colourpair)); + if (fg16[0] == '*') + cp->fg16 = ANY_COLOUR; + else + cp->fg16 = strtonum(fg16, 0, 255, &errstr); + if (bg16[0] == '*') + cp->bg16 = ANY_COLOUR; + else + cp->bg16 = strtonum(bg16, 0, 255, &errstr); + if (fg256[0] == '*') + cp->fg256 = ANY_COLOUR; + else + cp->fg256 = strtonum(fg256, 0, 255, &errstr); + if (bg256[0] == '*') + cp->bg256 = ANY_COLOUR; + else + cp->bg256 = strtonum(bg256, 0, 255, &errstr); + + ARRAY_ADD(&colourmap, cp); + + return 0; +} + +int +cmd_reset_colours_exec(struct cmd *self, unused struct cmd_ctx *ctx) +{ + struct args *args = self->args; + + ARRAY_CLEAR(&colourmap); + + return 0; +} Index: tty.c =================================================================== --- tty.c (revision 2649) +++ tty.c (working copy) @@ -40,6 +40,7 @@ void tty_colours(struct tty *, const struct grid_cell *); void tty_check_fg(struct tty *, struct grid_cell *); void tty_check_bg(struct tty *, struct grid_cell *); +void tty_upgrade_colour(struct tty *, struct grid_cell *); void tty_colours_fg(struct tty *, const struct grid_cell *); void tty_colours_bg(struct tty *, const struct grid_cell *); @@ -1267,6 +1268,7 @@ /* Fix up the colours if necessary. */ tty_check_fg(tty, &gc2); tty_check_bg(tty, &gc2); + tty_upgrade_colour(tty, &gc2); /* If any bits are being cleared, reset everything. */ if (tc->attr & ~gc2.attr) @@ -1444,6 +1446,44 @@ } void +tty_upgrade_colour(struct tty *tty, struct grid_cell *gc) +{ + u_int colours; + u_int i; + struct colourpair *cp = NULL; + + /* if this is already a 256 colour colour */ + if (gc->flags & (GRID_FLAG_FG256 || GRID_FLAG_BG256)) + return; + + /* if the terminal is not a 88/256 colour terminal */ + if (!(tty->term->flags & TERM_88COLOURS) && + !(tty->term_flags & TERM_88COLOURS) && + !(tty->term->flags & TERM_256COLOURS) && + !(tty->term_flags & TERM_256COLOURS)) + return; + + // check if there is a colourpair + for (i=0; iflags |= GRID_FLAG_FG256 | GRID_FLAG_BG256;; + // prefer exact matches + if (gc->fg == cp->fg16 && gc->bg == cp->bg16) { + gc->fg = cp->fg256; gc->flags |= GRID_FLAG_FG256; + gc->bg = cp->bg256; gc->flags |= GRID_FLAG_BG256; + break; + } + // otherwise, accept wildcards + if (gc->fg == cp->fg16 && cp->bg16 == ANY_COLOUR) { // fg + gc->fg = cp->fg256; gc->flags |= GRID_FLAG_FG256; + } + if (cp->fg16 == ANY_COLOUR && gc->bg == cp->bg16) { // bg + gc->bg = cp->bg256; gc->flags |= GRID_FLAG_BG256; + } + } +} + +void tty_colours_fg(struct tty *tty, const struct grid_cell *gc) { struct grid_cell *tc = &tty->cell; Index: Makefile.am =================================================================== --- Makefile.am (revision 2649) +++ Makefile.am (working copy) @@ -133,6 +133,7 @@ cmd-switch-client.c \ cmd-unbind-key.c \ cmd-unlink-window.c \ + cmd-map-colour.c \ cmd.c \ colour.c \ environ.c \ Index: examples/themes/amber.tmux.conf =================================================================== --- examples/themes/amber.tmux.conf (revision 0) +++ examples/themes/amber.tmux.conf (revision 0) @@ -0,0 +1,60 @@ +# +# tmux theme "amber" +# +# (c) 2011 Benjamin Schweizer. +# +# for activation, add this line to your ~/.tmux.conf: +# +# source /usr/share/tmux/amber.tmux.conf +# +# the colors used are: +# +# 208 214 166 172 178 130 136 94 +# +# This file is in the public domain. Contributions are welcome. +# + +reset-colours + +# specific overwrites +#map-colour 7 0 208 232 + +# foregrounds +map-colour 0 * 94 * # black +map-colour 1 * 136 * # red +map-colour 2 * 130 * # green +map-colour 3 * 178 * # yellow +map-colour 4 * 172 * # blue +map-colour 5 * 166 * # magenta +map-colour 6 * 214 * # cyan +map-colour 7 * 208 * # grey + +map-colour 90 * 94 * +map-colour 91 * 136 * +map-colour 92 * 130 * +map-colour 93 * 178 * +map-colour 94 * 172 * +map-colour 95 * 166 * +map-colour 96 * 214 * +map-colour 97 * 208 * + +# backgrounds +map-colour * 0 * 232 +map-colour * 1 * 233 +map-colour * 2 * 234 +map-colour * 3 * 235 +map-colour * 4 * 236 +map-colour * 5 * 237 +map-colour * 6 * 238 +map-colour * 7 * 239 + +map-colour * 90 * 232 +map-colour * 91 * 233 +map-colour * 92 * 234 +map-colour * 93 * 235 +map-colour * 94 * 236 +map-colour * 95 * 237 +map-colour * 96 * 238 +map-colour * 97 * 239 + +# eof. Index: examples/themes/sundevil.tmux.conf =================================================================== --- examples/themes/sundevil.tmux.conf (revision 0) +++ examples/themes/sundevil.tmux.conf (revision 0) @@ -0,0 +1,74 @@ +# +# tmux theme "sundevil" +# +# (c) 2011 Benjamin Schweizer. +# +# for activation, add this line to your ~/.tmux.conf: +# +# source /usr/share/tmux/sundevil.tmux.conf +# +# the colors used are: +# +#  red 173 d75f5f  +#  green 113 87d75f  +#  yellow 143 d7d75f  +#  blue 111 0087d7  +#  purple 103 5fd7d7  +#  orange 172 d78700  +#  mint 151 afd7af  +#  black 0 000000  +#  grey 59 5f5f5f  +#  white 251 c6c6c6  +#  white 254 e4e4e4  +# +# The colors are based on vim theme wombat256 David Liang, Lars H. Nielsen, +# Danila Despalov, Wolfgang Frisch. +# +# This file is in the public domain. Contributions are welcome. +# + +reset-colours + +# specific overwrites +map-colour 0 6 254 241 # black on cyan to white on grey, see mc +map-colour 0 7 254 241 # black on grey to white on grey, see mc + +# foregrounds +map-colour 0 * 251 * # black +map-colour 1 * 173 * # red +map-colour 2 * 113 * # green +map-colour 3 * 143 * # yellow +map-colour 4 * 111 * # blue +map-colour 5 * 103 * # magenta +map-colour 6 * 151 * # cyan +map-colour 7 * 251 * # grey + +map-colour 90 * 254 * # black +map-colour 91 * 173 * # red +map-colour 92 * 113 * # green +map-colour 93 * 143 * # yellow +map-colour 94 * 111 * # blue +map-colour 95 * 103 * # magenta +map-colour 96 * 151 * # cyan +map-colour 97 * 254 * # white + +# backgrounds +map-colour * 0 * 0 # black +map-colour * 1 * 241 # red +map-colour * 2 * 241 # green +map-colour * 3 * 241 # yellow +map-colour * 4 * 238 # blue +map-colour * 5 * 241 # magenta +map-colour * 6 * 241 # cyan +map-colour * 7 * 241 # grey + +map-colour * 90 * 0 # black +map-colour * 91 * 241 # red +map-colour * 92 * 241 # green +map-colour * 93 * 241 # yellow +map-colour * 94 * 238 # blue +map-colour * 95 * 241 # magenta +map-colour * 96 * 241 # cyan +map-colour * 97 * 241 # white + +# eof. Index: examples/themes/black_and_white.tmux.conf =================================================================== --- examples/themes/black_and_white.tmux.conf (revision 0) +++ examples/themes/black_and_white.tmux.conf (revision 0) @@ -0,0 +1,57 @@ +# +# tmux theme "black and white" +# +# (c) 2011 Benjamin Schweizer +# +# for activation, add this line to your ~/.tmux.conf: +# +# source /usr/share/tmux/black_and_white.tmux.conf +# +# the colors used are: +# +# 233 254 +# +# This file is in the public domain. Contributions are welcome. +# + +reset-colours + +# overwrites + +# foregrounds +map-colour 0 * 254 * +map-colour 1 * 254 * +map-colour 2 * 254 * +map-colour 3 * 254 * +map-colour 4 * 254 * +map-colour 5 * 254 * +map-colour 6 * 254 * +map-colour 7 * 254 * +map-colour 90 * 254 * +map-colour 91 * 254 * +map-colour 92 * 254 * +map-colour 93 * 254 * +map-colour 94 * 254 * +map-colour 95 * 254 * +map-colour 96 * 254 * +map-colour 97 * 254 * + +# backgrounds +map-colour * 0 * 233 +map-colour * 1 * 233 +map-colour * 2 * 233 +map-colour * 3 * 233 +map-colour * 4 * 233 +map-colour * 5 * 233 +map-colour * 6 * 233 +map-colour * 7 * 233 +map-colour * 90 * 233 +map-colour * 91 * 233 +map-colour * 92 * 233 +map-colour * 93 * 233 +map-colour * 94 * 233 +map-colour * 95 * 233 +map-colour * 96 * 233 +map-colour * 97 * 233 + +# eof. Index: tmux.1 =================================================================== --- tmux.1 (revision 2649) +++ tmux.1 (working copy) @@ -1938,6 +1938,32 @@ .Em all sessions would have locked. This has no effect as a session option; it must be set as a global option. +.It Ic map-colour Ar 16-colour-foreground Ar 16-colour-background Ar 256-colour-foreground Ar 256-colour-background +Translates colours from 16 to 88/256 colour palettes, e.g: +.Bd -literal -offset indent +map-colour 7 4 208 236 +.Ed +.Pp +This example translates the 16 colour pair 'gray on blue' (7=grey, 4=blue) +to 256 colour pair 'dark orange on dark grey'. It matches the default +.Xr Irssi 1 +status line. +.Bd -literal -offset indent +reset-colours +map-colour * 4 * 236 +map-colour * 6 * 238 +.Ed +.Pp +The second example illustrates the use of the +.Ic reset-colours +command along with the map-colour wildcard feature. First, all existing +colour mappings are cleared. Then, two new mappings are added: all blue +backgrounds map to a grey shade, and all cyan backgrounds map to a +similar grey shade. +.Pp +With these commands, one can create complete themes. Some example themes +are located in the examples/ directory. They can be activated using the +source command like 'source /usr/share/tmux/amber.tmux.conf'. .It Ic message-attr Ar attributes Set status line message attributes, where .Ar attributes @@ -2054,6 +2080,11 @@ Note that elinks will only attempt to set the window title if the STY environment variable is set. +.It Ic reset-colours +.Xc +Clears all colour mappings set with +.Ic map-colour +command. .It Ic set-titles-string Ar string String used to set the window title if .Ic set-titles Index: cmd.c =================================================================== --- cmd.c (revision 2649) +++ cmd.c (working copy) @@ -108,6 +108,8 @@ &cmd_switch_client_entry, &cmd_unbind_key_entry, &cmd_unlink_window_entry, + &cmd_map_colour_entry, + &cmd_reset_colours_entry, NULL };