nadir-platform 0.4.0

OS layer of the Nadir engine: windows, the event loop, input devices, GL surfaces, audio output and paths.
Documentation
// Copyright 2026 Joseph Anthony Abbott III
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Telling the player about an error that stops the game.

use std::io::{self, Write};

/// Tells the player about an error that stops the game, such as a window
/// that will not open. `title` names the game, and `message` says what went
/// wrong.
///
/// The message goes to stderr, as one line: `<title>: <message>`. On Linux
/// that is all: the game never starts another program, such as `zenity`, to
/// show it. On Windows a message box shows it as well, and on macOS an alert
/// (from the main thread only); this returns when the player closes it.
pub fn show_error_dialog(title: &str, message: &str) {
    // There is nowhere left to report a failure to write to stderr.
    let _ = write_error(&mut io::stderr().lock(), title, message);
    #[cfg(target_os = "macos")]
    crate::macos::alert(title, message);
    #[cfg(target_os = "windows")]
    crate::windows::message_box(title, message);
}

/// Writes the error as one line of text.
fn write_error(out: &mut impl Write, title: &str, message: &str) -> io::Result<()> {
    writeln!(out, "{title}: {message}")
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn the_message_follows_the_title_on_one_line() {
        let mut out = Vec::new();
        write_error(&mut out, "Sandbox", "could not open the window").expect("write to a Vec");
        assert_eq!(out, b"Sandbox: could not open the window\n");
    }
}