#[cfg(windows)]
pub fn attach() -> bool {
use windows_sys::Win32::System::Console::{ATTACH_PARENT_PROCESS, AttachConsole};
unsafe { AttachConsole(ATTACH_PARENT_PROCESS) != 0 }
}
#[cfg(not(windows))]
pub fn attach() -> bool {
true
}
pub fn report_error(msg: &str, has_console: bool) {
eprintln!("badterm: {msg}");
#[cfg(windows)]
if !has_console {
message_box(msg);
}
#[cfg(not(windows))]
let _ = has_console;
}
#[cfg(windows)]
fn message_box(msg: &str) {
use windows_sys::Win32::UI::WindowsAndMessaging::{MB_ICONERROR, MB_OK, MessageBoxW};
let wide = |s: &str| s.encode_utf16().chain(Some(0)).collect::<Vec<u16>>();
let (text, caption) = (wide(msg), wide("BadTerm"));
unsafe {
MessageBoxW(std::ptr::null_mut(), text.as_ptr(), caption.as_ptr(), MB_OK | MB_ICONERROR);
}
}