version 1.127, 2020/04/20 14:59:31 |
version 1.128, 2020/05/16 14:16:25 |
|
|
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. */ |
|
|
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; |
|
|
|
|
*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) |
|
|
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) |
|
|
} |
} |
|
|
/* |
/* |
* 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," |
|
|
"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," |
|
|
"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); |
} |
} |