Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contexmanager #96

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

Contexmanager #96

wants to merge 7 commits into from

Conversation

Cube707
Copy link
Collaborator

@Cube707 Cube707 commented Oct 30, 2022

This implements and closes #92.

The new contextmanager can be used to ensure consisten terminal-behavior while inside the context, even when outside of readchar functions. This allows for fully non-blocking and timing independent usage.

@Cube707
Copy link
Collaborator Author

Cube707 commented Oct 30, 2022

  • implement tests
  • documentation
  • export via __init__ and __all__

@Cube707
Copy link
Collaborator Author

Cube707 commented Nov 4, 2022

Here ist a example of how this can be used:

from readchar import ReadChar
from time import sleep

# construct an inverted code -> key-name mapping
# we need to revese the items so that aliases won't overrive the original name later on
known_keys = {v: k for k, v in reversed(vars(key).items()) if not k.startswith("__")}

with ReadChar() as read:
    while True:
        if read.key_waiting:
            c = read.key()

            if c in known_keys:
                print(known_keys[c])
            else:
                print(c)

        sleep(0.5)

select() is not reliable to as an alternative to kbhit(), it only works
one time an will than returne false untill the next key-press by the
user.
Now the content of stdin is read completly and put in a custom buffer,
which allows for peeking of data.
Repository owner deleted a comment from coveralls Nov 6, 2022
@Cube707
Copy link
Collaborator Author

Cube707 commented Nov 6, 2022

This should be working now.

@Eboubaker, @petereon as you work with this new feature befor, it would be great to get some testing/feedback from you. Use the code snippet above (or whatever else comes to mind, it also needs to be usabel witout example 😆). The class is also now public inside __init__.py

@Cube707
Copy link
Collaborator Author

Cube707 commented Nov 16, 2022

out now as pre-release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement great new idea
Projects
None yet
1 participant