Repository navigation
Normalize key codes and show arrow names in move prompt - #13
Merged
Merged
Conversation
readKey() now turns off ECHO and reads an arrow key's escape sequence while still in raw mode, so one arrow press is one key and macOS no longer echoes "[C". Keys are compared as ints and lowercased at setup, so upper-case and arrow keys match. A closed stdin exits instead of looping forever.
- Windows readKey() returns the same KEY_UP/DOWN/RIGHT/LEFT codes as Unix; other special keys are ignored like Esc. - Unix readKey() reads the whole escape sequence, so Home, F1 or Ctrl+arrow no longer leave stray bytes that count as key presses. - Piped (non-terminal) stdin is read through std::cin again instead of quitting. - The move prompt names keys with keyName() (arrows show as ←↑→↓ instead of a broken byte). - An unbound key no longer explores the current room again.
Owner
|
Hi @lasers , Thank you for fixing Thanks again ! Cheers mate |
Owner
|
It's working in the Unix and WIndows 11, merging. Thank you so much mate :) Cheers |
This file contains hidden or 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
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.
Depends on #12 — this branch is built on top of it, so until #12 is merged the diff below also shows its commit. Only the last commit (
0f7dba8) is new here.Follow-up to #12, cleaning up the rest of key handling:
Move (�/�/�/�)). A newkeyName()helper prints↑ ↓ → ←(andEsc,Space,Enter, …).readKey()now returns the sameKEY_UP/KEY_DOWN/KEY_RIGHT/KEY_LEFTcodes as Unix instead of0xE0xx. Other special keys are ignored like Esc.readKey()reads throughstd::cininstead of quitting (readNumber()may already have buffered the input there).xor Esc) replayed the current room: a free trap or fight.Testing
Built with
-Wall -Wextra -Wpedantic -Wconversion -Wshadow(no new warnings) and driven in a pseudo-terminal on macOS: arrows in bothESC [andESC Oforms, Home/F1/F5/Ctrl+→/Delete/Esc ignored, upper-caseP/Q, piped input played to the end, stdin from/dev/nullexits cleanly.The Windows branch is not tested. It would be great if someone could check arrow keys there.