-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tui: Only query keyboard enhancement support once #6160
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ use crossterm::{ | |
Command, | ||
}; | ||
use helix_view::graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle}; | ||
use once_cell::sync::OnceCell; | ||
use std::{ | ||
fmt, | ||
io::{self, Write}, | ||
|
@@ -52,6 +53,7 @@ impl Capabilities { | |
pub struct CrosstermBackend<W: Write> { | ||
buffer: W, | ||
capabilities: Capabilities, | ||
supports_keyboard_enhancement_protocol: OnceCell<bool>, | ||
} | ||
|
||
impl<W> CrosstermBackend<W> | ||
|
@@ -62,6 +64,7 @@ where | |
CrosstermBackend { | ||
buffer, | ||
capabilities: Capabilities::from_env_or_default(), | ||
supports_keyboard_enhancement_protocol: OnceCell::new(), | ||
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. This value is not included in Capabilities because the tty needs to be in raw mode to perform the query and the backend is created before raw mode is enabled |
||
} | ||
} | ||
} | ||
|
@@ -187,6 +190,12 @@ where | |
fn flush(&mut self) -> io::Result<()> { | ||
self.buffer.flush() | ||
} | ||
|
||
fn supports_keyboard_enhancement_protocol(&self) -> Result<bool, io::Error> { | ||
self.supports_keyboard_enhancement_protocol | ||
.get_or_try_init(terminal::supports_keyboard_enhancement) | ||
.copied() | ||
} | ||
} | ||
|
||
fn map_error(error: crossterm::Result<()>) -> io::Result<()> { | ||
|
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.
Ideally we would check
terminal.supports_keyboard_enhancement_protocol()
here but it's complicated to pass in values from Application because this function is set as a panic handler. We might be able to pass in just the boolean for whether keyboard enhancement is supported. I will check on some different terminals to see if it works to just send thisPopKeyboardEnhancementFlags
always thoughThere 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.
I gave this a test with Kitty, WezTerm (with enhanced keyboard protocol disabled), Alacritty and the default login terminal for my linux machine and it seems to not make a difference - the terminal ignores the escape sequence when it doesn't recognize it