-
Notifications
You must be signed in to change notification settings - Fork 151
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
Ignore Unknown keys #192
Merged
mitsuhiko
merged 1 commit into
console-rs:master
from
deadalusai:master--ignore-unknown-keys
Jan 14, 2023
Merged
Ignore Unknown keys #192
mitsuhiko
merged 1 commit into
console-rs:master
from
deadalusai:master--ignore-unknown-keys
Jan 14, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There are a few keystrokes which cause `console-rs` to produce `Unknown` keys. At the time of this commit this includes pressing the `Control` key, but also previously included `Shift` and `Alt`. Pressing these keys under a *nix terminal does not appear to produce a "key" at all - rather the user must press a complete key chord before `Term::read_key()` will produce a result. Looking at the `console-rs` source, we can see that it produces an `Unknown` key under Windows in at least two cases: 1. When the console is not "attended" 2. When the key code does not map to a known key in the Key enum Since `dialoguer` is already checking for non-attended consoles and executing an early return we can rule out needing to handle that scenario. For the second scenario, it seems reasonable to ignore any "key" not recognized by `console-rs` for the purposes of the Input component.
Related PR on console: console-rs/console#124 |
Pressing AltGr also triggers this behaviour on Windows, which can be more preblematic to enter special characters. |
This also includes Caps Lock (as mentioned in the issues above). Any chance this could be merged? |
This was referenced Mar 24, 2023
connor4312
added a commit
to microsoft/vscode
that referenced
this pull request
Mar 24, 2023
Was fixed by console-rs/dialoguer#192 Fixes #175747
connor4312
added a commit
to microsoft/vscode
that referenced
this pull request
Mar 24, 2023
* cli: fix tunnel message command Fixes #177394 * fix: windows terminal erroring on tunnel first run Was fixed by console-rs/dialoguer#192 Fixes #175747
qwq0
pushed a commit
to qwq0/vscode
that referenced
this pull request
Mar 25, 2023
) * cli: fix tunnel message command Fixes microsoft#177394 * fix: windows terminal erroring on tunnel first run Was fixed by console-rs/dialoguer#192 Fixes microsoft#175747
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I found this issue when pressing the
Ctrl
key while usingInput
, which causes it to returnErr(Not a terminal)
under windows (but works fine on Linux). In this case, I was in the process of pressingCtrl + C
in order to terminate the program.There are a few keystrokes which cause
console-rs
to produceUnknown
keys when running under Windows. At the time of this commit this includes pressing theControl
key, but also previously includedShift
andAlt
.Pressing these keys under a *nix terminal does not appear to produce a "key" at all - rather the user must press a complete key chord before
Term::read_key()
will produce a result.Looking at the
console-rs
source, from what I can see that it produces anUnknown
key under Windows in only two cases:Since
dialoguer
is already checking for non-attended consoles and executing an early return we can rule out needing to handle that scenario:https://github.com/mitsuhiko/dialoguer/blob/f7d02321f5eda89c15b76ffbefbaebdd2c9f0bcb/src/prompts/input.rs#L276-L278
For the second scenario, it seems reasonable to ignore any "key" not recognized by
console-rs
for the purposes of the Input component.