Skip to content

Contexmanager - #96

Draft
Cube707 wants to merge 7 commits into
masterfrom
contexmanager
Draft

Contexmanager#96
Cube707 wants to merge 7 commits into
masterfrom
contexmanager

Conversation

@Cube707

@Cube707Cube707 commented Oct 30, 2022

Copy link
Copy Markdown
Collaborator

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.

Comment threadreadchar/_posix_read.py
@Cube707

Cube707 commented Oct 30, 2022

Copy link
Copy Markdown
CollaboratorAuthor
  • implement tests
  • documentation
  • export via __init__ and __all__

@Cube707

Cube707 commented Nov 4, 2022

Copy link
Copy Markdown
CollaboratorAuthor

Here ist a example of how this can be used:

fromreadcharimportReadCharfromtimeimportsleep# construct an inverted code -> key-name mapping# we need to revese the items so that aliases won't overrive the original name later onknown_keys= {v: kfork, vinreversed(vars(key).items()) ifnotk.startswith("__")}
withReadChar() asread:
whileTrue:
ifread.key_waiting:
c=read.key()
ifcinknown_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 coverallsNov 6, 2022
@Cube707

Cube707 commented Nov 6, 2022

Copy link
Copy Markdown
CollaboratorAuthor

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
Copy Markdown
CollaboratorAuthor

out now as pre-release

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementgreat new idea

Projects

None yet

1 participant

@Cube707