mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	If we can identify the terminal as iTerm2 or as tmux, we can be sure
they support 256 and RGB colours, so set those flags too.
This commit is contained in:
		
							
								
								
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1171,6 +1171,7 @@ struct tty_term {
 | 
				
			|||||||
#define TERM_NOXENL 0x2
 | 
					#define TERM_NOXENL 0x2
 | 
				
			||||||
#define TERM_DECSLRM 0x4
 | 
					#define TERM_DECSLRM 0x4
 | 
				
			||||||
#define TERM_DECFRA 0x8
 | 
					#define TERM_DECFRA 0x8
 | 
				
			||||||
 | 
					#define TERM_RGBCOLOURS 0x10
 | 
				
			||||||
	int		 flags;
 | 
						int		 flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	LIST_ENTRY(tty_term) entry;
 | 
						LIST_ENTRY(tty_term) entry;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1117,7 +1117,9 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* Set terminal flags. */
 | 
						/* Set terminal flags. */
 | 
				
			||||||
	if (strncmp(tmp, "ITERM2 ", 7) == 0)
 | 
						if (strncmp(tmp, "ITERM2 ", 7) == 0)
 | 
				
			||||||
		flags |= TERM_DECSLRM;
 | 
							flags |= (TERM_DECSLRM|TERM_256COLOURS|TERM_RGBCOLOURS);
 | 
				
			||||||
 | 
						if (strncmp(tmp, "TMUX ", 5) == 0)
 | 
				
			||||||
 | 
							flags |= (TERM_256COLOURS|TERM_RGBCOLOURS);
 | 
				
			||||||
	log_debug("%s: received DSR %.*s", c->name, (int)*size, buf);
 | 
						log_debug("%s: received DSR %.*s", c->name, (int)*size, buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tty_set_flags(tty, flags);
 | 
						tty_set_flags(tty, flags);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										28
									
								
								tty-term.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								tty-term.c
									
									
									
									
									
								
							@@ -522,11 +522,16 @@ tty_term_find(char *name, int fd, char **cause)
 | 
				
			|||||||
		goto error;
 | 
							goto error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Figure out if we have 256 colours (or more). */
 | 
						/* Set flag if terminal has 256 colours. */
 | 
				
			||||||
	if (tty_term_number(term, TTYC_COLORS) >= 256 ||
 | 
						if (tty_term_number(term, TTYC_COLORS) >= 256)
 | 
				
			||||||
	    tty_term_has(term, TTYC_RGB))
 | 
					 | 
				
			||||||
		term->flags |= TERM_256COLOURS;
 | 
							term->flags |= TERM_256COLOURS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Set flag if terminal has RGB colours. */
 | 
				
			||||||
 | 
						if ((tty_term_flag(term, TTYC_TC) || tty_term_has(term, TTYC_RGB)) ||
 | 
				
			||||||
 | 
						    (tty_term_has(term, TTYC_SETRGBF) &&
 | 
				
			||||||
 | 
						    tty_term_has(term, TTYC_SETRGBB)))
 | 
				
			||||||
 | 
							term->flags |= TERM_RGBCOLOURS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1
 | 
						 * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1
 | 
				
			||||||
	 * rather than $COLUMNS (the cursor can never be beyond $COLUMNS - 1).
 | 
						 * rather than $COLUMNS (the cursor can never be beyond $COLUMNS - 1).
 | 
				
			||||||
@@ -561,22 +566,7 @@ tty_term_find(char *name, int fd, char **cause)
 | 
				
			|||||||
		code->type = TTYCODE_STRING;
 | 
							code->type = TTYCODE_STRING;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/* Log the capabilities. */
 | 
				
			||||||
	 * On terminals with RGB colour (Tc or RGB), fill in setrgbf and
 | 
					 | 
				
			||||||
	 * setrgbb if they are missing.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	if ((tty_term_flag(term, TTYC_TC) || tty_term_flag(term, TTYC_RGB)) &&
 | 
					 | 
				
			||||||
	    !tty_term_has(term, TTYC_SETRGBF) &&
 | 
					 | 
				
			||||||
	    !tty_term_has(term, TTYC_SETRGBB)) {
 | 
					 | 
				
			||||||
		code = &term->codes[TTYC_SETRGBF];
 | 
					 | 
				
			||||||
		code->value.string = xstrdup("\033[38;2;%p1%d;%p2%d;%p3%dm");
 | 
					 | 
				
			||||||
		code->type = TTYCODE_STRING;
 | 
					 | 
				
			||||||
		code = &term->codes[TTYC_SETRGBB];
 | 
					 | 
				
			||||||
		code->value.string = xstrdup("\033[48;2;%p1%d;%p2%d;%p3%dm");
 | 
					 | 
				
			||||||
		code->type = TTYCODE_STRING;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Log it. */
 | 
					 | 
				
			||||||
	for (i = 0; i < tty_term_ncodes(); i++)
 | 
						for (i = 0; i < tty_term_ncodes(); i++)
 | 
				
			||||||
		log_debug("%s%s", name, tty_term_describe(term, i));
 | 
							log_debug("%s%s", name, tty_term_describe(term, i));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										27
									
								
								tty.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								tty.c
									
									
									
									
									
								
							@@ -2386,11 +2386,10 @@ tty_check_fg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
 | 
				
			|||||||
	/* Is this a 24-bit colour? */
 | 
						/* Is this a 24-bit colour? */
 | 
				
			||||||
	if (gc->fg & COLOUR_FLAG_RGB) {
 | 
						if (gc->fg & COLOUR_FLAG_RGB) {
 | 
				
			||||||
		/* Not a 24-bit terminal? Translate to 256-colour palette. */
 | 
							/* Not a 24-bit terminal? Translate to 256-colour palette. */
 | 
				
			||||||
		if (!tty_term_has(tty->term, TTYC_SETRGBF)) {
 | 
							if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
 | 
				
			||||||
			colour_split_rgb(gc->fg, &r, &g, &b);
 | 
					 | 
				
			||||||
			gc->fg = colour_find_rgb(r, g, b);
 | 
					 | 
				
			||||||
		} else
 | 
					 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
 | 
							colour_split_rgb(gc->fg, &r, &g, &b);
 | 
				
			||||||
 | 
							gc->fg = colour_find_rgb(r, g, b);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* How many colours does this terminal have? */
 | 
						/* How many colours does this terminal have? */
 | 
				
			||||||
@@ -2436,11 +2435,10 @@ tty_check_bg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
 | 
				
			|||||||
	/* Is this a 24-bit colour? */
 | 
						/* Is this a 24-bit colour? */
 | 
				
			||||||
	if (gc->bg & COLOUR_FLAG_RGB) {
 | 
						if (gc->bg & COLOUR_FLAG_RGB) {
 | 
				
			||||||
		/* Not a 24-bit terminal? Translate to 256-colour palette. */
 | 
							/* Not a 24-bit terminal? Translate to 256-colour palette. */
 | 
				
			||||||
		if (!tty_term_has(tty->term, TTYC_SETRGBB)) {
 | 
							if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
 | 
				
			||||||
			colour_split_rgb(gc->bg, &r, &g, &b);
 | 
					 | 
				
			||||||
			gc->bg = colour_find_rgb(r, g, b);
 | 
					 | 
				
			||||||
		} else
 | 
					 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
 | 
							colour_split_rgb(gc->bg, &r, &g, &b);
 | 
				
			||||||
 | 
							gc->bg = colour_find_rgb(r, g, b);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* How many colours does this terminal have? */
 | 
						/* How many colours does this terminal have? */
 | 
				
			||||||
@@ -2617,15 +2615,14 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (colour & COLOUR_FLAG_RGB) {
 | 
						if (colour & COLOUR_FLAG_RGB) {
 | 
				
			||||||
 | 
							colour_split_rgb(colour & 0xffffff, &r, &g, &b);
 | 
				
			||||||
		if (*type == '3') {
 | 
							if (*type == '3') {
 | 
				
			||||||
			if (!tty_term_has(tty->term, TTYC_SETRGBF))
 | 
								if (!tty_term_has(tty->term, TTYC_SETRGBF))
 | 
				
			||||||
				return (-1);
 | 
									goto fallback_rgb;
 | 
				
			||||||
			colour_split_rgb(colour & 0xffffff, &r, &g, &b);
 | 
					 | 
				
			||||||
			tty_putcode3(tty, TTYC_SETRGBF, r, g, b);
 | 
								tty_putcode3(tty, TTYC_SETRGBF, r, g, b);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if (!tty_term_has(tty->term, TTYC_SETRGBB))
 | 
								if (!tty_term_has(tty->term, TTYC_SETRGBB))
 | 
				
			||||||
				return (-1);
 | 
									goto fallback_rgb;
 | 
				
			||||||
			colour_split_rgb(colour & 0xffffff, &r, &g, &b);
 | 
					 | 
				
			||||||
			tty_putcode3(tty, TTYC_SETRGBB, r, g, b);
 | 
								tty_putcode3(tty, TTYC_SETRGBB, r, g, b);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return (0);
 | 
							return (0);
 | 
				
			||||||
@@ -2638,6 +2635,12 @@ fallback_256:
 | 
				
			|||||||
	log_debug("%s: 256 colour fallback: %s", tty->client->name, s);
 | 
						log_debug("%s: 256 colour fallback: %s", tty->client->name, s);
 | 
				
			||||||
	tty_puts(tty, s);
 | 
						tty_puts(tty, s);
 | 
				
			||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fallback_rgb:
 | 
				
			||||||
 | 
						xsnprintf(s, sizeof s, "\033[%s;2;%d;%d;%dm", type, r, g, b);
 | 
				
			||||||
 | 
						log_debug("%s: RGB colour fallback: %s", tty->client->name, s);
 | 
				
			||||||
 | 
						tty_puts(tty, s);
 | 
				
			||||||
 | 
						return (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user