-
Notifications
You must be signed in to change notification settings - Fork 46
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
Feature: developing a context handler #92
Comments
@petereon i opened a new issue to discuss this. Feel free to drop more questions For more context read: |
Perfect, thank you very much for an exhaustive description. I wonder if it doesn't sound like a good opportunity to utilize That would give us a very good way to check if there is a character waiting for processing with a FIFO |
While this would defnetly be a reasonable approach where we to rewrite all of he input gathering yourselfs. But lukily the operating system already handles most of the heavy lifting. We just need to configure it to match our needs. So don't overcomplicate it. |
Yeah, that sounds like a pretty sane approach. I am just unsure how to handle the none-blocking read then. Sounds like there is either going to have to be an async event-loop or separate process/thread in that case. |
No, the terminal is already a queue and you can query it for content. On windows its super simple as there is a function for it. On linux use this https://gist.github.com/michelbl/efda48b19d3e587685e3441a74457024#file-kbhit-py-L103-L111 |
Also check out this development version that I made but didn't use |
Great, thank you for the information and apologies for how very uninformed I am about |
No worry. The reason I never used the development version is that I didn't know enough and thought it would work just like that. Turned out its more complicated 😂 |
Also keep in mind that on the windows side a lot of stuff doesn't work, so this will mostlikley be the limiting factor. So don't spend to much time (unless you want to 😆) |
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. |
take your time. there is no rush. I will also have more time in the coming weeks, as my thesis is due tomorrow and will no longer eat up my schedule |
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
<#92 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALGZGPORQAA37NXTURFU3MLV5XB4LANCNFSM6AAAAAAQJMRZIA>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
I spend some time on this and prepeard the function definitions without content. See: aa55140 |
Thanks, let me have a look. |
did some more work, check https://github.com/magmax/python-readchar/tree/contexmanager |
That's very cool, also I can see you are already done by the time I got to it. Impressive. Apologies for my inactivity, I was really hard pressed for time with work related stuff. |
I would still be happy about feedback. Especially about the intuitivenes of names and the general usability |
I have played around with it and had one issue in terms of usability: When there are multiple keys waiting at the same time, once the first is read it behaves as if no more keys were waiting. To replicate this, try the following code, press multiple keys while sleeping and wait for while loop to start running. Only printed the first pressed keys for me. After I pressed another as the while loop was running it dumped all the other ones. import time
from readchar import ReadChar
with ReadChar() as stream:
time.sleep(5)
while True:
if stream.key_waiting:
char = stream.key()
print(char) In terms of naming conventions, I wondered if this isn't more of a |
I will look into the issue. I assume you tested on Linux, not Windows? For the name, my initial idea was something like |
I tested on macOS. But that's still POSIX I guess. As for the naming, that does sound like a good way to approach it. Would be my first guess also. |
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:
CTRL+C
etc. As normal keystrokesand handle themHere is an example of how it could work:
If this is working an properly set up, I could replace the existing functions and they could be simply wrappers for this.
The text was updated successfully, but these errors were encountered: