mirror of
https://github.com/crossterm-rs/crossterm.git
synced 2025-05-05 15:32:57 +00:00
fix: KeyModifiers Display impl (#979)
The KeyModifiers Display implementation incorrectly formatted modifier keys, causing the output to be concatenated without + separators. This is now corrected.
This commit is contained in:
parent
69249c88fe
commit
2d3f3f5636
17
src/event.rs
17
src/event.rs
@ -870,8 +870,9 @@ impl Display for KeyModifiers {
|
||||
for modifier in self.iter() {
|
||||
if !first {
|
||||
f.write_str("+")?;
|
||||
first = false;
|
||||
}
|
||||
|
||||
first = false;
|
||||
match modifier {
|
||||
KeyModifiers::SHIFT => f.write_str("Shift")?,
|
||||
#[cfg(unix)]
|
||||
@ -1625,6 +1626,20 @@ mod tests {
|
||||
assert_eq!(format!("{}", Modifier(RightSuper)), "Right Super");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_modifiers_display() {
|
||||
let modifiers = KeyModifiers::SHIFT | KeyModifiers::CONTROL | KeyModifiers::ALT;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
assert_eq!(modifiers.to_string(), "Shift+Control+Option");
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
assert_eq!(modifiers.to_string(), "Shift+Ctrl+Alt");
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
||||
assert_eq!(modifiers.to_string(), "Shift+Control+Alt");
|
||||
}
|
||||
|
||||
const ESC_PRESSED: KeyEvent =
|
||||
KeyEvent::new_with_kind(KeyCode::Esc, KeyModifiers::empty(), KeyEventKind::Press);
|
||||
const ESC_RELEASED: KeyEvent =
|
||||
|
Loading…
x
Reference in New Issue
Block a user