blob: 817c39d5f2362e7d1e8f8054a6614738c2884432 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#[cfg(windows)]
pub mod win {
use std::io;
use winapi::um::consoleapi::GetConsoleMode;
use winapi::um::consoleapi::SetConsoleMode;
use winapi::um::wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
use winapi::um::wincon::ENABLE_ECHO_INPUT;
use winapi::um::winbase::STD_OUTPUT_HANDLE;
use winapi::um::processenv::GetStdHandle;
use winapi::shared::minwindef::DWORD;
pub fn enable_vt() -> io::Result<()> {
unsafe {
let h = GetStdHandle(STD_OUTPUT_HANDLE);
if h.is_null() { return Err(io::Error::last_os_error()); }
let mut mode: DWORD = 0;
if GetConsoleMode(h, &mut mode) == 0 {
return Err(io::Error::last_os_error());
}
let new = (mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING) & !ENABLE_ECHO_INPUT;
if SetConsoleMode(h, new) == 0 {
return Err(io::Error::last_os_error());
}
Ok(())
}
}
}
|