File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4190,6 +4190,13 @@ For example:
41904190.nf
41914191autodetect_codeset=russian
41924192.fi
4193+ .TP
4194+ .I kitty_keyboard_protocol
4195+ By default, Midnight Commander sends an escape sequence that enables the Kitty
4196+ Keyboard Protocol, which allows precise keyboard handling (including key
4197+ combinations such as C-Enter or C-Alt-Enter) when connected from terminals that
4198+ support this protocol. If set to false, Midnight Commander will not attempt to
4199+ enable this protocol.
41934200.\" NODE "Parameters for external editor or viewer"
41944201.SH "Parameters for external editor or viewer"
41954202Midnight Commander provides a way for specify an options for external editors
Original file line number Diff line number Diff line change @@ -103,7 +103,8 @@ mc_global_t mc_global =
103103 .disable_colors = FALSE,
104104 .ugly_line_drawing = FALSE,
105105 .old_mouse = FALSE,
106- .alternate_plus_minus = FALSE
106+ .alternate_plus_minus = FALSE,
107+ .kitty_keyboard_protocol = TRUE
107108 },
108109
109110 .vfs =
Original file line number Diff line number Diff line change @@ -206,6 +206,10 @@ typedef struct
206206 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\.
207207 and M-- and keypad + / - */
208208 gboolean alternate_plus_minus ;
209+
210+ // If true, send Kitty Keyboard Protocol initialization string to the terminal
211+ // Defaults to true, because terminals that don't support it simply do nothing
212+ gboolean kitty_keyboard_protocol ;
209213 } tty ;
210214
211215 struct
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -263,6 +263,7 @@ tty_init (gboolean mouse_enable, gboolean is_xterm)
263263 noecho ();
264264 keypad (stdscr , TRUE);
265265 nodelay (stdscr , FALSE);
266+ tty_kitty (TRUE);
266267
267268 tty_setup_sigwinch (sigwinch_handler );
268269}
273274tty_shutdown (void )
274275{
275276 tty_destroy_winch_pipe ();
277+ tty_kitty (FALSE);
276278 tty_reset_shell_mode ();
277279 tty_noraw_mode ();
278280 tty_keypad (FALSE);
Original file line number Diff line number Diff line change @@ -334,6 +334,7 @@ tty_init (gboolean mouse_enable, gboolean is_xterm)
334334 tty_enter_ca_mode ();
335335 tty_keypad (TRUE);
336336 tty_nodelay (FALSE);
337+ tty_kitty (TRUE);
337338
338339 tty_setup_sigwinch (sigwinch_handler );
339340}
@@ -346,6 +347,7 @@ tty_shutdown (void)
346347 char * op_cap ;
347348
348349 tty_destroy_winch_pipe ();
350+ tty_kitty (FALSE);
349351 tty_reset_shell_mode ();
350352 tty_noraw_mode ();
351353 tty_keypad (FALSE);
Original file line number Diff line number Diff line change @@ -426,3 +426,24 @@ tty_init_xterm_support (gboolean is_xterm)
426426}
427427
428428/* --------------------------------------------------------------------------------------------- */
429+
430+ /** Enable or disable Kitty Keyboard Protocol */
431+ void
432+ tty_kitty (gboolean set )
433+ {
434+ if (!mc_global .tty .kitty_keyboard_protocol )
435+ return ;
436+
437+ if (set )
438+ {
439+ // 1 = Disambiguate escape codes
440+ // 4 = Report alternate keys (required for detecting Ctrl+Alt+key)
441+ // 8 = Report all keys as escape codes (required for distinguishing keypad keys [+-*])
442+ SLtt_write_string ((char * ) ESC_STR "[>13u" );
443+ }
444+ else
445+ SLtt_write_string ((char * ) ESC_STR "[<u" );
446+ }
447+
448+ /* --------------------------------------------------------------------------------------------- */
449+
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ extern int tty_flush_input (void);
9595extern void tty_keypad (gboolean set );
9696extern void tty_nodelay (gboolean set );
9797extern int tty_baudrate (void );
98+ extern void tty_kitty (gboolean set );
9899
99100/* {{{ Output }}} */
100101
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ edition_post_exec (void)
8787 tty_flush_input ();
8888
8989 tty_keypad (TRUE);
90+ tty_kitty (TRUE);
9091 tty_raw_mode ();
9192 channels_up ();
9293 enable_mouse ();
@@ -113,6 +114,7 @@ edition_pre_exec (void)
113114 disable_bracketed_paste ();
114115
115116 tty_reset_shell_mode ();
117+ tty_kitty (FALSE);
116118 tty_keypad (FALSE);
117119 tty_reset_screen ();
118120
@@ -485,6 +487,7 @@ toggle_subshell (void)
485487 tty_reset_shell_mode ();
486488#endif
487489 tty_noecho ();
490+ tty_kitty (FALSE);
488491 tty_keypad (FALSE);
489492 tty_reset_screen ();
490493 tty_exit_ca_mode ();
@@ -521,6 +524,7 @@ toggle_subshell (void)
521524
522525 tty_reset_prog_mode ();
523526 tty_keypad (TRUE);
527+ tty_kitty (TRUE);
524528
525529 /* Prevent screen flash when user did 'exit' or 'logout' within
526530 subshell */
Original file line number Diff line number Diff line change @@ -367,6 +367,7 @@ static const struct
367367#ifdef ENABLE_EXT2FS_ATTR
368368 { "copymove_persistent_ext2_attr" , & copymove_persistent_ext2_attr },
369369#endif
370+ { "kitty_keyboard_protocol" , & mc_global .tty .kitty_keyboard_protocol },
370371 {
371372 NULL ,
372373 NULL ,
You can’t perform that action at this time.
0 commit comments