aboutsummaryrefslogtreecommitdiff
path: root/helix-tui
diff options
context:
space:
mode:
authorMichael Davis2023-04-21 03:53:27 +0000
committerGitHub2023-04-21 03:53:27 +0000
commitee7413a3fd723015843e569924abbfbf32b56182 (patch)
tree2452a41519061ccff8084daf8d6acaad8a32e69e /helix-tui
parent78088ac18510754c9aac27c162e4d81890a11a82 (diff)
tui: Allow toggling mouse capture at runtime (#6675)
This picks up changes to the `editor.mouse` option at runtime - either through `:set-option` or `:config-reload`. When the value changes, we tell the terminal to enable or disable mouse capture sequences.
Diffstat (limited to 'helix-tui')
-rw-r--r--helix-tui/src/backend/crossterm.rs16
-rw-r--r--helix-tui/src/backend/mod.rs1
-rw-r--r--helix-tui/src/backend/test.rs4
-rw-r--r--helix-tui/src/terminal.rs4
4 files changed, 25 insertions, 0 deletions
diff --git a/helix-tui/src/backend/crossterm.rs b/helix-tui/src/backend/crossterm.rs
index 9d70a9fb..0c32028e 100644
--- a/helix-tui/src/backend/crossterm.rs
+++ b/helix-tui/src/backend/crossterm.rs
@@ -63,6 +63,7 @@ pub struct CrosstermBackend<W: Write> {
buffer: W,
capabilities: Capabilities,
supports_keyboard_enhancement_protocol: OnceCell<bool>,
+ mouse_capture_enabled: bool,
}
impl<W> CrosstermBackend<W>
@@ -74,6 +75,7 @@ where
buffer,
capabilities: Capabilities::from_env_or_default(config),
supports_keyboard_enhancement_protocol: OnceCell::new(),
+ mouse_capture_enabled: false,
}
}
@@ -123,6 +125,7 @@ where
execute!(self.buffer, terminal::Clear(terminal::ClearType::All))?;
if config.enable_mouse_capture {
execute!(self.buffer, EnableMouseCapture)?;
+ self.mouse_capture_enabled = true;
}
if self.supports_keyboard_enhancement_protocol() {
execute!(
@@ -136,6 +139,19 @@ where
Ok(())
}
+ fn reconfigure(&mut self, config: Config) -> io::Result<()> {
+ if self.mouse_capture_enabled != config.enable_mouse_capture {
+ if config.enable_mouse_capture {
+ execute!(self.buffer, EnableMouseCapture)?;
+ } else {
+ execute!(self.buffer, DisableMouseCapture)?;
+ }
+ self.mouse_capture_enabled = config.enable_mouse_capture;
+ }
+
+ Ok(())
+ }
+
fn restore(&mut self, config: Config) -> io::Result<()> {
// reset cursor shape
write!(self.buffer, "\x1B[0 q")?;
diff --git a/helix-tui/src/backend/mod.rs b/helix-tui/src/backend/mod.rs
index 6d7c3894..6994bc6f 100644
--- a/helix-tui/src/backend/mod.rs
+++ b/helix-tui/src/backend/mod.rs
@@ -14,6 +14,7 @@ pub use self::test::TestBackend;
pub trait Backend {
fn claim(&mut self, config: Config) -> Result<(), io::Error>;
+ fn reconfigure(&mut self, config: Config) -> Result<(), io::Error>;
fn restore(&mut self, config: Config) -> Result<(), io::Error>;
fn force_restore() -> Result<(), io::Error>;
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
diff --git a/helix-tui/src/backend/test.rs b/helix-tui/src/backend/test.rs
index ff133ff3..771cc309 100644
--- a/helix-tui/src/backend/test.rs
+++ b/helix-tui/src/backend/test.rs
@@ -111,6 +111,10 @@ impl Backend for TestBackend {
Ok(())
}
+ fn reconfigure(&mut self, _config: Config) -> Result<(), io::Error> {
+ Ok(())
+ }
+
fn restore(&mut self, _config: Config) -> Result<(), io::Error> {
Ok(())
}
diff --git a/helix-tui/src/terminal.rs b/helix-tui/src/terminal.rs
index 802a8c1d..8b734275 100644
--- a/helix-tui/src/terminal.rs
+++ b/helix-tui/src/terminal.rs
@@ -116,6 +116,10 @@ where
self.backend.claim(config)
}
+ pub fn reconfigure(&mut self, config: Config) -> io::Result<()> {
+ self.backend.reconfigure(config)
+ }
+
pub fn restore(&mut self, config: Config) -> io::Result<()> {
self.backend.restore(config)
}