From b02016d8b1af5cf227b36b70997cf43daa7737e2 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Thu, 14 Feb 2019 00:25:52 +0100 Subject: [PATCH] initial commit --- .gitignore | 3 +++ Cargo.toml | 9 +++++++++ src/lib.rs | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f88dba --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +**/*.rs.bk +Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..97e606c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "output-vt100" +version = "0.1.0" +authors = ["Phuntsok Drak-pa "] +edition = "2018" + +[dependencies] +ctor = "0.1.7" +winapi = { version = "0.3.6", features = ["winuser", "winbase", "consoleapi", "processenv"] } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..90d9599 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,19 @@ +#[cfg(windows)] +pub fn init() { + use winapi::shared::minwindef::DWORD; + use winapi::um::consoleapi::{GetConsoleMode, SetConsoleMode}; + use winapi::um::processenv::GetStdHandle; + use winapi::um::winbase::STD_OUTPUT_HANDLE; + use winapi::um::wincon::{DISABLE_NEWLINE_AUTO_RETURN, ENABLE_VIRTUAL_TERMINAL_PROCESSING}; + + let console_out = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) }; + + let mut state: DWORD = 0; + assert_ne!(unsafe { GetConsoleMode(console_out, &mut state) }, 0); + state |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN; + assert_ne!(unsafe { SetConsoleMode(console_out, state) }, 0); +} +#[cfg(not(windows))] +pub fn init() { + ; +}