From 6c8ad88bcd2953dd9f7f7beb8b2c38fc9366c955 Mon Sep 17 00:00:00 2001 From: grufkork Date: Tue, 16 Feb 2021 18:58:13 +0100 Subject: [PATCH] Fixed ANSI codes when running standalone --- Cargo.lock | 12 +++++++++++- Cargo.toml | 7 +++++-- src/main.rs | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c4899a..799181f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -160,9 +160,10 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "scpmapper" -version = "1.0.0" +version = "1.0.1" dependencies = [ "inputbot", + "winapi-util", ] [[package]] @@ -220,6 +221,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index d3e35e5..4e1e3bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,13 @@ [package] name = "scpmapper" -version = "1.0.0" +version = "1.0.1" authors = ["grufkork "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -inputbot = "0.5.0" \ No newline at end of file +inputbot = "0.5.0" + +[target.'cfg(windows)'.dependencies] +winapi-util = "0.1.5" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2aa7972..c89d357 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,8 @@ struct Layout{ } fn main() { - println!("scpmapper v1.0.0"); + enable_virtual_terminal_processing(); + println!("scpmapper v1.0.1"); let loop_time = Duration::from_millis(33); @@ -354,4 +355,16 @@ fn zone_to_string(zone: Zone) -> String{ Zone::Light => "light".to_string(), Zone::Heavy => "heavy".to_string() } +} + +#[cfg(windows)] +pub fn enable_virtual_terminal_processing() { + use winapi_util::console::Console; + + if let Ok(mut term) = Console::stdout() { + let _ = term.set_virtual_terminal_processing(true); + } + if let Ok(mut term) = Console::stderr() { + let _ = term.set_virtual_terminal_processing(true); + } } \ No newline at end of file