Remove support for iTerm2's DSR 1337 extension and use the CSI > q extension

now supported by a few different terminals.
pull/2195/head
Nicholas Marriott 2020-04-23 10:22:27 +01:00
parent e94a15b3d6
commit c74572da92
6 changed files with 46 additions and 36 deletions

View File

@ -1,5 +1,8 @@
CHANGES FROM 3.1 TO 3.2 CHANGES FROM 3.1 TO 3.2
* Remove the DSR 1337 iTerm2 extension and replace by the extended device
attributes sequence (CSI > q) supported by more terminals.
* Add a -s flag to copy-mode to specify a different pane for the source * Add a -s flag to copy-mode to specify a different pane for the source
content. This means it is possible to view two places in a pane's history at content. This means it is possible to view two places in a pane's history at
the same time in different panes, or view the history while still using the the same time in different panes, or view the history while still using the

13
input.c
View File

@ -254,6 +254,7 @@ enum input_csi_type {
INPUT_CSI_TBC, INPUT_CSI_TBC,
INPUT_CSI_VPA, INPUT_CSI_VPA,
INPUT_CSI_WINOPS, INPUT_CSI_WINOPS,
INPUT_CSI_XDA,
}; };
/* Control (CSI) command table. */ /* Control (CSI) command table. */
@ -290,6 +291,7 @@ static const struct input_table_entry input_csi_table[] = {
{ 'm', "", INPUT_CSI_SGR }, { 'm', "", INPUT_CSI_SGR },
{ 'n', "", INPUT_CSI_DSR }, { 'n', "", INPUT_CSI_DSR },
{ 'q', " ", INPUT_CSI_DECSCUSR }, { 'q', " ", INPUT_CSI_DECSCUSR },
{ 'q', ">", INPUT_CSI_XDA },
{ 'r', "", INPUT_CSI_DECSTBM }, { 'r', "", INPUT_CSI_DECSTBM },
{ 's', "", INPUT_CSI_SCP }, { 's', "", INPUT_CSI_SCP },
{ 't', "", INPUT_CSI_WINOPS }, { 't', "", INPUT_CSI_WINOPS },
@ -1456,13 +1458,6 @@ input_csi_dispatch(struct input_ctx *ictx)
case 6: case 6:
input_reply(ictx, "\033[%u;%uR", s->cy + 1, s->cx + 1); input_reply(ictx, "\033[%u;%uR", s->cy + 1, s->cx + 1);
break; break;
case 1337: /* Terminal version, from iTerm2. */
copy = xstrdup(getversion());
for (cp = copy; *cp != '\0'; cp++)
*cp = toupper((u_char)*cp);
input_reply(ictx, "\033[TMUX %sn", copy);
free(copy);
break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
break; break;
@ -1597,6 +1592,10 @@ input_csi_dispatch(struct input_ctx *ictx)
if (n != -1) if (n != -1)
screen_set_cursor_style(s, n); screen_set_cursor_style(s, n);
break; break;
case INPUT_CSI_XDA:
input_reply(ictx, "\033P>|tmux %s\033\\", getversion());
break;
} }
ictx->last = -1; ictx->last = -1;

2
tmux.h
View File

