summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal/src/panic.rs
blob: 4ec409ff04e7e28bbb5372912d53f14273593987 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#[cfg(windows)]
use crate::tty::windows::win32_string;

// Use the default behavior of the other platforms.
#[cfg(not(windows))]
pub fn attach_handler() {}

// Install a panic handler that renders the panic in a classical Windows error
// dialog box as well as writes the panic to STDERR.
#[cfg(windows)]
pub fn attach_handler() {
    use std::{io, io::Write, panic, ptr};
    use winapi::um::winuser;

    panic::set_hook(Box::new(|panic_info| {
        let _ = writeln!(io::stderr(), "{}", panic_info);
        let msg = format!("{}\n\nPress Ctrl-C to Copy", panic_info);
        unsafe {
            winuser::MessageBoxW(
                ptr::null_mut(),
                win32_string(&msg).as_ptr(),
                win32_string("Alacritty: Runtime Error").as_ptr(),
                winuser::MB_ICONERROR
                    | winuser::MB_OK
                    | winuser::MB_SETFOREGROUND
                    | winuser::MB_TASKMODAL,
            );
        }
    }));
}