From ac88209f54120288b334f9750d54f0e17b3b6482 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Tue, 7 Nov 2023 00:36:00 +0100
Subject: [PATCH 01/11] Properly handle optional event modes

Both bracketed paste and the kitty keyboard enhancement flag are not
always supported.
This goes both for terminals that may not emit events according to their
spec and also applications that will run in the terminal independent of
reedline.

Make sure we enter the mode when starting to take control and exit the
mode when leaving the mode or being dropped.
The settings exposed to the user will just internally enable a setting
(in the case of the kitty keyboard enhancement flags crossterm provides
and easy way to check for support that we take into account with that)
---
 src/engine.rs                              | 72 +++++-----------------
 src/lib.rs                                 |  2 +
 src/terminal_extensions/bracketed_paste.rs | 37 +++++++++++
 src/terminal_extensions/kitty.rs           | 52 ++++++++++++++++
 src/terminal_extensions/mod.rs             |  2 +
 5 files changed, 110 insertions(+), 55 deletions(-)
 create mode 100644 src/terminal_extensions/bracketed_paste.rs
 create mode 100644 src/terminal_extensions/kitty.rs
 create mode 100644 src/terminal_extensions/mod.rs

diff --git a/src/engine.rs b/src/engine.rs
index 29d14810..859b1d34 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -1,7 +1,5 @@
 use std::path::PathBuf;
 
-use crossterm::event::{DisableBracketedPaste, EnableBracketedPaste};
-use crossterm::execute;
 use itertools::Itertools;
 
 use crate::{enums::ReedlineRawEvent, CursorConfig};
