Skip to content

Commit

Permalink
Switch from winapi to windows-sys
Browse files Browse the repository at this point in the history
`winapi` is being phased out across the ecosystem in favor of `windows-sys`, which is maintained by
Microsoft. Let's follow suit so dependents don't have to compile both.
  • Loading branch information
LingMan authored and hwittenborn committed Jul 5, 2023
1 parent e20bd92 commit f1e593b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ no-color = []
is-terminal = "0.4"
lazy_static = "1"

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
default-features = false
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48"
features = [
"consoleapi",
"processenv",
"winbase"
"Win32_Foundation",
"Win32_System_Console",
]

[dev_dependencies]
Expand Down
13 changes: 4 additions & 9 deletions src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ use std::sync::atomic::{AtomicBool, Ordering};
#[allow(clippy::result_unit_err)]
#[cfg(windows)]
pub fn set_virtual_terminal(use_virtual: bool) -> Result<(), ()> {
use winapi::{
shared::minwindef::DWORD,
um::{
consoleapi::{GetConsoleMode, SetConsoleMode},
processenv::GetStdHandle,
winbase::STD_OUTPUT_HANDLE,
wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING,
},
use windows_sys::Win32::System::Console::{
GetConsoleMode, GetStdHandle, SetConsoleMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING,
STD_OUTPUT_HANDLE,
};

unsafe {
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
let mut original_mode: DWORD = 0;
let mut original_mode = 0;
GetConsoleMode(handle, &mut original_mode);

let enabled = original_mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
extern crate is_terminal;
#[macro_use]
extern crate lazy_static;
#[cfg(windows)]
extern crate winapi;

#[cfg(test)]
extern crate rspec;
Expand Down

0 comments on commit f1e593b

Please sign in to comment.