From: nicm Date: Tue, 18 Apr 2017 18:21:37 +0000 (+0000) Subject: Detect iTerm2 and use DECSLRM for it as well. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a48fea48d884e689152ee604a4579e10ee675f9b;p=openbsd Detect iTerm2 and use DECSLRM for it as well. --- diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 44300a662b4..95288d3e592 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.736 2017/04/18 15:44:17 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.737 2017/04/18 18:21:37 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1071,6 +1071,7 @@ struct tty { TTY_VT220, TTY_VT320, TTY_VT420, + TTY_ITERM2, TTY_UNKNOWN } term_type; @@ -1085,7 +1086,8 @@ struct tty { struct tty_key *key_tree; }; #define TTY_TYPES \ - { "VT100", "VT101", "VT102", "VT220", "VT320", "VT420", "UNKNOWN" } + { "VT100", "VT101", "VT102", "VT220", "VT320", "VT420", "iTerm2", \ + "Unknown" } /* TTY command context. */ struct tty_ctx { diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c index 3967a9ce95e..3fbbb3a709a 100644 --- a/usr.bin/tmux/tty-keys.c +++ b/usr.bin/tmux/tty-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-keys.c,v 1.94 2017/04/18 13:34:04 nicm Exp $ */ +/* $OpenBSD: tty-keys.c,v 1.95 2017/04/18 18:21:37 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -46,6 +46,8 @@ static void tty_keys_callback(int, short, void *); static int tty_keys_mouse(struct tty *, const char *, size_t, size_t *); static int tty_keys_device_attributes(struct tty *, const char *, size_t, size_t *); +static int tty_keys_iterm2_version(struct tty *, const char *, size_t, + size_t *); /* Default raw keys. */ struct tty_default_key_raw { @@ -553,6 +555,17 @@ tty_keys_next(struct tty *tty) goto partial_key; } + /* Or a response from iTerm2? */ + switch (tty_keys_iterm2_version(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? */ switch (tty_keys_mouse(tty, buf, len, &size)) { case 0: /* yes */ @@ -912,3 +925,34 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, types[type]); return (0); } + +/* + * Handle a version response from iTerm2. Returns 0 for success, -1 for + * failure, 1 for partial. + */ +static int +tty_keys_iterm2_version(struct tty *tty, const char *buf, size_t len, + size_t *size) +{ + struct client *c = tty->client; + u_int i; + + *size = 0; + + if (memcmp("\033[ITERM2 ", buf, (len > 9) ? 9 : len) != 0) + return (-1); + if (len < 10) + return (1); + for (i = 9; i < len; i++) { + if (buf[i] == 'n') + break; + } + if (i == len) + return (1); + *size = i + 1; + + tty_set_type(tty, TTY_ITERM2); + + log_debug("%s: this is iTerm2", c->name); + return (0); +} diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index f69eaa99c10..2b99929dd7c 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.263 2017/04/18 15:44:17 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.264 2017/04/18 18:21:37 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -74,9 +74,9 @@ static void tty_default_attributes(struct tty *, const struct window_pane *, #define tty_use_acs(tty) \ (tty_term_has((tty)->term, TTYC_ACSC) && !((tty)->flags & TTY_UTF8)) #define tty_use_margin(tty) \ - ((tty)->term_type == TTY_VT420) + ((tty)->term_type == TTY_VT420 || (tty)->term_type == TTY_ITERM2) -#define tty_pane_full_width(tty, ctx) \ +#define tty_pane_full_width(tty, ctx) \ ((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) void @@ -251,7 +251,7 @@ tty_start_tty(struct tty *tty) tty->flags |= TTY_FOCUS; tty_puts(tty, "\033[?1004h"); } - tty_puts(tty, "\033[c"); + tty_puts(tty, "\033[c\033[1337n"); } tty->flags |= TTY_STARTED;