mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Detect iTerm2 and enable DECSLRM.
This commit is contained in:
		
							
								
								
									
										57
									
								
								tty-keys.c
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								tty-keys.c
									
									
									
									
									
								
							@@ -52,6 +52,8 @@ static int	tty_keys_clipboard(struct tty *, const char *, size_t,
 | 
				
			|||||||
		    size_t *);
 | 
							    size_t *);
 | 
				
			||||||
static int	tty_keys_device_attributes(struct tty *, const char *, size_t,
 | 
					static int	tty_keys_device_attributes(struct tty *, const char *, size_t,
 | 
				
			||||||
		    size_t *);
 | 
							    size_t *);
 | 
				
			||||||
 | 
					static int	tty_keys_device_status_report(struct tty *, const char *,
 | 
				
			||||||
 | 
							    size_t, size_t *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Default raw keys. */
 | 
					/* Default raw keys. */
 | 
				
			||||||
struct tty_default_key_raw {
 | 
					struct tty_default_key_raw {
 | 
				
			||||||
@@ -607,6 +609,17 @@ tty_keys_next(struct tty *tty)
 | 
				
			|||||||
		goto partial_key;
 | 
							goto partial_key;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Is this a device status report response? */
 | 
				
			||||||
 | 
						switch (tty_keys_device_status_report(tty, buf, len, &size)) {
 | 
				
			||||||
 | 
						case 0:		/* yes */
 | 
				
			||||||
 | 
							key = KEYC_UNKNOWN;
 | 
				
			||||||
 | 
							goto complete_key;
 | 
				
			||||||
 | 
						case -1:	/* no, or not valid */
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case 1:		/* partial */
 | 
				
			||||||
 | 
							goto partial_key;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Is this a mouse key press? */
 | 
						/* Is this a mouse key press? */
 | 
				
			||||||
	switch (tty_keys_mouse(tty, buf, len, &size, &m)) {
 | 
						switch (tty_keys_mouse(tty, buf, len, &size, &m)) {
 | 
				
			||||||
	case 0:		/* yes */
 | 
						case 0:		/* yes */
 | 
				
			||||||
@@ -1054,3 +1067,47 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
 | 
				
			|||||||
	tty_set_flags(tty, flags);
 | 
						tty_set_flags(tty, flags);
 | 
				
			||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Handle device status report input. Returns 0 for success, -1 for failure, 1
 | 
				
			||||||
 | 
					 * for partial.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len,
 | 
				
			||||||
 | 
					    size_t *size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct client	*c = tty->client;
 | 
				
			||||||
 | 
						u_int		 i;
 | 
				
			||||||
 | 
						char		 tmp[64];
 | 
				
			||||||
 | 
						int		 flags = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*size = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* First three bytes are always \033[. */
 | 
				
			||||||
 | 
						if (buf[0] != '\033')
 | 
				
			||||||
 | 
							return (-1);
 | 
				
			||||||
 | 
						if (len == 1)
 | 
				
			||||||
 | 
							return (1);
 | 
				
			||||||
 | 
						if (buf[1] != '[')
 | 
				
			||||||
 | 
							return (-1);
 | 
				
			||||||
 | 
						if (len == 2)
 | 
				
			||||||
 | 
							return (1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Copy the rest up to a 'n'. */
 | 
				
			||||||
 | 
						for (i = 0; i < (sizeof tmp) - 1 && buf[2 + i] != 'n'; i++) {
 | 
				
			||||||
 | 
							if (2 + i == len)
 | 
				
			||||||
 | 
								return (1);
 | 
				
			||||||
 | 
							tmp[i] = buf[2 + i];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (i == (sizeof tmp) - 1)
 | 
				
			||||||
 | 
							return (-1);
 | 
				
			||||||
 | 
						tmp[i] = '\0';
 | 
				
			||||||
 | 
						*size = 3 + i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Set terminal flags. */
 | 
				
			||||||
 | 
						if (strncmp(tmp, "ITERM2 ", 7) == 0)
 | 
				
			||||||
 | 
							flags |= TERM_DECSLRM;
 | 
				
			||||||
 | 
						log_debug("%s: received DSR %.*s", c->name, (int)*size, buf);
 | 
				
			||||||
 | 
						tty_set_flags(tty, flags);
 | 
				
			||||||
 | 
						return (0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								tty.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tty.c
									
									
									
									
									
								
							@@ -327,7 +327,7 @@ tty_start_tty(struct tty *tty)
 | 
				
			|||||||
			tty->flags |= TTY_FOCUS;
 | 
								tty->flags |= TTY_FOCUS;
 | 
				
			||||||
			tty_puts(tty, "\033[?1004h");
 | 
								tty_puts(tty, "\033[?1004h");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		tty_puts(tty, "\033[c");
 | 
							tty_puts(tty, "\033[c\033[1337n");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tty->flags |= TTY_STARTED;
 | 
						tty->flags |= TTY_STARTED;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user