-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Added Kitty Multicursor Support #14757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
4a9bf62
1818836
f97f671
fc4f004
2377612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ fn vte_version() -> Option<usize> { | |
| #[derive(Debug, Default, Clone, Copy)] | ||
| struct Capabilities { | ||
| kitty_keyboard: KittyKeyboardSupport, | ||
| kitty_multi_cursor: bool, | ||
| synchronized_output: bool, | ||
| true_color: bool, | ||
| extended_underlines: bool, | ||
|
|
@@ -125,7 +126,6 @@ impl TerminaBackend { | |
| ) -> io::Result<(Capabilities, String)> { | ||
| use std::time::{Duration, Instant}; | ||
|
|
||
| // Colibri "midnight" | ||
| const TEST_COLOR: RgbColor = RgbColor::new(59, 34, 76); | ||
|
|
||
| terminal.enter_raw_mode()?; | ||
|
|
@@ -238,6 +238,15 @@ impl TerminaBackend { | |
| log::debug!("terminfo could not be read, using default cursor reset escape sequence: {reset_cursor_command:?}"); | ||
| } | ||
|
|
||
| // Detect kitty multi-cursor support (available in kitty >= 0.43.0) | ||
| if matches!( | ||
| term_program().as_deref(), | ||
| Some("kitty") | Some("xterm-kitty") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this detection should be changed to how its described in the kitty docs, otherwise other terminals supporting this feature will not be able to use it out of the box -> https://github.com/kovidgoyal/kitty/blob/master/docs/multiple-cursors-protocol.rst#querying-for-support
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe Termina lacks the capability at the moment. I'll work on a pull request there to add it. |
||
| ) { | ||
| capabilities.kitty_multi_cursor = true; | ||
| log::debug!("Detected kitty terminal - enabling multi-cursor protocol support"); | ||
| } | ||
|
|
||
| terminal.enter_cooked_mode()?; | ||
|
|
||
| Ok((capabilities, reset_cursor_command)) | ||
|
|
@@ -544,6 +553,25 @@ impl Backend for TerminaBackend { | |
| self.flush() | ||
| } | ||
|
|
||
| fn set_multiple_cursors(&mut self, cursors: &[(u16, u16)]) -> io::Result<()> { | ||
| if !self.capabilities.kitty_multi_cursor { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // Always clear existing cursors first | ||
| write!(self.terminal, "\x1b[>0;4 q")?; | ||
|
|
||
| if !cursors.is_empty() { | ||
| write!(self.terminal, "\x1b[>29")?; // Shape 29 = follow main cursor | ||
| for (x, y) in cursors { | ||
| write!(self.terminal, ";2:{}:{}", y + 1, x + 1)?; // 1-indexed coords | ||
| } | ||
| write!(self.terminal, " q")?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These commands belong in Termina too, we shouldn't be writing escape sequences as literal text
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, I'll update the termina pull request |
||
| } | ||
|
|
||
| self.flush() | ||
| } | ||
|
|
||
| fn clear(&mut self) -> io::Result<()> { | ||
| self.start_synchronized_render()?; | ||
| write!( | ||
|
|
@@ -572,6 +600,12 @@ impl Backend for TerminaBackend { | |
| } | ||
| } | ||
|
|
||
| impl TerminaBackend { | ||
| pub fn supports_kitty_multi_cursor(&self) -> bool { | ||
| self.capabilities.kitty_multi_cursor | ||
| } | ||
| } | ||
|
|
||
| impl Drop for TerminaBackend { | ||
| fn drop(&mut self) { | ||
| // Avoid resetting the terminal while panicking because we set a panic hook above in | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this and other changes (like
slice_from_raw_parts_mutbelow) are unrelated and are probably lints from newer versions of Rust. If you install Rust using rustup it will respect the version set inrust-toolchain.toml. We keep an MSRV that is intentionally older, see https://github.com/helix-editor/helix/blob/master/docs/CONTRIBUTING.md#minimum-stable-rust-version-msrv-policyThese extra changes should be reset