mirror of
https://github.com/crossterm-rs/crossterm.git
synced 2025-05-05 23:42:58 +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() {
|
for modifier in self.iter() {
|
||||||
if !first {
|
if !first {
|
||||||
f.write_str("+")?;
|
f.write_str("+")?;
|
||||||
first = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
first = false;
|
||||||
match modifier {
|
match modifier {
|
||||||
KeyModifiers::SHIFT => f.write_str("Shift")?,
|
KeyModifiers::SHIFT => f.write_str("Shift")?,
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@ -1625,6 +1626,20 @@ mod tests {
|
|||||||
assert_eq!(format!("{}", Modifier(RightSuper)), "Right Super");
|
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 =
|
const ESC_PRESSED: KeyEvent =
|
||||||
KeyEvent::new_with_kind(KeyCode::Esc, KeyModifiers::empty(), KeyEventKind::Press);
|
KeyEvent::new_with_kind(KeyCode::Esc, KeyModifiers::empty(), KeyEventKind::Press);
|
||||||
const ESC_RELEASED: KeyEvent =
|
const ESC_RELEASED: KeyEvent =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user