diff --git a/Cargo.toml b/Cargo.toml index 32006e52..44d8cd79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,18 +28,28 @@ all-features = true # [features] default = ["bracketed-paste", "windows", "events"] -windows = ["dep:winapi", "dep:crossterm_winapi"] # Disables winapi dependencies from being included into the binary (SHOULD NOT be disabled on windows). -bracketed-paste = [] # Enables triggering a `Event::Paste` when pasting text into the terminal. +windows = [ + "dep:windows-sys", + "dep:crossterm_winapi", +] # Disables winapi dependencies from being included into the binary (SHOULD NOT be disabled on windows). +bracketed-paste = [ +] # Enables triggering a `Event::Paste` when pasting text into the terminal. event-stream = ["dep:futures-core", "events"] # Enables async events -use-dev-tty = ["filedescriptor"] # Enables raw file descriptor polling / selecting instead of mio. -events = ["dep:mio", "dep:signal-hook", "dep:signal-hook-mio"] # Enables reading input/events from the system. +use-dev-tty = [ + "filedescriptor", +] # Enables raw file descriptor polling / selecting instead of mio. +events = [ + "dep:mio", + "dep:signal-hook", + "dep:signal-hook-mio", +] # Enables reading input/events from the system. serde = ["dep:serde", "bitflags/serde"] # Enables 'serde' for various types. # # Shared dependencies # [dependencies] -bitflags = {version = "2.3" } +bitflags = { version = "2.3" } parking_lot = "0.12" # optional deps only added when requested @@ -49,10 +59,18 @@ serde = { version = "1.0", features = ["derive"], optional = true } # # Windows dependencies # -[target.'cfg(windows)'.dependencies.winapi] -version = "0.3.9" -features = ["winuser", "winerror"] +[target.'cfg(windows)'.dependencies.windows-sys] +version = "0.52.0" optional = true +features = [ + "Win32_Foundation", + "Win32_System_Console", + "Win32_System_Threading", + "Win32_System_WindowsProgramming", + "Win32_UI_WindowsAndMessaging", + "Win32_UI_TextServices", + "Win32_UI_Input_KeyboardAndMouse", +] [target.'cfg(windows)'.dependencies] crossterm_winapi = { version = "0.9.1", optional = true } @@ -65,7 +83,9 @@ libc = "0.2" signal-hook = { version = "0.3.17", optional = true } filedescriptor = { version = "0.8", optional = true } mio = { version = "0.8", features = ["os-poll"], optional = true } -signal-hook-mio = { version = "0.2.3", features = ["support-v0_8"], optional = true } +signal-hook-mio = { version = "0.2.3", features = [ + "support-v0_8", +], optional = true } # # Dev dependencies (examples, ...) diff --git a/src/ansi_support.rs b/src/ansi_support.rs index fc2f6f14..324a64b6 100644 --- a/src/ansi_support.rs +++ b/src/ansi_support.rs @@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use crossterm_winapi::{ConsoleMode, Handle}; use parking_lot::Once; -use winapi::um::wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING; +use windows_sys::Win32::System::Console::ENABLE_VIRTUAL_TERMINAL_PROCESSING; /// Enable virtual terminal processing. /// diff --git a/src/cursor/sys/windows.rs b/src/cursor/sys/windows.rs index 84a4cd07..879264a2 100644 --- a/src/cursor/sys/windows.rs +++ b/src/cursor/sys/windows.rs @@ -5,10 +5,12 @@ use std::io; use std::sync::atomic::{AtomicU64, Ordering}; use crossterm_winapi::{result, Coord, Handle, HandleType, ScreenBuffer}; -use winapi::{ - shared::minwindef::{FALSE, TRUE}, - um::wincon::{SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD}, +use windows_sys::Win32::Foundation::BOOL; +use windows_sys::Win32::System::Console::{ + SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD, }; +const FALSE: BOOL = 0; +const TRUE: BOOL = 1; /// The position of the cursor, written when you save the cursor's position. /// @@ -147,7 +149,7 @@ impl ScreenBufferCursor { unsafe { if result(SetConsoleCursorPosition( - **self.screen_buffer.handle(), + **self.screen_buffer.handle() as _, position, )) .is_err() @@ -166,7 +168,7 @@ impl ScreenBufferCursor { unsafe { if result(SetConsoleCursorInfo( - **self.screen_buffer.handle(), + **self.screen_buffer.handle() as _, &cursor_info, )) .is_err() diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index 97677ecf..bd85af0d 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -1,14 +1,16 @@ use crossterm_winapi::{ControlKeyState, EventFlags, KeyEventRecord, ScreenBuffer}; -use winapi::um::{ - wincon::{ +use windows_sys::Win32::{ + System::Console::{ CAPSLOCK_ON, LEFT_ALT_PRESSED, LEFT_CTRL_PRESSED, RIGHT_ALT_PRESSED, RIGHT_CTRL_PRESSED, SHIFT_PRESSED, }, - winuser::{ - GetForegroundWindow, GetKeyboardLayout, GetWindowThreadProcessId, ToUnicodeEx, VK_BACK, - VK_CONTROL, VK_DELETE, VK_DOWN, VK_END, VK_ESCAPE, VK_F1, VK_F24, VK_HOME, VK_INSERT, - VK_LEFT, VK_MENU, VK_NEXT, VK_NUMPAD0, VK_NUMPAD9, VK_PRIOR, VK_RETURN, VK_RIGHT, VK_SHIFT, - VK_TAB, VK_UP, + UI::{ + Input::KeyboardAndMouse::{ + GetKeyboardLayout, ToUnicodeEx, VK_BACK, VK_CONTROL, VK_DELETE, VK_DOWN, VK_END, + VK_ESCAPE, VK_F1, VK_F24, VK_HOME, VK_INSERT, VK_LEFT, VK_MENU, VK_NEXT, VK_NUMPAD0, + VK_NUMPAD9, VK_PRIOR, VK_RETURN, VK_RIGHT, VK_SHIFT, VK_TAB, VK_UP, + }, + WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId}, }, }; @@ -203,7 +205,7 @@ fn get_char_for_key(key_event: &KeyEventRecord) -> Option { fn parse_key_event_record(key_event: &KeyEventRecord) -> Option { let modifiers = KeyModifiers::from(&key_event.control_key_state); - let virtual_key_code = key_event.virtual_key_code as i32; + let virtual_key_code = key_event.virtual_key_code; // We normally ignore all key release events, but we will make an exception for an Alt key // release if it carries a u_char value, as this indicates an Alt code. diff --git a/src/event/sys/windows/poll.rs b/src/event/sys/windows/poll.rs index 84d9bf76..a3858b13 100644 --- a/src/event/sys/windows/poll.rs +++ b/src/event/sys/windows/poll.rs @@ -2,12 +2,9 @@ use std::io; use std::time::Duration; use crossterm_winapi::Handle; -use winapi::{ - shared::winerror::WAIT_TIMEOUT, - um::{ - synchapi::WaitForMultipleObjects, - winbase::{INFINITE, WAIT_ABANDONED_0, WAIT_FAILED, WAIT_OBJECT_0}, - }, +use windows_sys::Win32::{ + Foundation::{WAIT_ABANDONED_0, WAIT_FAILED, WAIT_OBJECT_0, WAIT_TIMEOUT}, + System::Threading::{WaitForMultipleObjects, INFINITE}, }; #[cfg(feature = "event-stream")] @@ -50,8 +47,9 @@ impl WinApiPoll { #[cfg(not(feature = "event-stream"))] let handles = &[*console_handle]; - let output = - unsafe { WaitForMultipleObjects(handles.len() as u32, handles.as_ptr(), 0, dw_millis) }; + let output = unsafe { + WaitForMultipleObjects(handles.len() as u32, handles.as_ptr() as _, 0, dw_millis) + }; match output { output if output == WAIT_OBJECT_0 => { diff --git a/src/style.rs b/src/style.rs index 72c22811..962a9bdb 100644 --- a/src/style.rs +++ b/src/style.rs @@ -248,7 +248,7 @@ impl Command for SetUnderlineColor { fn execute_winapi(&self) -> std::io::Result<()> { Err(std::io::Error::new( std::io::ErrorKind::Other, - "SetUnderlineColor not supported by winapi.", + "SetUnderlineColor not supported by windows-sys.", )) } } diff --git a/src/style/sys/windows.rs b/src/style/sys/windows.rs index f5e48b77..3c87c578 100644 --- a/src/style/sys/windows.rs +++ b/src/style/sys/windows.rs @@ -2,7 +2,7 @@ use std::convert::TryFrom; use std::sync::atomic::{AtomicU32, Ordering}; use crossterm_winapi::{Console, Handle, HandleType, ScreenBuffer}; -use winapi::um::wincon; +use windows_sys::Win32::System::Console as wincon; use super::super::{Color, Colored}; diff --git a/src/terminal.rs b/src/terminal.rs index e7406bed..beb492df 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -90,7 +90,7 @@ use crossterm_winapi::{ConsoleMode, Handle, ScreenBuffer}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; #[cfg(windows)] -use winapi::um::wincon::ENABLE_WRAP_AT_EOL_OUTPUT; +use windows_sys::Win32::System::Console::ENABLE_WRAP_AT_EOL_OUTPUT; #[doc(no_inline)] use crate::Command; diff --git a/src/terminal/sys/windows.rs b/src/terminal/sys/windows.rs index 2e408b5c..983262a1 100644 --- a/src/terminal/sys/windows.rs +++ b/src/terminal/sys/windows.rs @@ -4,9 +4,8 @@ use std::fmt::{self, Write}; use std::io::{self}; use crossterm_winapi::{Console, ConsoleMode, Coord, Handle, ScreenBuffer, Size}; -use winapi::{ - shared::minwindef::DWORD, - um::wincon::{SetConsoleTitleW, ENABLE_ECHO_INPUT, ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT}, +use windows_sys::Win32::System::Console::{ + SetConsoleTitleW, CONSOLE_MODE, ENABLE_ECHO_INPUT, ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT, }; use crate::{ @@ -15,7 +14,8 @@ use crate::{ }; /// bits which can't be set in raw mode -const NOT_RAW_MODE_MASK: DWORD = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT; +const NOT_RAW_MODE_MASK: CONSOLE_MODE = + ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT; pub(crate) fn is_raw_mode_enabled() -> std::io::Result { let console_mode = ConsoleMode::from(Handle::current_in_handle()?); @@ -366,7 +366,7 @@ mod tests { use crossterm_winapi::ScreenBuffer; use serial_test::serial; - use winapi::um::wincon::GetConsoleTitleW; + use windows_sys::Win32::System::Console::GetConsoleTitleW; use super::{scroll_down, scroll_up, set_size, set_window_title, size, temp_screen_buffer}; diff --git a/src/tty.rs b/src/tty.rs index 78e32aae..ecade483 100644 --- a/src/tty.rs +++ b/src/tty.rs @@ -9,7 +9,7 @@ use std::os::unix::io::AsRawFd; use std::os::windows::io::AsRawHandle; #[cfg(windows)] -use winapi::um::consoleapi::GetConsoleMode; +use windows_sys::Win32::System::Console::{GetConsoleMode, CONSOLE_MODE}; /// Adds the `is_tty` method to types that might represent a terminal /// @@ -39,8 +39,8 @@ impl IsTty for S { #[cfg(windows)] impl IsTty for S { fn is_tty(&self) -> bool { - let mut mode = 0; - let ok = unsafe { GetConsoleMode(self.as_raw_handle() as *mut _, &mut mode) }; - ok == 1 + let mut mode = CONSOLE_MODE::default(); + let ok = unsafe { GetConsoleMode(self.as_raw_handle() as isize, &mut mode) }; + ok != 0 } }