From 7be793230e6dd6f6401dc3b8986721189b04cf73 Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Sun, 13 Aug 2023 10:57:07 +0200 Subject: [PATCH] Format code, recreate generated files and enforce format in CI --- .github/workflows/ci.yml | 7 ++-- convert.py | 2 + src/code.rs | 3 +- src/key.rs | 1 + src/webdriver.rs | 81 ++++++++++++++++++++++++++++------------ 5 files changed, 66 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c7a9a1..fa0e646 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,12 +19,13 @@ jobs: - uses: dtolnay/rust-toolchain@stable - run: cargo test - clippy: - name: Clippy + clippy-fmt: + name: Run Clippy and format code runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable with: - components: clippy + components: clippy, rustfmt - run: cargo clippy --all-targets -- -D warnings + - run: cargo fmt --check diff --git a/convert.py b/convert.py index e87ea09..0628e7a 100644 --- a/convert.py +++ b/convert.py @@ -46,6 +46,7 @@ def add_alternative_for(display, key, alternative): def convert_key(text, file): print(""" // AUTO GENERATED CODE - DO NOT EDIT +#![cfg_attr(rustfmt, rustfmt_skip)] use std::fmt::{self, Display}; use std::str::FromStr; @@ -141,6 +142,7 @@ def convert_key(text, file): def convert_code(text, file): print(""" // AUTO GENERATED CODE - DO NOT EDIT +#![cfg_attr(rustfmt, rustfmt_skip)] use std::fmt::{self, Display}; use std::str::FromStr; diff --git a/src/code.rs b/src/code.rs index 6fa2af8..c0ca289 100644 --- a/src/code.rs +++ b/src/code.rs @@ -1,5 +1,6 @@ // AUTO GENERATED CODE - DO NOT EDIT +#![cfg_attr(rustfmt, rustfmt_skip)] use std::fmt::{self, Display}; use std::str::FromStr; @@ -180,7 +181,7 @@ pub enum Code { /// Note that on Apple keyboards, the key labelled Delete on the main part of /// the keyboard should be encoded as "Backspace". Delete, - /// Page Down, End or + /// End or End, /// Help. Not present on standard PC keyboards. Help, diff --git a/src/key.rs b/src/key.rs index 6452ed9..0a481f9 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,5 +1,6 @@ // AUTO GENERATED CODE - DO NOT EDIT +#![cfg_attr(rustfmt, rustfmt_skip)] use std::fmt::{self, Display}; use std::str::FromStr; diff --git a/src/webdriver.rs b/src/webdriver.rs index b46dc2c..f9533a4 100644 --- a/src/webdriver.rs +++ b/src/webdriver.rs @@ -243,12 +243,41 @@ fn code(raw_key: char) -> Code { } fn is_shifted_character(raw_key: char) -> bool { - matches!(raw_key, - '~' | '|' | '{' | '}' | '<' | ')' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '(' - | '+' | '>' | '_' | '\"' | ':' | '?' | '\u{E00D}' | '\u{E05C}' | '\u{E056}' - | '\u{E05B}' | '\u{E055}' | '\u{E058}' | '\u{E05A}' | '\u{E057}' | '\u{E059}' - | '\u{E054}' | '\u{E05D}' | 'A'..='Z' - ) + matches!( + raw_key, + '~' | '|' + | '{' + | '}' + | '<' + | ')' + | '!' + | '@' + | '#' + | '$' + | '%' + | '^' + | '&' + | '*' + | '(' + | '+' + | '>' + | '_' + | '\"' + | ':' + | '?' + | '\u{E00D}' + | '\u{E05C}' + | '\u{E056}' + | '\u{E05B}' + | '\u{E055}' + | '\u{E058}' + | '\u{E05A}' + | '\u{E057}' + | '\u{E059}' + | '\u{E054}' + | '\u{E05D}' + | 'A'..='Z' + ) } fn key_location(raw_key: char) -> Location { @@ -400,22 +429,23 @@ pub fn send_keys(text: &str) -> Vec { return false; } // values from - matches!(normalised_key_value(first_char(text)), + matches!( + normalised_key_value(first_char(text)), Key::Alt - | Key::AltGraph - | Key::CapsLock - | Key::Control - | Key::Fn - | Key::FnLock - | Key::Meta - | Key::NumLock - | Key::ScrollLock - | Key::Shift - | Key::Symbol - | Key::SymbolLock - | Key::Hyper - | Key::Super - ) + | Key::AltGraph + | Key::CapsLock + | Key::Control + | Key::Fn + | Key::FnLock + | Key::Meta + | Key::NumLock + | Key::ScrollLock + | Key::Shift + | Key::Symbol + | Key::SymbolLock + | Key::Hyper + | Key::Super + ) } /// Spec: @@ -447,19 +477,22 @@ pub fn send_keys(text: &str) -> Vec { CompositionEvent { state: CompositionState::Start, data: String::new(), - }.into(), + } + .into(), ); result.push( CompositionEvent { state: CompositionState::Update, data: s.to_owned(), - }.into(), + } + .into(), ); result.push( CompositionEvent { state: CompositionState::End, data: s.to_owned(), - }.into(), + } + .into(), ); } }