Skip to content

Commit

Permalink
Add a terminal feature for enable/disable extended keys (supported by
Browse files Browse the repository at this point in the history
xterm and mintty) and add an option to make tmux send it. Only forward
extended keys if the application has requested them, even though we use
the CSI u sequence and xterm uses CSI 27 ~ - this is what mintty does as
well.
  • Loading branch information
nicm committed May 16, 2020
1 parent 292b335 commit 0ab82d9
Show file tree
Hide file tree
Showing 8 changed files with 809 additions and 336 deletions.
571 changes: 425 additions & 146 deletions input-keys.c

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion input.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ enum input_csi_type {
INPUT_CSI_HPA,
INPUT_CSI_ICH,
INPUT_CSI_IL,
INPUT_CSI_MODOFF,
INPUT_CSI_MODSET,
INPUT_CSI_RCP,
INPUT_CSI_REP,
INPUT_CSI_RM,
Expand Down Expand Up @@ -289,7 +291,9 @@ static const struct input_table_entry input_csi_table[] = {
{ 'l', "", INPUT_CSI_RM },
{ 'l', "?", INPUT_CSI_RM_PRIVATE },
{ 'm', "", INPUT_CSI_SGR },
{ 'm', ">", INPUT_CSI_MODSET },
{ 'n', "", INPUT_CSI_DSR },
{ 'n', ">", INPUT_CSI_MODOFF },
{ 'q', " ", INPUT_CSI_DECSCUSR },
{ 'q', ">", INPUT_CSI_XDA },
{ 'r', "", INPUT_CSI_DECSTBM },
Expand Down Expand Up @@ -1380,6 +1384,19 @@ input_csi_dispatch(struct input_ctx *ictx)
if (n != -1 && m != -1)
screen_write_cursormove(sctx, m - 1, n - 1, 1);
break;
case INPUT_CSI_MODSET:
n = input_get(ictx, 0, 0, 0);
m = input_get(ictx, 1, 0, 0);
if (n == 0 || (n == 4 && m == 0))
screen_write_mode_clear(sctx, MODE_KEXTENDED);
else if (n == 4 && (m == 1 || m == 2))
screen_write_mode_set(sctx, MODE_KEXTENDED);
break;
case INPUT_CSI_MODOFF:
n = input_get(ictx, 0, 0, 0);
if (n == 4)
screen_write_mode_clear(sctx, MODE_KEXTENDED);
break;
case INPUT_CSI_WINOPS:
input_csi_dispatch_winops(ictx);
break;
Expand Down Expand Up @@ -1593,7 +1610,7 @@ input_csi_dispatch(struct input_ctx *ictx)
break;
case INPUT_CSI_XDA:
n = input_get(ictx, 0, 0, 0);
if (n != 0)
if (n == 0)
input_reply(ictx, "\033P>|tmux %s\033\\", getversion());
break;

Expand Down
13 changes: 11 additions & 2 deletions options-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ const struct options_table_entry options_table[] = {
"clients."
},

{ .name = "extended-keys",
.type = OPTIONS_TABLE_FLAG,
.scope = OPTIONS_TABLE_SERVER,
.default_num = 0,
.text = "Whether to request extended key sequences from terminals "
"that support it."
},

{ .name = "focus-events",
.type = OPTIONS_TABLE_FLAG,
.scope = OPTIONS_TABLE_SERVER,
Expand Down Expand Up @@ -1053,11 +1061,12 @@ const struct options_table_entry options_table[] = {
"bottom."
},

{ .name = "xterm-keys",
{ .name = "xterm-keys", /* no longer used */
.type = OPTIONS_TABLE_FLAG,
.scope = OPTIONS_TABLE_WINDOW,
.default_num = 1,
.text = "Whether xterm-style function key sequences should be sent."
.text = "Whether xterm-style function key sequences should be sent. "
"This option is no longer used."
},

/* Hook options. */
Expand Down
18 changes: 8 additions & 10 deletions tmux.1
Original file line number Diff line number Diff line change
Expand Up @@ -3225,6 +3225,12 @@ sessions.
.Op Ic on | off
.Xc
If enabled, the server will exit when there are no attached clients.
.It Xo Ic extended-keys
.Op Ic on | off
.Xc
When enabled, extended keys are requested from the terminal and if supported
are recognised by
.Nm .
.It Xo Ic focus-events
.Op Ic on | off
.Xc
Expand Down Expand Up @@ -4054,16 +4060,6 @@ option.
.Xc
If this option is set, searches will wrap around the end of the pane contents.
The default is on.
.Pp
.It Xo Ic xterm-keys
.Op Ic on | off
.Xc
If this option is set,
.Nm
will generate
.Xr xterm 1 -style
function key sequences; these have a number included to indicate modifiers such
as Shift, Alt or Ctrl.
.El
.Pp
Available pane options are:
Expand Down Expand Up @@ -5754,6 +5750,8 @@ Disable and enable bracketed paste.
These are set automatically if the
.Em XT
capability is present.
.It Em \&Dseks , \&Eneks
Disable and enable extended keys.
.It Em \&Dsfcs , \&Enfcs
Disable and enable focus reporting.
These are set automatically if the
Expand Down
17 changes: 15 additions & 2 deletions tty-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ static const struct tty_feature tty_feature_sync = {
0
};

/* Terminal supports extended keys. */
static const char *tty_feature_extkeys_capabilities[] = {
"Eneks=\\E[>4;1m",
"Dseks=\\E[>4m",
NULL
};
static const struct tty_feature tty_feature_extkeys = {
"extkeys",
tty_feature_extkeys_capabilities,
0
};

/* Terminal supports DECSLRM margins. */
static const char *tty_feature_margins_capabilities[] = {
"Enmg=\\E[?69h",
Expand Down Expand Up @@ -218,6 +230,7 @@ static const struct tty_feature *tty_features[] = {
&tty_feature_ccolour,
&tty_feature_clipboard,
&tty_feature_cstyle,
&tty_feature_extkeys,
&tty_feature_focus,
&tty_feature_margins,
&tty_feature_overline,
Expand Down Expand Up @@ -321,7 +334,7 @@ tty_default_features(int *feat, const char *name, u_int version)
} table[] = {
#define TTY_FEATURES_BASE_MODERN_XTERM "256,RGB,bpaste,clipboard,strikethrough,title"
{ .name = "mintty",
.features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,margins,overline"
.features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,extkeys,margins,overline"
},
{ .name = "tmux",
.features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,focus,overline,usstyle"
Expand All @@ -333,7 +346,7 @@ tty_default_features(int *feat, const char *name, u_int version)
.features = TTY_FEATURES_BASE_MODERN_XTERM ",cstyle,margins,sync"
},
{ .name = "XTerm",
.features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,focus,margins,rectfill"
.features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,extkeys,focus,margins,rectfill"
}
};
u_int i;
Expand Down
Loading

0 comments on commit 0ab82d9

Please sign in to comment.