Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

Contexmanager#96

Draft
Cube707 wants to merge 7 commits intomastermagmax/python-readchar:masterfrom
contexmanagermagmax/python-readchar:contexmanagerCopy head branch name to clipboard
Draft

Contexmanager#96
Cube707 wants to merge 7 commits intomastermagmax/python-readchar:masterfrom
contexmanagermagmax/python-readchar:contexmanagerCopy head branch name to clipboard

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.

readchar/_posix_read.py Show resolved Hide resolved
@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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.