aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-03-07 10:29:06 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-03-07 10:29:06 +0000
commite6d35b6aa49ca708f62a289bc7c44ad09f5a393f (patch)
tree2ada93cebada7d5bee775832411894ddad6b1680
parent521fa7d6409da23ff3f9f357dc8244374ef01a9e (diff)
downloadrtmux-e6d35b6aa49ca708f62a289bc7c44ad09f5a393f.tar.gz
rtmux-e6d35b6aa49ca708f62a289bc7c44ad09f5a393f.tar.bz2
rtmux-e6d35b6aa49ca708f62a289bc7c44ad09f5a393f.zip
Support for 88 colour terminals.
-rw-r--r--CHANGES3
-rw-r--r--TODO2
-rw-r--r--colour.c31
-rw-r--r--server-msg.c4
-rw-r--r--tmux.c9
-rw-r--r--tmux.h11
-rw-r--r--tty-term.c8
-rw-r--r--tty.c74
8 files changed, 100 insertions, 42 deletions
diff --git a/CHANGES b/CHANGES
index 99012b24..3cd5643d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,6 @@
07 March 2009
+* Support for 88 colour terminals.
* break-pane command to create a new window using an existing pane.
02 March 2009
@@ -1123,7 +1124,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.257 2009-03-07 09:29:54 nicm Exp $
+$Id: CHANGES,v 1.258 2009-03-07 10:29:06 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
diff --git a/TODO b/TODO
index 99a60204..ebb5d9d3 100644
--- a/TODO
+++ b/TODO
@@ -81,7 +81,6 @@
- attach should have a flag to create session if it doesn't exist
- swap-pane-up, swap-pane-down (maybe move-pane-*)
- move-pane (to window) (maybe break-pane?)
-- 88 colour support; new grid cell flag, and 256<->88 88<->16 translation tables
- some fix for SF feature request 2527847 - now remain-by-default has gone
cannot control it per-session
- clear window title on exit
@@ -94,4 +93,5 @@
for stuff like mode keys?
- document status-keys
- document break-pane
+- document -8 flag
- refer to windows by name etc (duplicates? fnmatch?)
diff --git a/colour.c b/colour.c
index 497f157b..f825c4a9 100644
--- a/colour.c
+++ b/colour.c
@@ -1,4 +1,4 @@
-/* $Id: colour.c,v 1.4 2009-01-27 20:22:33 nicm Exp $ */
+/* $Id: colour.c,v 1.5 2009-03-07 10:29:06 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -74,9 +74,9 @@ colour_fromstring(const char *s)
}
u_char
-colour_translate256(u_char c)
+colour_256to16(u_char c)
{
- static const u_char table[] = {
+ static const u_char table[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 4, 4, 4, 12, 12, 2, 6, 4, 4, 12, 12, 2, 2, 6, 4,
12, 12, 2, 2, 2, 6, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10,
@@ -97,3 +97,28 @@ colour_translate256(u_char c)
return (table[c]);
}
+
+u_char
+colour_256to88(u_char c)
+{
+ static const u_char table[256] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 17, 18, 18, 19, 20, 21, 21, 22, 22, 23, 20, 21, 21, 22,
+ 22, 23, 24, 25, 25, 26, 26, 27, 24, 25, 25, 26, 26, 27, 28, 29,
+ 29, 30, 30, 31, 32, 33, 33, 34, 34, 35, 36, 37, 37, 38, 38, 39,
+ 36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43, 40, 41, 41, 42,
+ 42, 43, 44, 45, 45, 46, 46, 47, 32, 33, 33, 34, 34, 35, 36, 37,
+ 37, 38, 38, 39, 36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43,
+ 40, 41, 41, 42, 42, 43, 44, 45, 45, 46, 46, 47, 48, 49, 49, 50,
+ 50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54, 54, 55, 56, 57,
+ 57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61, 61, 62, 62, 63,
+ 48, 49, 49, 50, 50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54,
+ 54, 55, 56, 57, 57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61,
+ 61, 62, 62, 63, 64, 65, 65, 66, 66, 67, 68, 69, 69, 70, 70, 71,
+ 68, 69, 69, 70, 70, 71, 72, 73, 73, 74, 74, 75, 72, 73, 73, 74,
+ 74, 75, 76, 77, 77, 78, 78, 79, 0, 0, 80, 80, 80, 81, 81, 81,
+ 82, 82, 82, 83, 83, 83, 84, 84, 84, 85, 85, 85, 86, 86, 86, 87
+ };
+
+ return (table[c]);
+}
diff --git a/server-msg.c b/server-msg.c
index decafe8b..e7a82dad 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -1,4 +1,4 @@
-/* $Id: server-msg.c,v 1.64 2009-02-16 19:01:16 nicm Exp $ */
+/* $Id: server-msg.c,v 1.65 2009-03-07 10:29:06 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -205,6 +205,8 @@ server_msg_fn_identify(struct hdr *hdr, struct client *c)
c->tty.flags |= TTY_UTF8;
if (data.flags & IDENTIFY_256COLOURS)
c->tty.term_flags |= TERM_256COLOURS;
+ else if (data.flags & IDENTIFY_88COLOURS)
+ c->tty.term_flags |= TERM_88COLOURS;
if (data.flags & IDENTIFY_HASDEFAULTS)
c->tty.term_flags |= TERM_HASDEFAULTS;
xfree(term);
diff --git a/tmux.c b/tmux.c
index c963a81e..4e362aa5 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.107 2009-02-13 21:39:45 nicm Exp $ */
+/* $Id: tmux.c,v 1.108 2009-03-07 10:29:06 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -191,10 +191,15 @@ main(int argc, char **argv)
unlock = flags = 0;
path = NULL;
- while ((opt = getopt(argc, argv, "2df:qS:uUVv")) != -1) {
+ while ((opt = getopt(argc, argv, "28df:qS:uUVv")) != -1) {
switch (opt) {
case '2':
flags |= IDENTIFY_256COLOURS;
+ flags &= ~IDENTIFY_88COLOURS;
+ break;
+ case '8':
+ flags |= IDENTIFY_88COLOURS;
+ flags &= ~IDENTIFY_256COLOURS;
break;
case 'f':
cfg_file = xstrdup(optarg);
diff --git a/tmux.h b/tmux.h
index 7a5212df..8544f828 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.278 2009-03-07 09:29:54 nicm Exp $ */
+/* $Id: tmux.h,v 1.279 2009-03-07 10:29:06 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -400,7 +400,8 @@ struct msg_identify_data {
#define IDENTIFY_UTF8 0x1
#define IDENTIFY_256COLOURS 0x2
-#define IDENTIFY_HASDEFAULTS 0x4
+#define IDENTIFY_88COLOURS 0x4
+#define IDENTIFY_HASDEFAULTS 0x8
int flags;
u_int sx;
@@ -753,7 +754,8 @@ struct tty_term {
#define TERM_HASDEFAULTS 0x1
#define TERM_256COLOURS 0x2
-#define TERM_EARLYWRAP 0x4
+#define TERM_88COLOURS 0x4
+#define TERM_EARLYWRAP 0x8
int flags;
SLIST_ENTRY(tty_term) entry;
@@ -1353,7 +1355,8 @@ void input_mouse(struct window_pane *, u_char, u_char, u_char);
/* colour.c */
const char *colour_tostring(u_char);
int colour_fromstring(const char *);
-u_char colour_translate256(u_char);
+u_char colour_256to16(u_char);
+u_char colour_256to88(u_char);
/* attributes.c */
const char *attributes_tostring(u_char);
diff --git a/tty-term.c b/tty-term.c
index 55f44e40..61ebcacb 100644
--- a/tty-term.c
+++ b/tty-term.c
@@ -1,4 +1,4 @@
-/* $Id: tty-term.c,v 1.16 2009-03-02 18:05:40 nicm Exp $ */
+/* $Id: tty-term.c,v 1.17 2009-03-07 10:29:06 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -310,7 +310,7 @@ tty_term_find(char *name, int fd, char **cause)
term->flags |= TERM_HASDEFAULTS;
/*
- * Try to figure out if we have 256 colours. The standard xterm
+ * Try to figure out if we have 256 or 88 colours. The standard xterm
* definitions are broken (well, or the way they are parsed is: in any
* case they end up returning 8). So also do a hack.
*/
@@ -318,6 +318,10 @@ tty_term_find(char *name, int fd, char **cause)
term->flags |= TERM_256COLOURS;
if (strstr(name, "256col") != NULL) /* XXX HACK */
term->flags |= TERM_256COLOURS;
+ if (tty_term_number(term, TTYC_COLORS) == 88)
+ term->flags |= TERM_88COLOURS;
+ if (strstr(name, "88col") != NULL) /* XXX HACK */
+ term->flags |= TERM_88COLOURS;
return (term);
diff --git a/tty.c b/tty.c
index 495654d8..eb322fce 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $Id: tty.c,v 1.79 2009-02-17 18:53:10 nicm Exp $ */
+/* $Id: tty.c,v 1.80 2009-03-07 10:29:06 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -36,6 +36,9 @@ void tty_draw_line(struct tty *, struct window_pane *, u_int);
void tty_raw(struct tty *, const char *);
+int tty_try_256(struct tty *, u_char, const char *);
+int tty_try_88(struct tty *, u_char, const char *);
+
void tty_attributes(struct tty *, const struct grid_cell *);
void tty_attributes_fg(struct tty *, const struct grid_cell *);
void tty_attributes_bg(struct tty *, const struct grid_cell *);
@@ -866,20 +869,47 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc)
}
}
+int
+tty_try_256(struct tty *tty, u_char colour, const char *type)
+{
+ char s[32];
+
+ if (!(tty->term->flags & TERM_256COLOURS) &&
+ !(tty->term_flags & TERM_256COLOURS))
+ return (-1);
+
+ xsnprintf(s, sizeof s, "\033[%s;5;%hhum", type, colour);
+ tty_puts(tty, s);
+ return (0);
+}
+
+int
+tty_try_88(struct tty *tty, u_char colour, const char *type)
+{
+ char s[32];
+
+ if (!(tty->term->flags & TERM_88COLOURS) &&
+ !(tty->term_flags & TERM_88COLOURS))
+ return (-1);
+ colour = colour_256to88(colour);
+
+ xsnprintf(s, sizeof s, "\033[%s;5;%hhum", type, colour);
+ tty_puts(tty, s);
+ return (0);
+}
+
void
tty_attributes_fg(struct tty *tty, const struct grid_cell *gc)
{
- char s[32];
- u_char fg = gc->fg;
+ u_char fg;
+ fg = gc->fg;
if (gc->flags & GRID_FLAG_FG256) {
- if ((tty->term->flags & TERM_256COLOURS) ||
- (tty->term_flags & TERM_256COLOURS)) {
- xsnprintf(s, sizeof s, "\033[38;5;%hhum", fg);
- tty_puts(tty, s);
+ if (tty_try_256(tty, fg, "38") == 0)
return;
- }
- fg = colour_translate256(fg);
+ if (tty_try_88(tty, fg, "38") == 0)
+ return;
+ fg = colour_256to16(fg);
if (fg & 8) {
fg &= 7;
tty_putcode(tty, TTYC_BOLD);
@@ -887,7 +917,7 @@ tty_attributes_fg(struct tty *tty, const struct grid_cell *gc)
} else if (tty->cell.attr & GRID_ATTR_BRIGHT)
tty_reset(tty);
}
-
+
if (fg == 8 &&
!(tty->term->flags & TERM_HASDEFAULTS) &&
!(tty->term_flags & TERM_HASDEFAULTS))
@@ -901,29 +931,17 @@ tty_attributes_fg(struct tty *tty, const struct grid_cell *gc)
void
tty_attributes_bg(struct tty *tty, const struct grid_cell *gc)
{
- char s[32];
- u_char bg = gc->bg;
+ u_char bg;
+ bg = gc->bg;
if (gc->flags & GRID_FLAG_BG256) {
- if ((tty->term->flags & TERM_256COLOURS) ||
- (tty->term_flags & TERM_256COLOURS)) {
- xsnprintf(s, sizeof s, "\033[48;5;%hhum", bg);
- tty_puts(tty, s);
+ if (tty_try_256(tty, bg, "48") == 0)
return;
- }
- bg = colour_translate256(bg);
- if (bg & 8) {
- /*
- * Bold background; can't do this on standard
- * terminals...
- */
-#if 0
- xsnprintf(s, sizeof s, "\033[%hhum", 92 + bg);
- tty_puts(tty, s);
+ if (tty_try_88(tty, bg, "48") == 0)
return;
-#endif
+ bg = colour_256to16(bg);
+ if (bg & 8)
bg &= 7;
- }
}
if (bg == 8 &&