From 9c40f7264338ab1a41dfc603db6b0412b3d7bf51 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 16 Jan 2025 13:23:29 +0100 Subject: [PATCH] Add feature flag for turning off keyboard protocols To work around terminal bugs. The flag "keyboard-protocols" defaults to "on" and enables keyboard protocols, but can be turned off by setting "no-keyboard-protocols". This has downsides as a feature flag - if you use multiple terminals and one of them can't do it you'll have to disable it in all, but anything else would require us to hook this up to env-dispatch, and ensure that we turn the protocols *off* when the flag is disabled. Since this is a temporary inconvenience, this would be okay to ask zellij and Jetbrains-with-WSL users. --- doc_src/language.rst | 4 ++++ src/future_feature_flags.rs | 12 ++++++++++++ src/input_common.rs | 9 +++++++-- tests/checks/status.fish | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc_src/language.rst b/doc_src/language.rst index 2cb414c0e..898b847d3 100644 --- a/doc_src/language.rst +++ b/doc_src/language.rst @@ -2024,6 +2024,7 @@ You can see the current list of features via ``status features``:: ampersand-nobg-in-token on 3.4 & only backgrounds if followed by a separating character remove-percent-self off 4.0 %self is no longer expanded (use $fish_pid) test-require-arg off 4.0 builtin test requires an argument + keyboard-protocols on 4.0 Use keyboard protocols (kitty, xterm's modifyotherkeys Here is what they mean: @@ -2033,6 +2034,9 @@ Here is what they mean: - ``ampersand-nobg-in-token`` was introduced in fish 3.4 (and made the default in 3.5). It makes it so a ``&`` i no longer interpreted as the backgrounding operator in the middle of a token, so dealing with URLs becomes easier. Either put spaces or a semicolon after the ``&``. This is recommended formatting anyway, and ``fish_indent`` will have done it for you already. - ``remove-percent-self`` turns off the special ``%self`` expansion. It was introduced in 4.0. To get fish's pid, you can use the :envvar:`fish_pid` variable. - ``test-require-arg`` removes :doc:`builtin test `'s one-argument form (``test "string"``. It was introduced in 4.0. To test if a string is non-empty, use ``test -n "string"``. If disabled, any call to ``test`` that would change sends a :ref:`debug message ` of category "deprecated-test", so starting fish with ``fish --debug=deprecated-test`` can be used to find offending calls. +- ``keyboard-protocols`` lets fish turn on various keyboard protocols including the kitty keyboard protocol. + It was introduced in 4.0 and is on by default. + Disable it with ``no-keyboard-protocols`` to work around bugs in your terminal. These changes are introduced off by default. They can be enabled on a per session basis:: diff --git a/src/future_feature_flags.rs b/src/future_feature_flags.rs index 503da62bd..38000e38a 100644 --- a/src/future_feature_flags.rs +++ b/src/future_feature_flags.rs @@ -27,6 +27,9 @@ pub enum FeatureFlag { /// Remove `test`'s one and zero arg mode (make `test -n` return false etc) test_require_arg, + + /// Whether keyboard protocols (kitty's CSI x u, xterm's modifyOtherKeys) are used + keyboard_protocols, } struct Features { @@ -107,6 +110,14 @@ pub const METADATA: &[FeatureMetadata] = &[ default_value: false, read_only: false, }, + FeatureMetadata { + flag: FeatureFlag::keyboard_protocols, + name: L!("keyboard-protocols"), + groups: L!("4.0"), + description: L!("Use keyboard protocols (kitty, xterm's modifyotherkeys"), + default_value: true, + read_only: false, + }, ]; thread_local!( @@ -168,6 +179,7 @@ impl Features { AtomicBool::new(METADATA[3].default_value), AtomicBool::new(METADATA[4].default_value), AtomicBool::new(METADATA[5].default_value), + AtomicBool::new(METADATA[6].default_value), ], } } diff --git a/src/input_common.rs b/src/input_common.rs index d8befb2a3..ddac41b1e 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -8,6 +8,7 @@ use crate::env::{EnvStack, Environment}; use crate::fd_readable_set::FdReadableSet; use crate::flog::FLOG; use crate::fork_exec::flog_safe::FLOG_SAFE; +use crate::future_feature_flags::{feature_test, FeatureFlag}; use crate::global_safety::RelaxedAtomicBool; use crate::key::{ self, alt, canonicalize_control_char, canonicalize_keyed_control_char, function_key, shift, @@ -482,7 +483,9 @@ pub fn terminal_protocols_enable_ifn() { return; } TERMINAL_PROTOCOLS.store(true, Ordering::Release); - let sequences = if IN_MIDNIGHT_COMMANDER_PRE_CSI_U.load() { + let sequences = if !feature_test(FeatureFlag::keyboard_protocols) + || IN_MIDNIGHT_COMMANDER_PRE_CSI_U.load() + { "\x1b[?2004h" } else if IN_ITERM_PRE_CSI_U.load() { concat!("\x1b[?2004h", "\x1b[>4;1m", "\x1b[>5u", "\x1b=",) @@ -516,7 +519,9 @@ pub(crate) fn terminal_protocols_disable_ifn() { if !TERMINAL_PROTOCOLS.load(Ordering::Acquire) { return; } - let sequences = if IN_ITERM_PRE_CSI_U.load() { + let sequences = if !feature_test(FeatureFlag::keyboard_protocols) { + "\x1b[?2004l" + } else if IN_ITERM_PRE_CSI_U.load() { concat!("\x1b[?2004l", "\x1b[>4;0m", "\x1b[<1u", "\x1b>",) } else if IN_JETBRAINS.load() { concat!("\x1b[?2004l", "\x1b[>4;0m", "\x1b>",) diff --git a/tests/checks/status.fish b/tests/checks/status.fish index 3b2973268..d861611fc 100644 --- a/tests/checks/status.fish +++ b/tests/checks/status.fish @@ -59,6 +59,7 @@ status features #CHECK: ampersand-nobg-in-token on 3.4 & only backgrounds if followed by a separator #CHECK: remove-percent-self off 4.0 %self is no longer expanded (use $fish_pid) #CHECK: test-require-arg off 4.0 builtin test requires an argument +#CHECK: keyboard-protocols on 4.0 Use keyboard protocols (kitty, xterm's modifyotherkeys status test-feature stderr-nocaret echo $status #CHECK: 0