question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: developing a context handler

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:20

github_iconTop GitHub Comments

1reaction
petereoncommented, Sep 11, 2022

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:

take your time. there is no rush.

I will also have more time in the coming weeks, as my thesis is due tomorrow and no longer eat up my schedule

— Reply to this email directly, view it on GitHub https://github.com/magmax/python-readchar/issues/92#issuecomment-1242948146, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALGZGPORQAA37NXTURFU3MLV5XB4LANCNFSM6AAAAAAQJMRZIA . You are receiving this because you were assigned.Message ID: @.***>

1reaction
petereoncommented, Sep 11, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found