Unnamed repository; edit this file 'description' to name the repository.
feat(helix-tui): add configuration to manually enable/disable KKP (#14398)
| -rw-r--r-- | book/src/editor.md | 1 | ||||
| -rw-r--r-- | helix-tui/src/backend/termina.rs | 14 | ||||
| -rw-r--r-- | helix-tui/src/terminal.rs | 4 | ||||
| -rw-r--r-- | helix-view/src/editor.rs | 12 |
4 files changed, 27 insertions, 4 deletions
diff --git a/book/src/editor.md b/book/src/editor.md index b5544a06..ee3aab6a 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -64,6 +64,7 @@ | `clipboard-provider` | Which API to use for clipboard interaction. One of `pasteboard` (MacOS), `wayland`, `x-clip`, `x-sel`, `win-32-yank`, `termux`, `tmux`, `windows`, `termcode`, `none`, or a custom command set. | Platform and environment specific. | | `editor-config` | Whether to read settings from [EditorConfig](https://editorconfig.org) files | `true` | | `rainbow-brackets` | Whether to render rainbow colors for matching brackets. Requires tree-sitter `rainbows.scm` queries for the language. | `false` | +| `kitty-keyboard-protocol` | Whether to enable Kitty Keyboard Protocol. Can be `enabled`, `disabled` or `auto` | `auto` | ### `[editor.clipboard-provider]` Section diff --git a/helix-tui/src/backend/termina.rs b/helix-tui/src/backend/termina.rs index 8c6844d9..f0beb848 100644 --- a/helix-tui/src/backend/termina.rs +++ b/helix-tui/src/backend/termina.rs @@ -1,6 +1,7 @@ use std::io::{self, Write as _}; use helix_view::{ + editor::KittyKeyboardProtocolConfig, graphics::{CursorKind, Rect, UnderlineStyle}, theme::{Color, Modifier}, }; @@ -147,6 +148,15 @@ impl TerminaBackend { let mut capabilities = Capabilities::default(); let start = Instant::now(); + capabilities.kitty_keyboard = match config.kitty_keyboard_protocol { + KittyKeyboardProtocolConfig::Disabled => KittyKeyboardSupport::None, + KittyKeyboardProtocolConfig::Enabled => KittyKeyboardSupport::Full, + KittyKeyboardProtocolConfig::Auto => { + write!(terminal, "{}", Csi::Keyboard(csi::Keyboard::QueryFlags))?; + KittyKeyboardSupport::None + } + }; + // Many terminal extensions can be detected by querying the terminal for the state of the // extension and then sending a request for the primary device attributes (which is // consistently supported by all terminals). If we receive the status of the feature (for @@ -154,9 +164,7 @@ impl TerminaBackend { // If we only receive the device attributes then we know it is not. write!( terminal, - "{}{}{}{}{}{}{}", - // Kitty keyboard - Csi::Keyboard(csi::Keyboard::QueryFlags), + "{}{}{}{}{}{}", // Synchronized output Csi::Mode(csi::Mode::QueryDecPrivateMode(csi::DecPrivateMode::Code( csi::DecPrivateModeCode::SynchronizedOutput diff --git a/helix-tui/src/terminal.rs b/helix-tui/src/terminal.rs index 0b038fdf..72f38d71 100644 --- a/helix-tui/src/terminal.rs +++ b/helix-tui/src/terminal.rs @@ -2,7 +2,7 @@ //! Frontend for [Backend] use crate::{backend::Backend, buffer::Buffer}; -use helix_view::editor::Config as EditorConfig; +use helix_view::editor::{Config as EditorConfig, KittyKeyboardProtocolConfig}; use helix_view::graphics::{CursorKind, Rect}; use std::io; @@ -25,6 +25,7 @@ pub struct Viewport { pub struct Config { pub enable_mouse_capture: bool, pub force_enable_extended_underlines: bool, + pub kitty_keyboard_protocol: KittyKeyboardProtocolConfig, } impl From<&EditorConfig> for Config { @@ -32,6 +33,7 @@ impl From<&EditorConfig> for Config { Self { enable_mouse_capture: config.mouse, force_enable_extended_underlines: config.undercurl, + kitty_keyboard_protocol: config.kitty_keyboard_protocol, } } } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index cd8560e0..162d2b1f 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -381,6 +381,17 @@ pub struct Config { pub editor_config: bool, /// Whether to render rainbow colors for matching brackets. Defaults to `false`. pub rainbow_brackets: bool, + /// Whether to enable Kitty Keyboard Protocol + pub kitty_keyboard_protocol: KittyKeyboardProtocolConfig, +} + +#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize, Clone, Copy)] +#[serde(rename_all = "kebab-case")] +pub enum KittyKeyboardProtocolConfig { + #[default] + Auto, + Disabled, + Enabled, } #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)] @@ -1061,6 +1072,7 @@ impl Default for Config { clipboard_provider: ClipboardProvider::default(), editor_config: true, rainbow_brackets: false, + kitty_keyboard_protocol: Default::default(), } } } |