Skip to content

Commit 4785a40

Browse files
committed
Migrate from winapi to windows-sys.
This PR migrates terminal_size from winapi to windows-sys. Windows-sys is actively maintained, by Microsoft, and has recently started to be adopted in the ecosystem; mio, parking_lot, wasmtime, and others have moved to windows-sys. Migrating terminal_size to windows-sys will help me remove one more of Wasmtime's transitive dependencies on winapi.
1 parent 0f36d74 commit 4785a40

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

Cargo.toml

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ edition = "2018"
1313
[target.'cfg(not(windows))'.dependencies.libc]
1414
version = "0.2"
1515

16-
[target.'cfg(windows)'.dependencies.winapi]
17-
version = "0.3"
16+
[target.'cfg(windows)'.dependencies.windows-sys]
17+
version = "0.36.0"
1818
features = [
19-
"handleapi",
20-
"processenv",
21-
"winbase",
22-
"wincon",
23-
"winnt",
19+
"Win32_Foundation",
20+
"Win32_System_Console",
2421
]

examples/get_size.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#[cfg(windows)]
22
fn run() {
33
use std::os::windows::io::RawHandle;
4-
use winapi::um::processenv::GetStdHandle;
5-
use winapi::um::winbase::{STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE};
4+
use windows_sys::Win32::System::Console::{
5+
GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
6+
};
67

78
let stdout = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) } as RawHandle;
89
println!(

src/windows.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::os::windows::io::RawHandle;
66
/// Note that this returns the size of the actual command window, and
77
/// not the overall size of the command window buffer
88
pub fn terminal_size() -> Option<(Width, Height)> {
9-
use winapi::um::processenv::GetStdHandle;
10-
use winapi::um::winbase::STD_OUTPUT_HANDLE;
9+
use windows_sys::Win32::System::Console::{GetStdHandle, STD_OUTPUT_HANDLE};
1110

1211
let handle = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) as RawHandle };
1312

@@ -18,13 +17,13 @@ pub fn terminal_size() -> Option<(Width, Height)> {
1817
///
1918
/// If the given handle is not a tty, returns `None`
2019
pub fn terminal_size_using_handle(handle: RawHandle) -> Option<(Width, Height)> {
21-
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
22-
use winapi::um::wincon::{
20+
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
21+
use windows_sys::Win32::System::Console::{
2322
GetConsoleScreenBufferInfo, CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT,
2423
};
2524

26-
// convert between winapi::um::winnt::HANDLE and std::os::windows::raw::HANDLE
27-
let hand = handle as winapi::um::winnt::HANDLE;
25+
// convert between windows_sys::Win32::Foundation::HANDLE and std::os::windows::raw::HANDLE
26+
let hand = handle as windows_sys::Win32::Foundation::HANDLE;
2827

2928
if hand == INVALID_HANDLE_VALUE {
3029
return None;

0 commit comments

Comments
 (0)