surjection-core 1.2.0

Core library of Surjection: MCP servers, skills and secret references for AI coding clients
Documentation
//! Starting other programs from the app without a console window (#41).
//!
//! The app is a GUI process: on Windows every console program it starts
//! (git, `op`, taskkill, ...) gets a console window of its own unless the
//! spawn sets `CREATE_NO_WINDOW`. Every `Command` that core or the app
//! starts goes through [`hide_window`]; a test
//! (`tests/no_console_window.rs`) keeps it that way.
//!
//! Hiding is opt-in per process: the app calls [`hide_console_windows`]
//! once at start-up. The CLI never does, so the git and `op` it starts
//! keep its console: an ssh prompt reaches the user's terminal and Ctrl+C
//! reaches git.

use std::process::Command;
use std::sync::atomic::{AtomicBool, Ordering};

/// `CREATE_NO_WINDOW`: the child runs without a console window.
pub const CREATE_NO_WINDOW: u32 = 0x0800_0000;

static HIDE: AtomicBool = AtomicBool::new(false);

/// From now on [`hide_window`] starts programs without a console window.
/// For GUI processes (the app), called once before anything is started.
pub fn hide_console_windows() {
    HIDE.store(true, Ordering::Relaxed);
}

/// True once [`hide_console_windows`] was called in this process.
pub fn hiding_console_windows() -> bool {
    HIDE.load(Ordering::Relaxed)
}

/// Starts `command` without a console window on Windows once this process
/// called [`hide_console_windows`]; otherwise (the CLI, other OSes) it
/// does nothing and the child shares the parent's console.
pub fn hide_window(command: &mut Command) -> &mut Command {
    #[cfg(windows)]
    if hiding_console_windows() {
        use std::os::windows::process::CommandExt as _;
        command.creation_flags(CREATE_NO_WINDOW);
    }
    command
}