GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add FromStr trait for Key by farmaazon · Pull Request #4 · rust-windowing/keyboard-types

Conversation

@farmaazon

@farmaazon farmaazon commented Feb 11, 2020

Copy link
Copy Markdown
Contributor

Extended the convert.py script, so it implement trait FromStr for Key. Thanks to that, one can now parse strings from e.g. js_sys::KeyboardEvent::key() and have the enum value.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@farmaazon
Add FromStr trait for Key
90bf03b
@farmaazon
farmaazon requested a review from pyfisch February 11, 2020 15:11
pyfisch
pyfisch requested changes Feb 12, 2020
View reviewed changes

@pyfisch pyfisch left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good!

Can you bump the minimum supported Rust version so Travis does not fail?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread convert.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/key.rs Outdated
fn from_str(s: &str) -> Result<Self, Self::Err> {
use Key::*;
match s {
ch if ch.chars().take(2).count() == 1 => Ok(Character(ch.to_string())),

@pyfisch pyfisch Feb 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

A key string can also consist of a base character and multiple combining characters.
https://w3c.github.io/uievents-key/#keys-unicode
Not sure if it is worth supporting.

Additionally Control Characters should be excluded.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@farmaazon farmaazon Feb 13, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I could add the exact check if string is a key string, but I'm not sure how do you feel with adding new dependency (I would use https://docs.rs/unic-ucd-category/0.9.0/unic_ucd_category/enum.GeneralCategory.html )

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@pyfisch pyfisch Feb 17, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, the dependency would be quite big for such a small feature.

How about checking that:

  1. there are no control characters in the string (char::is_control)
  2. No characters besides the first are in the ASCII range (char::is_ascii)

This prevents common mistakes like mistyped keynames (e.g. Ennter) from being recognized as characters while allowing all characters specified. If the need arises we can add the dependency later.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

farmaazon reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
farmaazon added 4 commits February 13, 2020 09:35
@farmaazon
Implement std::error::Error on UnrecognizedKeyError
e0353f1
@farmaazon
Bump minimum rust version
eed662f
@farmaazon
Address compilation warnings
c983ff5
@farmaazon
Add keystring recognizing
9017d9c
@farmaazon
farmaazon requested a review from pyfisch March 4, 2020 11:34
pyfisch
pyfisch approved these changes Mar 4, 2020
View reviewed changes
@pyfisch
pyfisch merged commit 9310355 into rust-windowing:master Mar 4, 2020
@pyfisch pyfisch mentioned this pull request Mar 4, 2020
String to Key #3
Closed
@pyfisch

pyfisch commented Mar 4, 2020

Copy link
Copy Markdown
Contributor

Released as v0.5.0

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephanemagnenat stephanemagnenat mentioned this pull request Apr 7, 2021
String to code #10
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pyfisch pyfisch pyfisch approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@farmaazon @pyfisch
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.