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

enable raw mode compatibility for panic & error reports #142

Closed
slordua opened this issue Dec 21, 2023 · 1 comment
Closed

enable raw mode compatibility for panic & error reports #142

slordua opened this issue Dec 21, 2023 · 1 comment

Comments

@slordua
Copy link

slordua commented Dec 21, 2023

a project I'm working on utilizes raw mode, invoked via crossterm

this prints reports all funny.. this is my solution in color_eyre for now, but it would be nice to see this integrated more elegantly. an enable_raw_mode: bool in HookBuilder could be ok.

use crossterm::terminal::{disable_raw_mode, enable_raw_mode};

// error
// color_eyre::Handler

impl eyre::EyreHandler for Handler {
    fn debug(
        &self,
        error: &(dyn std::error::Error + 'static),
        f: &mut core::fmt::Formatter<'_>,
    ) -> core::fmt::Result {
        let _ = disable_raw_mode();

        // ..

        let _ = enable_raw_mode();

        Ok(())
    }
}

// panic
pub struct RawModePanic;

impl PanicMessage for RawModePanic {
    fn display(
        &self,
        pi: &std::panic::PanicInfo<'_>,
        f: &mut std::fmt::Formatter<'_>,
    ) -> std::fmt::Result {
        let _ = disable_raw_mode();

        // ..

        Ok(())
    }
}

async fn main() -> Result<()> {
    enable_raw_mode()?;

    color_eyre::config::HookBuilder::default()
        .panic_message(RawModePanic)
        .install()?;

    Ok(())
}

for panic, there's no need to re-enable raw mode as we're exiting, but one thing i'm not accounting for here is un-recoverable error, in which case the terminal would be left in raw on exit. need match on ErrorKind perhaps whether to re-enable or something

@slordua slordua closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2024
@slordua
Copy link
Author

slordua commented Jun 7, 2024

solved this by just using a guard with drop impl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant