mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Support for 88 colour terminals.
This commit is contained in:
		
							
								
								
									
										3
									
								
								CHANGES
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								CHANGES
									
									
									
									
									
								
							| @@ -1,5 +1,6 @@ | |||||||
| 07 March 2009 | 07 March 2009 | ||||||
|  |  | ||||||
|  | * Support for 88 colour terminals. | ||||||
| * break-pane command to create a new window using an existing pane. | * break-pane command to create a new window using an existing pane. | ||||||
|  |  | ||||||
| 02 March 2009 | 02 March 2009 | ||||||
| @@ -1123,7 +1124,7 @@ | |||||||
|   (including mutt, emacs). No status bar yet and no key remapping or other |   (including mutt, emacs). No status bar yet and no key remapping or other | ||||||
|   customisation. |   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:  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 |  LocalWords:  rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								TODO
									
									
									
									
									
								
							| @@ -81,7 +81,6 @@ | |||||||
| - attach should have a flag to create session if it doesn't exist | - attach should have a flag to create session if it doesn't exist | ||||||
| - swap-pane-up, swap-pane-down (maybe move-pane-*) | - swap-pane-up, swap-pane-down (maybe move-pane-*) | ||||||
| - move-pane (to window) (maybe break-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 | - some fix for SF feature request 2527847 - now remain-by-default has gone | ||||||
|   cannot control it per-session |   cannot control it per-session | ||||||
| - clear window title on exit | - clear window title on exit | ||||||
| @@ -94,4 +93,5 @@ | |||||||
|   for stuff like mode keys? |   for stuff like mode keys? | ||||||
| - document status-keys | - document status-keys | ||||||
| - document break-pane | - document break-pane | ||||||
|  | - document -8 flag | ||||||
| - refer to windows by name etc (duplicates? fnmatch?) | - refer to windows by name etc (duplicates? fnmatch?) | ||||||
|   | |||||||
							
								
								
									
										31
									
								
								colour.c
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								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> |  * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> | ||||||
| @@ -74,9 +74,9 @@ colour_fromstring(const char *s) | |||||||
| } | } | ||||||
|  |  | ||||||
| u_char | 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,  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, | 		 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, | 		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]); | 	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]); | ||||||
|  | } | ||||||
|   | |||||||
| @@ -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> |  * 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; | 		c->tty.flags |= TTY_UTF8; | ||||||
| 	if (data.flags & IDENTIFY_256COLOURS) | 	if (data.flags & IDENTIFY_256COLOURS) | ||||||
| 		c->tty.term_flags |= TERM_256COLOURS; | 		c->tty.term_flags |= TERM_256COLOURS; | ||||||
|  | 	else if (data.flags & IDENTIFY_88COLOURS) | ||||||
|  | 		c->tty.term_flags |= TERM_88COLOURS; | ||||||
| 	if (data.flags & IDENTIFY_HASDEFAULTS) | 	if (data.flags & IDENTIFY_HASDEFAULTS) | ||||||
| 		c->tty.term_flags |= TERM_HASDEFAULTS; | 		c->tty.term_flags |= TERM_HASDEFAULTS; | ||||||
| 	xfree(term); | 	xfree(term); | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								tmux.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								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> |  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> | ||||||
| @@ -191,10 +191,15 @@ main(int argc, char **argv) | |||||||
|  |  | ||||||
| 	unlock = flags = 0; | 	unlock = flags = 0; | ||||||
| 	path = NULL; | 	path = NULL; | ||||||
|         while ((opt = getopt(argc, argv, "2df:qS:uUVv")) != -1) { |         while ((opt = getopt(argc, argv, "28df:qS:uUVv")) != -1) { | ||||||
|                 switch (opt) { |                 switch (opt) { | ||||||
| 		case '2': | 		case '2': | ||||||
| 			flags |= IDENTIFY_256COLOURS; | 			flags |= IDENTIFY_256COLOURS; | ||||||
|  | 			flags &= ~IDENTIFY_88COLOURS; | ||||||
|  | 			break; | ||||||
|  | 		case '8': | ||||||
|  | 			flags |= IDENTIFY_88COLOURS; | ||||||
|  | 			flags &= ~IDENTIFY_256COLOURS; | ||||||
| 			break; | 			break; | ||||||
| 		case 'f': | 		case 'f': | ||||||
| 			cfg_file = xstrdup(optarg); | 			cfg_file = xstrdup(optarg); | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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> |  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> | ||||||
| @@ -400,7 +400,8 @@ struct msg_identify_data { | |||||||
|  |  | ||||||
| #define IDENTIFY_UTF8 0x1 | #define IDENTIFY_UTF8 0x1 | ||||||
| #define IDENTIFY_256COLOURS 0x2 | #define IDENTIFY_256COLOURS 0x2 | ||||||
| #define IDENTIFY_HASDEFAULTS 0x4 | #define IDENTIFY_88COLOURS 0x4 | ||||||
|  | #define IDENTIFY_HASDEFAULTS 0x8 | ||||||
| 	int		flags; | 	int		flags; | ||||||
|  |  | ||||||
| 	u_int		sx; | 	u_int		sx; | ||||||
| @@ -753,7 +754,8 @@ struct tty_term { | |||||||
|  |  | ||||||
| #define TERM_HASDEFAULTS 0x1 | #define TERM_HASDEFAULTS 0x1 | ||||||
| #define TERM_256COLOURS 0x2 | #define TERM_256COLOURS 0x2 | ||||||
| #define TERM_EARLYWRAP 0x4 | #define TERM_88COLOURS 0x4 | ||||||
|  | #define TERM_EARLYWRAP 0x8 | ||||||
| 	int		 flags; | 	int		 flags; | ||||||
|  |  | ||||||
| 	SLIST_ENTRY(tty_term) entry; | 	SLIST_ENTRY(tty_term) entry; | ||||||
| @@ -1353,7 +1355,8 @@ void	 input_mouse(struct window_pane *, u_char, u_char, u_char); | |||||||
| /* colour.c */ | /* colour.c */ | ||||||
| const char *colour_tostring(u_char); | const char *colour_tostring(u_char); | ||||||
| int	 colour_fromstring(const 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 */ | /* attributes.c */ | ||||||
| const char *attributes_tostring(u_char); | const char *attributes_tostring(u_char); | ||||||
|   | |||||||
| @@ -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> |  * 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; | 		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 | 	 * definitions are broken (well, or the way they are parsed is: in any | ||||||
| 	 * case they end up returning 8). So also do a hack. | 	 * 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; | 		term->flags |= TERM_256COLOURS; | ||||||
| 	if (strstr(name, "256col") != NULL) /* XXX HACK */ | 	if (strstr(name, "256col") != NULL) /* XXX HACK */ | ||||||
| 		term->flags |= TERM_256COLOURS; | 		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); | 	return (term); | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										74
									
								
								tty.c
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								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> |  * 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 *); | 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(struct tty *, const struct grid_cell *); | ||||||
| void	tty_attributes_fg(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 *); | 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 | void | ||||||
| tty_attributes_fg(struct tty *tty, const struct grid_cell *gc) | tty_attributes_fg(struct tty *tty, const struct grid_cell *gc) | ||||||
| { | { | ||||||
| 	char	s[32]; | 	u_char	fg; | ||||||
| 	u_char	fg = gc->fg; |  | ||||||
|  |  | ||||||
|  | 	fg = gc->fg; | ||||||
| 	if (gc->flags & GRID_FLAG_FG256) { | 	if (gc->flags & GRID_FLAG_FG256) { | ||||||
| 		if ((tty->term->flags & TERM_256COLOURS) || | 		if (tty_try_256(tty, fg, "38") == 0) | ||||||
| 		    (tty->term_flags & TERM_256COLOURS)) { |  | ||||||
| 			xsnprintf(s, sizeof s, "\033[38;5;%hhum", fg); |  | ||||||
| 			tty_puts(tty, s); |  | ||||||
| 			return; | 			return; | ||||||
| 		} | 		if (tty_try_88(tty, fg, "38") == 0) | ||||||
| 		fg = colour_translate256(fg); | 			return; | ||||||
|  | 		fg = colour_256to16(fg); | ||||||
| 		if (fg & 8) { | 		if (fg & 8) { | ||||||
| 			fg &= 7; | 			fg &= 7; | ||||||
| 			tty_putcode(tty, TTYC_BOLD); | 			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) | 		} else if (tty->cell.attr & GRID_ATTR_BRIGHT) | ||||||
| 			tty_reset(tty); | 			tty_reset(tty); | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
| 	if (fg == 8 && | 	if (fg == 8 && | ||||||
| 	    !(tty->term->flags & TERM_HASDEFAULTS) && | 	    !(tty->term->flags & TERM_HASDEFAULTS) && | ||||||
| 	    !(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 | void | ||||||
| tty_attributes_bg(struct tty *tty, const struct grid_cell *gc) | tty_attributes_bg(struct tty *tty, const struct grid_cell *gc) | ||||||
| { | { | ||||||
| 	char	s[32]; | 	u_char	bg; | ||||||
| 	u_char	bg = gc->bg; |  | ||||||
|  |  | ||||||
|  | 	bg = gc->bg; | ||||||
| 	if (gc->flags & GRID_FLAG_BG256) { | 	if (gc->flags & GRID_FLAG_BG256) { | ||||||
| 		if ((tty->term->flags & TERM_256COLOURS) || | 		if (tty_try_256(tty, bg, "48") == 0) | ||||||
| 		    (tty->term_flags & TERM_256COLOURS)) { |  | ||||||
| 			xsnprintf(s, sizeof s, "\033[48;5;%hhum", bg); |  | ||||||
| 			tty_puts(tty, s); |  | ||||||
| 			return; | 			return; | ||||||
| 		} | 		if (tty_try_88(tty, bg, "48") == 0) | ||||||
| 		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); |  | ||||||
| 			return; | 			return; | ||||||
| #endif | 		bg = colour_256to16(bg); | ||||||
|  | 		if (bg & 8) | ||||||
| 			bg &= 7; | 			bg &= 7; | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (bg == 8 && | 	if (bg == 8 && | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Nicholas Marriott
					Nicholas Marriott