diff --git a/.gitignore b/.gitignore index ccb756c..66fed9e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ /dist .idea *.dll +*.lib +*.exe node_modules assets/build.css \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5a3bf89..5d66c3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,17 @@ dependencies = [ "memchr", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -46,6 +57,15 @@ dependencies = [ "wasi", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -105,6 +125,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" name = "pacman" version = "0.1.0" dependencies = [ + "atty", "colors-transform", "lazy_static", "libc", @@ -114,6 +135,7 @@ dependencies = [ "tracing", "tracing-error", "tracing-subscriber", + "winapi", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 859580e..ee8a8c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,9 @@ tracing = { version = "0.1.37", features = ["max_level_debug", "release_max_leve tracing-error = "0.2.0" tracing-subscriber = {version = "0.3.17", features = ["env-filter"]} +[target.'cfg(target_os = "windows")'.dependencies] +atty = "0.2" +winapi = {version = "0.3", features = ["wincon", "winuser"]} + [target.'cfg(target_os = "emscripten")'.dependencies] libc = "0.2.16" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6b52f3c..8c6a27c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +// #![windows_subsystem = "windows"] use std::process; use std::time::Duration; @@ -55,21 +56,34 @@ fn ttf_context() -> &'static ttf::Sdl2TtfContext { Box::leak(Box::new(ttf::init().unwrap())) } +#[cfg(not(target_os = "windows"))] +fn hide_console_window() {} + +#[cfg(target_os = "windows")] +fn hide_console_window() { + if !atty::is(atty::Stream::Stdout) { + unsafe { winapi::um::wincon::FreeConsole() }; + } +} + fn main() { + hide_console_window(); + let ctx = sdl2::init().unwrap(); let video_ctx = ctx.video().unwrap(); - + let window = match video_ctx - .window("rust-sdl2-emscripten", 640, 480) - .position_centered() - .resizable() - .allow_highdpi() - .opengl() - .build() + .window("rust-sdl2-emscripten", 640, 480) + .position_centered() + .resizable() + .allow_highdpi() + .opengl() + .build() { Ok(window) => window, Err(err) => panic!("failed to create window: {}", err), }; + let mut canvas = match window.into_canvas().accelerated().build() { Ok(canvas) => canvas,