@@ -31,6 +29,7 @@ use {
         painting::{Painter, PromptLines},
         prompt::{PromptEditMode, PromptHistorySearchStatus},
         result::{ReedlineError, ReedlineErrorVariants},
+        terminal_extensions::{bracketed_paste::BracketedPasteGuard, kitty::KittyProtocolGuard},
         utils::text_manipulation,
         EditCommand, ExampleHighlighter, Highlighter, LineBuffer, Menu, MenuEvent, Prompt,
         PromptHistorySearch, ReedlineMenu, Signal, UndoBehavior, ValidationResult, Validator,
@@ -144,11 +143,11 @@ pub struct Reedline {
     // Use different cursors depending on the current edit mode
     cursor_shapes: Option<CursorConfig>,
 
-    // Indicate if global terminal have enabled BracketedPaste
-    bracket_paste_enabled: bool,
+    // Manage bracketed paste mode
+    bracketed_paste: BracketedPasteGuard,
 
-    // Use kitty protocol to handle escape code input or not
-    use_kitty_protocol: bool,
+    // Manage optional kitty protocol
+    kitty_protocol: KittyProtocolGuard,
 
     #[cfg(feature = "external_printer")]
     external_printer: Option<ExternalPrinter<String>>,
@@ -172,12 +171,6 @@ impl Drop for Reedline {
         // Ensures that the terminal is in a good state if we panic semigracefully
         // Calling `disable_raw_mode()` twice is fine with Linux
         let _ignore = terminal::disable_raw_mode();
-        if self.bracket_paste_enabled {
-            let _ = execute!(io::stdout(), DisableBracketedPaste);
-        }
-        if self.use_kitty_protocol {
-            let _ = execute!(io::stdout(), event::PopKeyboardEnhancementFlags);
-        }
     }
 }
 
@@ -223,8 +216,8 @@ impl Reedline {
             menus: Vec::new(),
             buffer_editor: None,
             cursor_shapes: None,
-            bracket_paste_enabled: false,
-            use_kitty_protocol: false,
+            bracketed_paste: BracketedPasteGuard::default(),
+            kitty_protocol: KittyProtocolGuard::default(),
             #[cfg(feature = "external_printer")]
             external_printer: None,
         }
@@ -242,20 +235,14 @@ impl Reedline {
 
     /// Enable BracketedPaste feature.
     pub fn enable_bracketed_paste(&mut self) -> Result<()> {
-        let res = execute!(io::stdout(), EnableBracketedPaste);
-        if res.is_ok() {
-            self.bracket_paste_enabled = true;
-        }
-        res
+        self.bracketed_paste.set(true);
+        Ok(())
     }
 
     /// Disable BracketedPaste feature.
     pub fn disable_bracketed_paste(&mut self) -> Result<()> {
-        let res = execute!(io::stdout(), DisableBracketedPaste);
-        if res.is_ok() {
-            self.bracket_paste_enabled = false;
-        }
-        res
+        self.bracketed_paste.set(false);
+        Ok(())
     }
 
     /// Return terminal support on keyboard enhancement
@@ -269,12 +256,12 @@ impl Reedline {
 
     /// Enable keyboard enhancement to disambiguate escape code
     pub fn enable_kitty_protocol(&mut self) {
-        self.use_kitty_protocol = true;
+        self.kitty_protocol.set(true);
     }
 
     /// Disable keyboard enhancement to disambiguate escape code
     pub fn disable_kitty_protocol(&mut self) {
-        self.use_kitty_protocol = false;
+        self.kitty_protocol.set(false);
     }
 
     /// Return the previously generated history session id
@@ -627,13 +614,13 @@ impl Reedline {
     /// and the `Ok` variant wraps a [`Signal`] which handles user inputs.
     pub fn read_line(&mut self, prompt: &dyn Prompt) -> Result<Signal> {
         terminal::enable_raw_mode()?;
+        self.bracketed_paste.enter();
+        self.kitty_protocol.enter();
 
         let result = self.read_line_helper(prompt);
 
-        if self.use_kitty_protocol {
-            let _ = execute!(io::stdout(), event::PopKeyboardEnhancementFlags);
-        }
-
+        self.bracketed_paste.exit();
+        self.kitty_protocol.exit();
         terminal::disable_raw_mode()?;
         result
     }
@@ -679,31 +666,6 @@ impl Reedline {
         let mut crossterm_events: Vec<ReedlineRawEvent> = vec![];
         let mut reedline_events: Vec<ReedlineEvent> = vec![];
 
-        if self.use_kitty_protocol {
-            if let Ok(true) = crossterm::terminal::supports_keyboard_enhancement() {
-                // enable kitty protocol
-                //
-                // Note that, currently, only the following support this protocol:
-                // * [kitty terminal](https://sw.kovidgoyal.net/kitty/)
-                // * [foot terminal](https://codeberg.org/dnkl/foot/issues/319)
-                // * [WezTerm terminal](https://wezfurlong.org/wezterm/config/lua/config/enable_kitty_keyboard.html)
-                // * [notcurses library](https://github.com/dankamongmen/notcurses/issues/2131)
-                // * [neovim text editor](https://github.com/neovim/neovim/pull/18181)
-                // * [kakoune text editor](https://github.com/mawww/kakoune/issues/4103)
-                // * [dte text editor](https://gitlab.com/craigbarnes/dte/-/issues/138)
-                //
-                // Refer to https://sw.kovidgoyal.net/kitty/keyboard-protocol/ if you're curious.
-                let _ = execute!(
-                    io::stdout(),
-                    event::PushKeyboardEnhancementFlags(
-                        event::KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
-                    )
-                );
-            } else {
-                // TODO: Log or warning
-            }
-        }
-
         loop {
             let mut paste_enter_state = false;
 
diff --git a/src/lib.rs b/src/lib.rs
index 83fb2a9e..aa60a103 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -280,6 +280,8 @@ pub use menu::{
     menu_functions, ColumnarMenu, ListMenu, Menu, MenuEvent, MenuTextStyle, ReedlineMenu,
 };
 
+mod terminal_extensions;
+
 mod utils;
 
 mod external_printer;
diff --git a/src/terminal_extensions/bracketed_paste.rs b/src/terminal_extensions/bracketed_paste.rs
new file mode 100644
index 00000000..00f874ac
--- /dev/null
+++ b/src/terminal_extensions/bracketed_paste.rs
@@ -0,0 +1,37 @@
+use crossterm::{execute, event};
+
+/// Helper managing proper setup and teardown of bracketed paste mode
+///
+/// https://en.wikipedia.org/wiki/Bracketed-paste
+#[derive(Default)]
+pub(crate) struct BracketedPasteGuard {
+    enabled: bool,
+    active: bool,
+}
+
+impl BracketedPasteGuard {
+    pub fn set(&mut self, enable: bool) {
+        self.enabled = enable;
+    }
+    pub fn enter(&mut self) {
+        if self.enabled && !self.active {
+            let _ = execute!(std::io::stdout(), event::EnableBracketedPaste);
+            self.active = true;
+        }
+    }
+    pub fn exit(&mut self) {
+        if self.active {
+            let _ = execute!(std::io::stdout(), event::DisableBracketedPaste);
+            self.active = false;
+        }
+    }
+}
+
+impl Drop for BracketedPasteGuard {
+    fn drop(&mut self) {
+        if self.active {
+            let _ = execute!(std::io::stdout(), event::DisableBracketedPaste);
+        }
+    }
+}
+
diff --git a/src/terminal_extensions/kitty.rs b/src/terminal_extensions/kitty.rs
new file mode 100644
index 00000000..94e6e5d7
--- /dev/null
+++ b/src/terminal_extensions/kitty.rs
@@ -0,0 +1,52 @@
+use crossterm::{event, execute};
+
+/// Helper managing proper setup and teardown of the kitty keyboard enhancement protocol
+///
+/// Note that, currently, only the following support this protocol:
+/// * [kitty terminal](https://sw.kovidgoyal.net/kitty/)
+/// * [foot terminal](https://codeberg.org/dnkl/foot/issues/319)
+/// * [WezTerm terminal](https://wezfurlong.org/wezterm/config/lua/config/enable_kitty_keyboard.html)
+/// * [notcurses library](https://github.com/dankamongmen/notcurses/issues/2131)
+/// * [neovim text editor](https://github.com/neovim/neovim/pull/18181)
+/// * [kakoune text editor](https://github.com/mawww/kakoune/issues/4103)
+/// * [dte text editor](https://gitlab.com/craigbarnes/dte/-/issues/138)
+///
+/// Refer to https://sw.kovidgoyal.net/kitty/keyboard-protocol/ if you're curious.
+#[derive(Default)]
+pub(crate) struct KittyProtocolGuard {
+    enabled: bool,
+    active: bool,
+}
+
+impl KittyProtocolGuard {
+    pub fn set(&mut self, enable: bool) {
+        self.enabled =
+            enable && crossterm::terminal::supports_keyboard_enhancement().unwrap_or_default();
+    }
+    pub fn enter(&mut self) {
+        if self.enabled && !self.active {
+                let _ = execute!(
+                    std::io::stdout(),
+                    event::PushKeyboardEnhancementFlags(
+                        event::KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
+                    )
+                );
+
+            self.active = true;
+        }
+    }
+    pub fn exit(&mut self) {
+        if self.active {
+            let _ = execute!(std::io::stdout(), event::PopKeyboardEnhancementFlags);
+            self.active = false;
+        }
+    }
+}
+
+impl Drop for KittyProtocolGuard {
+    fn drop(&mut self) {
+        if self.active {
+            let _ = execute!(std::io::stdout(), event::PopKeyboardEnhancementFlags);
+        }
+    }
+}
diff --git a/src/terminal_extensions/mod.rs b/src/terminal_extensions/mod.rs
new file mode 100644
index 00000000..69a718e1
--- /dev/null
+++ b/src/terminal_extensions/mod.rs
@@ -0,0 +1,2 @@
+pub(crate) mod kitty;
+pub(crate) mod bracketed_paste;

From 01261c8067a7fc391ff2065f771fd5b49e5c9060 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Tue, 7 Nov 2023 22:57:45 +0100
Subject: [PATCH 02/11] Adjust demo to sane bracketed paste API

---
 examples/demo.rs | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/examples/demo.rs b/examples/demo.rs
index 96bf4959..722b9fe0 100644
--- a/examples/demo.rs
+++ b/examples/demo.rs
@@ -3,8 +3,7 @@ use std::process::Command;
 use {
     crossterm::{
         cursor::SetCursorStyle,
-        event::{DisableBracketedPaste, KeyCode, KeyModifiers},
-        execute,
+        event::{KeyCode, KeyModifiers},
     },
     nu_ansi_term::{Color, Style},
     reedline::{
@@ -13,7 +12,6 @@ use {
         EditCommand, EditMode, Emacs, ExampleHighlighter, Keybindings, ListMenu, Reedline,
         ReedlineEvent, ReedlineMenu, Signal, Vi,
     },
-    std::io::stdout,
 };
 
 use reedline::CursorConfig;
@@ -95,11 +93,7 @@ fn main() -> std::io::Result<()> {
         ))
         .with_validator(Box::new(DefaultValidator))
         .with_ansi_colors(true);
-    let res = line_editor.enable_bracketed_paste();
-    let bracketed_paste_enabled = res.is_ok();
-    if !bracketed_paste_enabled {
-        println!("Warn: failed to enable bracketed paste mode: {res:?}");
-    }
+    let _ = line_editor.enable_bracketed_paste();
 
     // Adding default menus for the compiled reedline
     line_editor = line_editor
@@ -226,9 +220,6 @@ fn main() -> std::io::Result<()> {
         }
     }
 
-    if bracketed_paste_enabled {
-        let _ = execute!(stdout(), DisableBracketedPaste);
-    }
     println!();
     Ok(())
 }

From 33b54a61ad9f4fd5ad9232a8165beb9f3a3dabaa Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Wed, 8 Nov 2023 18:23:27 +0100
Subject: [PATCH 03/11] cargo fmt

---
 src/terminal_extensions/bracketed_paste.rs |  3 +--
 src/terminal_extensions/kitty.rs           | 12 ++++++------
 src/terminal_extensions/mod.rs             |  2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/terminal_extensions/bracketed_paste.rs b/src/terminal_extensions/bracketed_paste.rs
index 00f874ac..b6601cd8 100644
--- a/src/terminal_extensions/bracketed_paste.rs
+++ b/src/terminal_extensions/bracketed_paste.rs
@@ -1,4 +1,4 @@
-use crossterm::{execute, event};
+use crossterm::{event, execute};
 
 /// Helper managing proper setup and teardown of bracketed paste mode
 ///
@@ -34,4 +34,3 @@ impl Drop for BracketedPasteGuard {
         }
     }
 }
-
diff --git a/src/terminal_extensions/kitty.rs b/src/terminal_extensions/kitty.rs
index 94e6e5d7..e4ac6db4 100644
--- a/src/terminal_extensions/kitty.rs
+++ b/src/terminal_extensions/kitty.rs
@@ -25,12 +25,12 @@ impl KittyProtocolGuard {
     }
     pub fn enter(&mut self) {
         if self.enabled && !self.active {
-                let _ = execute!(
-                    std::io::stdout(),
-                    event::PushKeyboardEnhancementFlags(
-                        event::KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
-                    )
-                );
+            let _ = execute!(
+                std::io::stdout(),
+                event::PushKeyboardEnhancementFlags(
+                    event::KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
+                )
+            );
 
             self.active = true;
         }
diff --git a/src/terminal_extensions/mod.rs b/src/terminal_extensions/mod.rs
index 69a718e1..6e2f14d2 100644
--- a/src/terminal_extensions/mod.rs
+++ b/src/terminal_extensions/mod.rs
@@ -1,2 +1,2 @@
-pub(crate) mod kitty;
 pub(crate) mod bracketed_paste;
+pub(crate) mod kitty;

From b41568ebdc9131a6f247ee0ddabd9e3fe427f380 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 14:09:47 +0100
Subject: [PATCH 04/11] Add a static helper `kitty_protocol_available`

Public as `reedline::kitty_protocol_available`

Replace the method `Reedline::can_use_kitty_protocol` that doesn't
depend on `Reedline` in the future

Rewrite `KittyProtocolGuard` in terms of it.
---
 src/lib.rs                       | 1 +
 src/terminal_extensions/kitty.rs | 3 +--
 src/terminal_extensions/mod.rs   | 9 +++++++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs
index aa60a103..0802b875 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -281,6 +281,7 @@ pub use menu::{
 };
 
 mod terminal_extensions;
+pub use terminal_extensions::kitty_protocol_available;
 
 mod utils;
 
diff --git a/src/terminal_extensions/kitty.rs b/src/terminal_extensions/kitty.rs
index e4ac6db4..e6bdd637 100644
--- a/src/terminal_extensions/kitty.rs
+++ b/src/terminal_extensions/kitty.rs
@@ -20,8 +20,7 @@ pub(crate) struct KittyProtocolGuard {
 
 impl KittyProtocolGuard {
     pub fn set(&mut self, enable: bool) {
-        self.enabled =
-            enable && crossterm::terminal::supports_keyboard_enhancement().unwrap_or_default();
+        self.enabled = enable && super::kitty_protocol_available();
     }
     pub fn enter(&mut self) {
         if self.enabled && !self.active {
diff --git a/src/terminal_extensions/mod.rs b/src/terminal_extensions/mod.rs
index 6e2f14d2..927c96b5 100644
--- a/src/terminal_extensions/mod.rs
+++ b/src/terminal_extensions/mod.rs
@@ -1,2 +1,11 @@
 pub(crate) mod bracketed_paste;
 pub(crate) mod kitty;
+
+/// Return if the terminal supports the kitty keyboard enhancement protocol
+///
+/// Read more: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
+///
+/// SIDE EFFECT: Touches the terminal file descriptors
+pub fn kitty_protocol_available() -> bool {
+    crossterm::terminal::supports_keyboard_enhancement().unwrap_or_default()
+}

From 6f85ff4293f3a45f3e86ae313b875f765062fe9c Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 14:14:16 +0100
Subject: [PATCH 05/11] Remove `Reedline::can_use_kitty_protocol`

---
 src/engine.rs | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/src/engine.rs b/src/engine.rs
index 859b1d34..e2c086a5 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -245,15 +245,6 @@ impl Reedline {
         Ok(())
     }
 
-    /// Return terminal support on keyboard enhancement
-    pub fn can_use_kitty_protocol(&mut self) -> bool {
-        if let Ok(b) = crossterm::terminal::supports_keyboard_enhancement() {
-            b
-        } else {
-            false
-        }
-    }
-
     /// Enable keyboard enhancement to disambiguate escape code
     pub fn enable_kitty_protocol(&mut self) {
         self.kitty_protocol.set(true);

From 2ffc6d2fd492ec6f68e15a0c7d52a837e8bb56b8 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 14:36:57 +0100
Subject: [PATCH 06/11] Add builder style setters for terminal enhancement

---
 src/engine.rs | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/engine.rs b/src/engine.rs
index e2c086a5..68708b1d 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -233,6 +233,30 @@ impl Reedline {
         Some(HistorySessionId::new(nanos))
     }
 
+    /// Toggle whether reedline enables bracketed paste to reed copied content
+    ///
+    /// This currently alters the behavior for multiline pastes as pasting of regular text will
+    /// execute after every complete new line as determined by the [`Validator`]. With enabled
+    /// bracketed paste all lines will appear in the buffer and can then be submitted with a
+    /// separate enter.
+    ///
+    /// At this point most terminals should support it or ignore the setting of the necessary
+    /// flags. For full compatibillity, keep it disabled.
+    pub fn use_bracketed_paste(mut self, enable: bool) -> Self {
+        self.bracketed_paste.set(enable);
+        self
+    }
+
+    /// Toggle whether reedline uses the kitty keyboard enhancement protocol
+    ///
+    /// This allows us to disambiguate more events than the traditional standard
+    /// Only available with a few terminal emulators.
+    /// You can check for that with [`crate::kitty_protocol_available`]
+    /// `Reedline` will perform this check internally
+    pub fn use_kitty_keyboard_enhancement(mut self, enable: bool) -> Self {
+        self.kitty_protocol.set(enable);
+        self
+    }
     /// Enable BracketedPaste feature.
     pub fn enable_bracketed_paste(&mut self) -> Result<()> {
         self.bracketed_paste.set(true);

From ebf8f1a7d91c743e9a3ccebe2fafac87f604886d Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 15:00:43 +0100
Subject: [PATCH 07/11] Switch demo to bracketed paste via builder

---
 examples/demo.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/demo.rs b/examples/demo.rs
index 722b9fe0..17659f44 100644
--- a/examples/demo.rs
+++ b/examples/demo.rs
@@ -87,13 +87,13 @@ fn main() -> std::io::Result<()> {
         .with_quick_completions(true)
         .with_partial_completions(true)
         .with_cursor_config(cursor_config)
+        .use_bracketed_paste(true)
         .with_highlighter(Box::new(ExampleHighlighter::new(commands)))
         .with_hinter(Box::new(
             DefaultHinter::default().with_style(Style::new().fg(Color::DarkGray)),
         ))
         .with_validator(Box::new(DefaultValidator))
         .with_ansi_colors(true);
-    let _ = line_editor.enable_bracketed_paste();
 
     // Adding default menus for the compiled reedline
     line_editor = line_editor

From b94c2720d43883a999a11512596752e82e21bf34 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 15:01:38 +0100
Subject: [PATCH 08/11] Expand `use_kitty_keyboard_enhancement` doccomment

---
 src/engine.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/engine.rs b/src/engine.rs
index 68708b1d..df637b76 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -253,6 +253,8 @@ impl Reedline {
     /// Only available with a few terminal emulators.
     /// You can check for that with [`crate::kitty_protocol_available`]
     /// `Reedline` will perform this check internally
+    ///
+    /// Read more: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
     pub fn use_kitty_keyboard_enhancement(mut self, enable: bool) -> Self {
         self.kitty_protocol.set(enable);
         self

From fa6a4b84d5f7216a35d0cb814d561a3b97a46cf4 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 15:02:00 +0100
Subject: [PATCH 09/11] Remove old terminal enhancement APIs

---
 src/engine.rs | 21 ---------------------
 1 file changed, 21 deletions(-)

diff --git a/src/engine.rs b/src/engine.rs
index df637b76..8746150e 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -259,27 +259,6 @@ impl Reedline {
         self.kitty_protocol.set(enable);
         self
     }
-    /// Enable BracketedPaste feature.
-    pub fn enable_bracketed_paste(&mut self) -> Result<()> {
-        self.bracketed_paste.set(true);
-        Ok(())
-    }
-
-    /// Disable BracketedPaste feature.
-    pub fn disable_bracketed_paste(&mut self) -> Result<()> {
-        self.bracketed_paste.set(false);
-        Ok(())
-    }
-
-    /// Enable keyboard enhancement to disambiguate escape code
-    pub fn enable_kitty_protocol(&mut self) {
-        self.kitty_protocol.set(true);
-    }
-
-    /// Disable keyboard enhancement to disambiguate escape code
-    pub fn disable_kitty_protocol(&mut self) {
-        self.kitty_protocol.set(false);
-    }
 
     /// Return the previously generated history session id
     pub fn get_history_session_id(&self) -> Option<HistorySessionId> {

From fab9f54ba90cb532a58a2998e7e489ad2f5ef878 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 15:02:23 +0100
Subject: [PATCH 10/11] Use `use_kitty_keyboard_enhancement(true)` in demo

As we internally check whether it is available, this should be fine in
nearly all terminals (if they can safely be probed)
---
 examples/demo.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/demo.rs b/examples/demo.rs
index 17659f44..2e7a402e 100644
--- a/examples/demo.rs
+++ b/examples/demo.rs
@@ -88,6 +88,7 @@ fn main() -> std::io::Result<()> {
         .with_partial_completions(true)
         .with_cursor_config(cursor_config)
         .use_bracketed_paste(true)
+        .use_kitty_keyboard_enhancement(true)
         .with_highlighter(Box::new(ExampleHighlighter::new(commands)))
         .with_hinter(Box::new(
             DefaultHinter::default().with_style(Style::new().fg(Color::DarkGray)),

From cde7c891ac3f62cdeae9b1d4b6b2607ea9e40126 Mon Sep 17 00:00:00 2001
From: sholderbach <sholderbach@users.noreply.github.com>
Date: Mon, 13 Nov 2023 15:05:08 +0100
Subject: [PATCH 11/11] Fix typo

---
 src/engine.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/engine.rs b/src/engine.rs
index 8746150e..e4ca9c7e 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -241,7 +241,7 @@ impl Reedline {
     /// separate enter.
     ///
     /// At this point most terminals should support it or ignore the setting of the necessary
-    /// flags. For full compatibillity, keep it disabled.
+    /// flags. For full compatibility, keep it disabled.
     pub fn use_bracketed_paste(mut self, enable: bool) -> Self {
         self.bracketed_paste.set(enable);
         self