Skip to content

Commit

Permalink
Fix control-character parsing in windows (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
WindSoilder authored Feb 27, 2022
1 parent 9bc5cd3 commit e920d0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

5 comments on commit e920d0c

@archseer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimonPost sorry to ping you like this, but could you cut a 0.23.1 release with this patch?

@TimonPost
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archseer yea sure! I'll try to do it this evening

@archseer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

@TimonPost
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archseer published!

@archseer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Bumped the version in helix

Please sign in to comment.