From d99f2f760b74e941ad953a597d32f61fd709b09e Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Wed, 16 Feb 2022 23:02:14 +0800 Subject: [PATCH 1/4] fix control-character parsing in windows --- src/event/sys/windows/parse.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index f4b6887ac..4a5f88dd3 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -97,6 +97,11 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option { let c = character_raw as u8; if c <= b'\x1F' { character = (c | b'\x40') as char; + // if we press something like ctrl-g, we will get `character` with value `G`. + // in this case, convert the `character` to lowercase `g`. + if character.is_ascii_uppercase() { + character.make_ascii_lowercase(); + } } else { return None; } From 945c14889d910de0389aea26c54211051001e09f Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Sun, 27 Feb 2022 21:22:36 +0800 Subject: [PATCH 2/4] not convert to lowercase when shift is not pressed Co-authored-by: Timon --- src/event/sys/windows/parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index 4a5f88dd3..e7cd25fd5 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -99,7 +99,7 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option { character = (c | b'\x40') as char; // if we press something like ctrl-g, we will get `character` with value `G`. // in this case, convert the `character` to lowercase `g`. - if character.is_ascii_uppercase() { + if character.is_ascii_uppercase() && !modifiers.contains(KeyModifiers::SHIFT) { character.make_ascii_lowercase(); } } else { From 1f4dbca80afb89d04a369247834137c41fdd4c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B3=93=E6=B3=BD?= Date: Sun, 27 Feb 2022 21:29:45 +0800 Subject: [PATCH 3/4] fmt code --- src/event/sys/windows/parse.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index e7cd25fd5..93000b86d 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -99,7 +99,9 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option { character = (c | b'\x40') as char; // if we press something like ctrl-g, we will get `character` with value `G`. // in this case, convert the `character` to lowercase `g`. - if character.is_ascii_uppercase() && !modifiers.contains(KeyModifiers::SHIFT) { + if character.is_ascii_uppercase() + && !modifiers.contains(KeyModifiers::SHIFT) + { character.make_ascii_lowercase(); } } else { From 01ff22b034cebb27c6be6fb8764e780d990e6b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B3=93=E6=B3=BD?= Date: Sun, 27 Feb 2022 21:39:03 +0800 Subject: [PATCH 4/4] fix clippy --- src/style/sys/windows.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/style/sys/windows.rs b/src/style/sys/windows.rs index b2bb7f687..91cc2df07 100644 --- a/src/style/sys/windows.rs +++ b/src/style/sys/windows.rs @@ -28,10 +28,9 @@ pub(crate) fn set_foreground_color(fg_color: Color) -> Result<()> { // Notice that the color values are stored in wAttribute. // So we need to use bitwise operators to check if the values exists or to get current console colors. - let mut color: u16; let attrs = csbi.attributes(); let bg_color = attrs & 0x0070; - color = color_value | bg_color; + let mut color = color_value | bg_color; // background intensity is a separate value in attrs, // wee need to check if this was applied to the current bg color. @@ -53,10 +52,9 @@ pub(crate) fn set_background_color(bg_color: Color) -> Result<()> { // Notice that the color values are stored in wAttribute. // So wee need to use bitwise operators to check if the values exists or to get current console colors. - let mut color: u16; let attrs = csbi.attributes(); let fg_color = attrs & 0x0007; - color = fg_color | color_value; + let mut color = fg_color | color_value; // Foreground intensity is a separate value in attrs, // So we need to check if this was applied to the current fg color.