@ -1249,7 +1249,7 @@ struct tty {
#define TTY_FOCUS 0x40 #define TTY_FOCUS 0x40
#define TTY_BLOCK 0x80 #define TTY_BLOCK 0x80
#define TTY_HAVEDA 0x100 #define TTY_HAVEDA 0x100
#define TTY_HAVEDSR 0x200 #define TTY_HAVEXDA 0x200
#define TTY_SYNCING 0x400 #define TTY_SYNCING 0x400
int flags; int flags;

View File

@ -33,7 +33,7 @@
* - alternate escape (under XT). * - alternate escape (under XT).
* *
* Also: * Also:
* - XT is used to decide whether to send DA and DSR; * - XT is used to decide whether to send DA and XDA;
* - DECSLRM and DECFRA use a flag instead of capabilities; * - DECSLRM and DECFRA use a flag instead of capabilities;
* - UTF-8 is a separate flag on the client; needed for unattached clients. * - UTF-8 is a separate flag on the client; needed for unattached clients.
*/ */

View File

@ -52,7 +52,7 @@ 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 *, static int tty_keys_extended_device_attributes(struct tty *, const char *,
size_t, size_t *); size_t, size_t *);
/* Default raw keys. */ /* Default raw keys. */
@ -612,8 +612,8 @@ tty_keys_next(struct tty *tty)
goto partial_key; goto partial_key;
} }
/* Is this a device status report response? */ /* Is this an extended device attributes response? */
switch (tty_keys_device_status_report(tty, buf, len, &size)) { switch (tty_keys_extended_device_attributes(tty, buf, len, &size)) {
case 0: /* yes */ case 0: /* yes */
key = KEYC_UNKNOWN; key = KEYC_UNKNOWN;
goto complete_key; goto complete_key;
@ -936,7 +936,7 @@ tty_keys_clipboard(__unused struct tty *tty, const char *buf, size_t len,
*size = 0; *size = 0;
/* First three bytes are always \033]52;. */ /* First five bytes are always \033]52;. */
if (buf[0] != '\033') if (buf[0] != '\033')
return (-1); return (-1);
if (len == 1) if (len == 1)
@ -1040,9 +1040,11 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
return (1); return (1);
/* Copy the rest up to a 'c'. */ /* Copy the rest up to a 'c'. */
for (i = 0; i < (sizeof tmp) - 1 && buf[3 + i] != 'c'; i++) { for (i = 0; i < (sizeof tmp) - 1; i++) {
if (3 + i == len) if (3 + i == len)
return (1); return (1);
if (buf[3 + i] == 'c')
break;
tmp[i] = buf[3 + i]; tmp[i] = buf[3 + i];
} }
if (i == (sizeof tmp) - 1) if (i == (sizeof tmp) - 1)
@ -1101,48 +1103,54 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
} }
/* /*
* Handle device status report input. Returns 0 for success, -1 for failure, 1 * Handle extended device attributes input. Returns 0 for success, -1 for
* for partial. * failure, 1 for partial.
*/ */
static int static int
tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len, tty_keys_extended_device_attributes(struct tty *tty, const char *buf,
size_t *size) size_t len, size_t *size)
{ {
struct client *c = tty->client; struct client *c = tty->client;
u_int i; u_int i;
char tmp[64]; char tmp[64];
*size = 0; *size = 0;
if (tty->flags & TTY_HAVEDSR) if (tty->flags & TTY_HAVEXDA)
return (-1); return (-1);
/* First three bytes are always \033[. */ /* First four bytes are always \033P>|. */
if (buf[0] != '\033') if (buf[0] != '\033')
return (-1); return (-1);
if (len == 1) if (len == 1)
return (1); return (1);
if (buf[1] != '[') if (buf[1] != 'P')
return (-1); return (-1);
if (len == 2) if (len == 2)
return (1); return (1);
if (buf[2] != 'I' && buf[2] != 'T') if (buf[2] != '>')
return (-1); return (-1);
if (len == 3) if (len == 3)
return (1); return (1);
if (buf[3] != '|')
return (-1);
if (len == 4)
return (1);
/* Copy the rest up to a 'n'. */ /* Copy the rest up to a '\033\\'. */
for (i = 0; i < (sizeof tmp) - 1 && buf[2 + i] != 'n'; i++) { for (i = 0; i < (sizeof tmp) - 1; i++) {
if (2 + i == len) if (4 + i == len)
return (1); return (1);
tmp[i] = buf[2 + i]; if (buf[4 + i - 1] == '\033' && buf[4 + i] == '\\')
break;
tmp[i] = buf[4 + i];
} }
if (i == (sizeof tmp) - 1) if (i == (sizeof tmp) - 1)
return (-1); return (-1);
tmp[i] = '\0'; tmp[i - 1] = '\0';
*size = 3 + i; *size = 5 + i;
/* Add terminal features. */ /* Add terminal features. */
if (strncmp(tmp, "ITERM2 ", 7) == 0) { if (strncmp(tmp, "ITerm2 ", 7) == 0) {
tty_add_features(&c->term_features, tty_add_features(&c->term_features,
"256," "256,"
"RGB," "RGB,"
@ -1152,7 +1160,7 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len,
"sync," "sync,"
"title", "title",
","); ",");
} else if (strncmp(tmp, "TMUX ", 5) == 0) { } else if (strncmp(tmp, "tmux ", 5) == 0) {
tty_add_features(&c->term_features, tty_add_features(&c->term_features,
"256," "256,"
"RGB," "RGB,"
@ -1163,10 +1171,10 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len,
"usstyle", "usstyle",
","); ",");
} }
log_debug("%s: received DSR %.*s", c->name, (int)*size, buf); log_debug("%s: received extended DA %.*s", c->name, (int)*size, buf);
tty_update_features(tty); tty_update_features(tty);
tty->flags |= TTY_HAVEDSR; tty->flags |= TTY_HAVEXDA;
return (0); return (0);
} }

8
tty.c
View File

@ -287,7 +287,7 @@ tty_start_timer_callback(__unused int fd, __unused short events, void *data)
struct client *c = tty->client; struct client *c = tty->client;
log_debug("%s: start timer fired", c->name); log_debug("%s: start timer fired", c->name);
tty->flags |= (TTY_HAVEDA|TTY_HAVEDSR); tty->flags |= (TTY_HAVEDA|TTY_HAVEXDA);
} }
void void
@ -361,10 +361,10 @@ tty_send_requests(struct tty *tty)
if (tty_term_flag(tty->term, TTYC_XT)) { if (tty_term_flag(tty->term, TTYC_XT)) {
if (~tty->flags & TTY_HAVEDA) if (~tty->flags & TTY_HAVEDA)
tty_puts(tty, "\033[>c"); tty_puts(tty, "\033[>c");
if (~tty->flags & TTY_HAVEDSR) if (~tty->flags & TTY_HAVEXDA)
tty_puts(tty, "\033[1337n"); tty_puts(tty, "\033[>q");
} else } else
tty->flags |= (TTY_HAVEDA|TTY_HAVEDSR); tty->flags |= (TTY_HAVEDA|TTY_HAVEXDA);
} }
void void