/ console Public
read_char: Handle non-tty terminals explicitly #124
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.
Key::Unknownis produced only when:
key_from_key_codefunction under Windows:
Line 337 in b3ecb7d
read_keyis invoked on a non-tty terminal:
Lines 274 to 276 in b3ecb7d
The two places in the code which explicitly handled
Key::Unknownwere treating it as a proxy for an "unattended terminal" check:
Lines 258 to 263 in b3ecb7d
Since this is only 100% valid to do when running under *nix I've replaced these handlers with an explicit
!self.is_ttycheck instead, which is a common pattern in the Term code.
Key::Unknownis now assumed to represent an unprintable / control key and skipped when being evaluated.
I found this issue when pressing the
Ctrlkey while using the
read_keyfunction, which causes it to return
Err(Not a terminal)under Windows (but works fine on Linux). In this case, I was in the process of pressing
Ctrl + Cin order to terminate the program.
It looks like this issue also occurred previously for the
Altkeys under Windows - rather than extend the
Keysenum further to support the
Ctrlkey I think the proposed fix is a little more future proof (though you may like to add support for VK_CONTROL for the sake of completeness anyway).