mod input;
mod keymap;
mod paths;
mod window;
use core::ptr;
use nadir_sys::windows::user32::{MB_ICONERROR, MB_OK, MessageBoxW};
pub(crate) use paths::user_dirs;
pub(crate) use window::Backend;
fn wide(text: &str) -> Vec<u16> {
text.encode_utf16().chain([0]).collect()
}
pub(crate) fn message_box(title: &str, message: &str) {
let (title, message) = (wide(title), wide(message));
let chosen = unsafe {
MessageBoxW(
ptr::null_mut(),
message.as_ptr(),
title.as_ptr(),
MB_OK | MB_ICONERROR,
)
};
let _ = chosen;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_wide_string_is_utf_16_with_a_nul_at_the_end() {
assert_eq!(wide(""), [0]);
assert_eq!(wide("Nadir"), [0x4E, 0x61, 0x64, 0x69, 0x72, 0]);
assert_eq!(wide("é"), [0xE9, 0]);
assert_eq!(wide("\u{1F3AE}"), [0xD83C, 0xDFAE, 0]);
}
}