Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/man/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -4190,6 +4190,13 @@ For example:
.nf
autodetect_codeset=russian
.fi
.TP
.I kitty_keyboard_protocol
By default, Midnight Commander sends an escape sequence that enables the Kitty
Keyboard Protocol, which allows precise keyboard handling (including key
combinations such as C-Enter or C-Alt-Enter) when connected from terminals that
support this protocol. If set to false, Midnight Commander will not attempt to
enable this protocol.
.\"NODE "Parameters for external editor or viewer"
.SH "Parameters for external editor or viewer"
Midnight Commander provides a way for specify an options for external editors
Expand Down
3 changes: 2 additions & 1 deletion lib/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ mc_global_t mc_global =
.disable_colors = FALSE,
.ugly_line_drawing = FALSE,
.old_mouse = FALSE,
.alternate_plus_minus = FALSE
.alternate_plus_minus = FALSE,
.kitty_keyboard_protocol = TRUE
},

.vfs =
Expand Down
4 changes: 4 additions & 0 deletions lib/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ typedef struct
/* If true, use + and \ keys normally and select/unselect do if M-+ / M-\.
and M-- and keypad + / - */
gboolean alternate_plus_minus;

// If true, send Kitty Keyboard Protocol initialization string to the terminal
// Defaults to true, because terminals that don't support it simply do nothing
gboolean kitty_keyboard_protocol;
} tty;

struct
Expand Down
296 changes: 209 additions & 87 deletions lib/tty/key.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/tty/tty-ncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ tty_init (gboolean mouse_enable, gboolean is_xterm)
noecho ();
keypad (stdscr, TRUE);
nodelay (stdscr, FALSE);
tty_kitty (TRUE);

tty_setup_sigwinch (sigwinch_handler);
}
Expand All @@ -273,6 +274,7 @@ void
tty_shutdown (void)
{
tty_destroy_winch_pipe ();
tty_kitty (FALSE);
tty_reset_shell_mode ();
tty_noraw_mode ();
tty_keypad (FALSE);
Expand Down
2 changes: 2 additions & 0 deletions lib/tty/tty-slang.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ tty_init (gboolean mouse_enable, gboolean is_xterm)
tty_enter_ca_mode ();
tty_keypad (TRUE);
tty_nodelay (FALSE);
tty_kitty (TRUE);

tty_setup_sigwinch (sigwinch_handler);
}
Expand All @@ -346,6 +347,7 @@ tty_shutdown (void)
char *op_cap;

tty_destroy_winch_pipe ();
tty_kitty (FALSE);
tty_reset_shell_mode ();
tty_noraw_mode ();
tty_keypad (FALSE);
Expand Down
21 changes: 21 additions & 0 deletions lib/tty/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,24 @@ tty_init_xterm_support (gboolean is_xterm)
}

/* --------------------------------------------------------------------------------------------- */

/** Enable or disable Kitty Keyboard Protocol */
void
tty_kitty (gboolean set)
{
if (!mc_global.tty.kitty_keyboard_protocol)
return;

if (set)
{
// 1 = Disambiguate escape codes
// 4 = Report alternate keys (required for detecting Ctrl+Alt+key)
// 8 = Report all keys as escape codes (required for distinguishing keypad keys [+-*])
SLtt_write_string ((char*) ESC_STR "[>13u");
}
else
SLtt_write_string ((char*) ESC_STR "[<u");
}

/* --------------------------------------------------------------------------------------------- */

1 change: 1 addition & 0 deletions lib/tty/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ extern int tty_flush_input (void);
extern void tty_keypad (gboolean set);
extern void tty_nodelay (gboolean set);
extern int tty_baudrate (void);
extern void tty_kitty (gboolean set);

/* {{{ Output }}} */

Expand Down
4 changes: 4 additions & 0 deletions src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ edition_post_exec (void)
tty_flush_input ();

tty_keypad (TRUE);
tty_kitty (TRUE);
tty_raw_mode ();
channels_up ();
enable_mouse ();
Expand All @@ -113,6 +114,7 @@ edition_pre_exec (void)
disable_bracketed_paste ();

tty_reset_shell_mode ();
tty_kitty (FALSE);
tty_keypad (FALSE);
tty_reset_screen ();

Expand Down Expand Up @@ -485,6 +487,7 @@ toggle_subshell (void)
tty_reset_shell_mode ();
#endif
tty_noecho ();
tty_kitty (FALSE);
tty_keypad (FALSE);
tty_reset_screen ();
tty_exit_ca_mode ();
Expand Down Expand Up @@ -521,6 +524,7 @@ toggle_subshell (void)

tty_reset_prog_mode ();
tty_keypad (TRUE);
tty_kitty (TRUE);

/* Prevent screen flash when user did 'exit' or 'logout' within
subshell */
Expand Down
1 change: 1 addition & 0 deletions src/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ static const struct
#ifdef ENABLE_EXT2FS_ATTR
{ "copymove_persistent_ext2_attr", &copymove_persistent_ext2_attr },
#endif
{ "kitty_keyboard_protocol", &mc_global.tty.kitty_keyboard_protocol },
{
NULL,
NULL,
Expand Down