Open
Description
Due to the way readchar currently handles terminal setup, we cannot control terminal behaviour outside of the two readchar functions. This leads to issues #62 and #73
We could solve this by externalising terminal setup and teardown and have it run at the beginning and end, ensuring consistent behaviour in between. Under python this calls for a Context Manager
Requirements would be:
- setting up the terminal for readchars needs, this means:
- no echoing or other handeling of typed keys. They need to be waiting untill readchar calls read the next time
- no interruptions, readchar will read
CTRL+C
etc. As normal keystrokesand handle them - whatever else is needet to ensure readchar works consistently
- giving a way to check if a key is waiting to be read
- reading chars and keys as with the current behavior
- ensuring consistent behaviour above both platform's (even if that means limiting one)
- decide on good, intuitive names
- document the new feature
Here is an example of how it could work:
With ReadChar() as read:
if read.key_iswaiting():
print(read.key())
#other stuff in parallel #
sleep(0.5)
If this is working an properly set up, I could replace the existing functions and they could be simply wrappers for this.