mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 02:46:17 +04:00
Handle failure when enabling bracketed paste (#9353)
* match instead of crash * pulling bracketedpaste out, refactor, tracking for bracketed paste * sending disable bracketed paste only when supports true * move disable bracketed paste to throwaway
This commit is contained in:
parent
1bc7aac780
commit
9c56afeff3
@ -79,6 +79,7 @@ pub struct CrosstermBackend<W: Write> {
|
||||
capabilities: Capabilities,
|
||||
supports_keyboard_enhancement_protocol: OnceCell<bool>,
|
||||
mouse_capture_enabled: bool,
|
||||
supports_bracketed_paste: bool,
|
||||
}
|
||||
|
||||
impl<W> CrosstermBackend<W>
|
||||
@ -91,6 +92,7 @@ pub fn new(buffer: W, config: &EditorConfig) -> CrosstermBackend<W> {
|
||||
capabilities: Capabilities::from_env_or_default(config),
|
||||
supports_keyboard_enhancement_protocol: OnceCell::new(),
|
||||
mouse_capture_enabled: false,
|
||||
supports_bracketed_paste: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,9 +136,16 @@ fn claim(&mut self, config: Config) -> io::Result<()> {
|
||||
execute!(
|
||||
self.buffer,
|
||||
terminal::EnterAlternateScreen,
|
||||
EnableBracketedPaste,
|
||||
EnableFocusChange
|
||||
)?;
|
||||
match execute!(self.buffer, EnableBracketedPaste,) {
|
||||
Err(err) if err.kind() == io::ErrorKind::Unsupported => {
|
||||
log::warn!("Bracketed paste is not supported on this terminal.");
|
||||
self.supports_bracketed_paste = false;
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
Ok(_) => (),
|
||||
};
|
||||
execute!(self.buffer, terminal::Clear(terminal::ClearType::All))?;
|
||||
if config.enable_mouse_capture {
|
||||
execute!(self.buffer, EnableMouseCapture)?;
|
||||
@ -177,9 +186,11 @@ fn restore(&mut self, config: Config) -> io::Result<()> {
|
||||
if self.supports_keyboard_enhancement_protocol() {
|
||||
execute!(self.buffer, PopKeyboardEnhancementFlags)?;
|
||||
}
|
||||
if self.supports_bracketed_paste {
|
||||
execute!(self.buffer, DisableBracketedPaste,)?;
|
||||
}
|
||||
execute!(
|
||||
self.buffer,
|
||||
DisableBracketedPaste,
|
||||
DisableFocusChange,
|
||||
terminal::LeaveAlternateScreen
|
||||
)?;
|
||||
@ -195,12 +206,8 @@ fn force_restore() -> io::Result<()> {
|
||||
// disable without calling enable previously
|
||||
let _ = execute!(stdout, DisableMouseCapture);
|
||||
let _ = execute!(stdout, PopKeyboardEnhancementFlags);
|
||||
execute!(
|
||||
stdout,
|
||||
DisableBracketedPaste,
|
||||
DisableFocusChange,
|
||||
terminal::LeaveAlternateScreen
|
||||
)?;
|
||||
let _ = execute!(stdout, DisableBracketedPaste);
|
||||
execute!(stdout, DisableFocusChange, terminal::LeaveAlternateScreen)?;
|
||||
terminal::disable_raw_mode()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user