diff --git a/src/cursor.rs b/src/cursor.rs index 663df4435..4d0f89807 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -328,7 +328,7 @@ impl Command for Show { } /// A command that enables blinking of the terminal cursor. -/// +/// /// # Notes /// /// - Some Unix terminals (ex: GNOME and Konsole) as well as Windows versions lower than Windows 10 do not support this functionality. diff --git a/src/cursor/sys/windows.rs b/src/cursor/sys/windows.rs index 06da423aa..eaee0aa6f 100644 --- a/src/cursor/sys/windows.rs +++ b/src/cursor/sys/windows.rs @@ -134,20 +134,14 @@ impl ScreenBufferCursor { if x < 0 { return Err(io::Error::new( io::ErrorKind::Other, - format!( - "Argument Out of Range Exception when setting cursor position to X: {}", - x - ), + format!("Argument Out of Range Exception when setting cursor position to X: {x}"), )); } if y < 0 { return Err(io::Error::new( io::ErrorKind::Other, - format!( - "Argument Out of Range Exception when setting cursor position to Y: {}", - y - ), + format!("Argument Out of Range Exception when setting cursor position to Y: {y}"), )); } diff --git a/src/event.rs b/src/event.rs index 57dfce598..dfd17eda1 100644 --- a/src/event.rs +++ b/src/event.rs @@ -643,7 +643,9 @@ pub struct KeyEvent { pub modifiers: KeyModifiers, /// Kind of event. /// - /// Only set if [`KeyboardEnhancementFlags::REPORT_EVENT_TYPES`] has been enabled with [`PushKeyboardEnhancementFlags`]. + /// Only set if: + /// - Unix: [`KeyboardEnhancementFlags::REPORT_EVENT_TYPES`] has been enabled with [`PushKeyboardEnhancementFlags`]. + /// - Windows: always pub kind: KeyEventKind, /// Keyboard state. /// diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index 98b3167b9..beb0b51af 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -13,7 +13,7 @@ use winapi::um::{ }; use crate::{ - event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEventKind}, + event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind}, Result, }; @@ -221,7 +221,12 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option // values. let ch = std::char::from_u32(unicode_scalar_value as u32).unwrap(); let key_code = KeyCode::Char(ch); - let key_event = KeyEvent::new(key_code, modifiers); + let kind = if key_event.key_down { + KeyEventKind::Press + } else { + KeyEventKind::Release + }; + let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind); return Some(WindowsKeyEvent::KeyEvent(key_event)); } } @@ -235,10 +240,6 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option return None; } - if !key_event.key_down { - return None; - } - let parse_result = match virtual_key_code { VK_SHIFT | VK_CONTROL | VK_MENU => None, VK_BACK => Some(KeyCode::Backspace), @@ -283,7 +284,12 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option }; if let Some(key_code) = parse_result { - let key_event = KeyEvent::new(key_code, modifiers); + let kind = if key_event.key_down { + KeyEventKind::Press + } else { + KeyEventKind::Release + }; + let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind); return Some(WindowsKeyEvent::KeyEvent(key_event)); } diff --git a/src/style/types/colored.rs b/src/style/types/colored.rs index 34c962e86..a1a91b52a 100644 --- a/src/style/types/colored.rs +++ b/src/style/types/colored.rs @@ -114,8 +114,8 @@ impl fmt::Display for Colored { Color::DarkCyan => f.write_str("5;6"), Color::White => f.write_str("5;15"), Color::Grey => f.write_str("5;7"), - Color::Rgb { r, g, b } => write!(f, "2;{};{};{}", r, g, b), - Color::AnsiValue(val) => write!(f, "5;{}", val), + Color::Rgb { r, g, b } => write!(f, "2;{r};{g};{b}"), + Color::AnsiValue(val) => write!(f, "5;{val}"), _ => Ok(()), } } diff --git a/src/terminal/sys/windows.rs b/src/terminal/sys/windows.rs index 697146ad2..b5592b763 100644 --- a/src/terminal/sys/windows.rs +++ b/src/terminal/sys/windows.rs @@ -195,13 +195,13 @@ pub(crate) fn set_size(width: u16, height: u16) -> Result<()> { if width > bounds.x { return Err(ErrorKind::new( io::ErrorKind::InvalidInput, - format!("terminal width {} too large", width), + format!("terminal width {width} too large"), )); } if height > bounds.y { return Err(ErrorKind::new( io::ErrorKind::InvalidInput, - format!("terminal height {} too large", height), + format!("terminal height {height} too large"), )); } @@ -218,7 +218,7 @@ pub(crate) fn set_window_title(title: impl fmt::Display) -> Result<()> { } let mut title_utf16 = Utf16Encoder(Vec::new()); - write!(title_utf16, "{}", title).expect("formatting failed"); + write!(title_utf16, "{title}").expect("formatting failed"); title_utf16.0.push(0); let title = title_utf16.0;