Skip to main content

cli_or_gui/
hide_terminal.rs

1#[cfg(target_os = "windows")]
2pub fn hide_console_window() {
3    use windows::Win32::{
4        Foundation::HWND,
5        System::Console::GetConsoleWindow,
6        UI::WindowsAndMessaging::{SW_HIDE, ShowWindow},
7    };
8
9    unsafe {
10        let console_window = GetConsoleWindow();
11        if !console_window.0.is_null() {
12            ShowWindow(HWND(console_window.0.cast()), SW_HIDE).unwrap();
13        }
14    }
15}
16
17#[cfg(not(target_os = "windows"))]
18#[allow(clippy::missing_const_for_fn)]
19pub fn hide_console_window() {
20    // No-op on non-Windows platforms.
21    // Linux/macOS GUI bundles do not automatically open terminal windows,
22    // and running directly from a shell should not hide the shell window.
23}