Feature: developing a context handler
See original GitHub issueDue 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.
Issue Analytics
- State:
- Created a year ago
- Comments:20
Top Results From Across the Web
How to Build Custom Context Managers in Python
In this method, there are 5 steps to implement your own context-managers: Define a function. (optional) Write any setup code your context needs....
Read more >3 Ways to create Context Managers in Python - Medium
Usually, a Context Manager consists of two magic methods: __enter__ and __exit__ . The with statement calls the Context Manager. The with ...
Read more >contextlib — Utilities for with-statement contexts ... - Python Docs
This function is a decorator that can be used to define a factory function for async with statement asynchronous context managers, without needing...
Read more >Context Managers and Python's with Statement
In this step-by-step tutorial, you'll learn what the Python with statement is and how to use it with existing context managers.
Read more >Feature handlers made easy in Python | Guide for regular devs
Use this Merixstudio guide to create feature handlers in the backend in a clean code manner.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Good luck with your thesis, mate. So glad I am done with that stuff already 😃
On Sun, Sep 11, 2022, 13:53 Jan Wille @.***> wrote:
I will have a proper read into this. Good opportunity to learn how OS’s handle this stuff 😄. It might take a bit of time.