#console #hide #background #gui #api-bindings #console-application #windows

hide_console

A library for hiding console windows in Rust applications

3 unstable releases

0.2.1 Mar 2, 2025
0.1.1 Mar 2, 2025
0.1.0 Mar 2, 2025

#65 in Windows APIs

Download history 316/week @ 2025-02-25 71/week @ 2025-03-04

387 downloads per month

MIT license

14KB
62 lines

Hide Console

crates.io Documentation MIT License

A library for hiding console windows in Rust applications. Perfect for creating background applications or applications with graphical interface without visible console window.

Features

  • Hiding console window on Windows platform
  • Showing console window when needed
  • Cross-platform support (works safely on all platforms)
  • Minimal dependencies
  • Simple and clear API

Documentation

Full documentation is available at docs.rs/hide_console.

Installation

Add to your Cargo.toml:

[dependencies]
hide_console = "0.2.1"

Or use the command:

cargo add hide_console

Usage

Basic Example

use hide_console::hide_console;

fn main() {
    // Perform necessary actions before hiding the console
    println!("This message will be visible");
    
    // Hide the console window
    hide_console();
    
    // Continue program execution without visible console
    println!("This message won't be visible in the console, but will be written to stdout");
}

Showing and Hiding the Console

use hide_console::{hide_console, show_console};
use std::io;

fn main() {
    // Hide console at application start
    hide_console();
    
    // Do some work without visible console
    
    // When user interaction is needed, show console again
    show_console();
    println!("Please enter your name:");
    
    let mut name = String::new();
    io::stdin().read_line(&mut name).expect("Failed to read input");
    
    println!("Hello, {}!", name.trim());
    
    // Hide console again for background work
    hide_console();
}

Checking Console Hiding Support

use hide_console::is_hide_console_supported;

fn main() {
    if is_hide_console_supported() {
        println!("Console hiding is supported on this platform");
    } else {
        println!("Console hiding is not supported on this platform");
    }
}

Examples

The library contains several examples that you can run:

# Simple console hiding example
cargo run --example simple

# GUI application emulation
cargo run --example gui_emulation

# Toggle console visibility
cargo run --example toggle_console

Platforms

  • Windows: Full support for hiding and showing console.
  • macOS, Linux, and others: The functions don't perform any actions, but don't cause errors.

How It Works

On Windows platform, the library uses WinAPI to hide and show the console window:

  1. Gets the console window handle using GetConsoleWindow()
  2. Hides or shows the window using ShowWindow() with the SW_HIDE or SW_SHOW parameter

On other platforms, the functions simply return without performing any actions.

License

MIT

Contributing

Contributions are welcome! Please submit pull requests or create issues on GitHub.

Social Media

twitch.tv/mloccy_

t.me/mloccy

Dependencies

~180KB