Skip to content
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

Handle failure when enabling bracketed paste #9353

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions helix-tui/src/backend/crossterm.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force_restore also needs to be modified so that it calls

let _ = execute!(stdout, DisableBracketedPaste);

rather than bailing when it isn't supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do i need to modify the trait method here to accept self?
or is there another way to check the supports_bracketed_paste field?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force_restore is called from a panic handler so there's no way to pass in information like the crossterm backend. Instead we have to execute the commands directly against stdout and in this case we can execute DisableBracketedPaste and then just discard the Result so that we continue restoring the terminal even when it gives Err(Error::Unsupported)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we just bind it to the throwaway and remove it from the execute! at the end?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep exactly 👍

Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,22 @@ where
{
fn claim(&mut self, config: Config) -> io::Result<()> {
terminal::enable_raw_mode()?;
execute!(
match execute!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The execute! for EnableBracketedPaste should be separated from the other terminal commands so that if the other commands fail we bail.

Also we need to track whether the terminal supports bracketed paste so that we can decide not to send DisableBracketedPaste in restore:

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(_) => (),
}

self.buffer,
terminal::EnterAlternateScreen,
EnableBracketedPaste,
EnableFocusChange
)?;
) {
Ok(_) => {}
Err(e) => match e.kind() {
io::ErrorKind::Unsupported => {
log::error!("Bracketed paste is not supported on this terminal.")
}
_ => {
return Err(e);
}
},
};
execute!(self.buffer, terminal::Clear(terminal::ClearType::All))?;
if config.enable_mouse_capture {
execute!(self.buffer, EnableMouseCapture)?;
Expand Down
Loading