Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix control-character parsing in windows #629

Merged
merged 4 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/event/sys/windows/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<KeyEvent> {
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()
&& !modifiers.contains(KeyModifiers::SHIFT)
{
character.make_ascii_lowercase();
}
} else {
return None;
}
Expand Down
6 changes: 2 additions & 4 deletions src/style/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down